first commit

This commit is contained in:
2025-03-12 17:06:23 +01:00
commit 2241f7131f
13185 changed files with 1692479 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
<?php
stPluginHelper::addConfigValue('stPaymentType', 'stEservicePlugin', array('name' => 'stEservice', 'description' => 'Płatność przez serwis eService'));
if (SF_APP == 'backend') {
stPluginHelper::addEnableModule('stEserviceBackend', 'backend');
stPluginHelper::addRouting('stEservicePlugin', '/eservice', 'stEserviceBackend', 'index', 'backend');
stConfiguration::addModule('stEservicePlugin', 'group_3', 1);
} elseif (SF_APP == 'frontend') {
stLanguage::addModuleToRemoveLangParameter('stEserviceFrontend', 'return');
stPluginHelper::addRouting('stEservicePlugin', '/eservice/:action/*', 'stEserviceFrontend', 'index', 'frontend');
stPluginHelper::addEnableModule('stEserviceFrontend', 'frontend');
}

View File

@@ -0,0 +1,14 @@
PaymentType:
PaymentType_Eservice:
created_at: 2013-07-09 09:00:00
updated_at: 2013-07-09 09:00:00
module_name: stEservice
active: 0
culture: pl_PL
name: eService (karta lub przelew)
PaymentTypeI18n:
PaymentTypeI18n_Eservice:
id: PaymentType_Eservice
culture: en_US
name: eService (card or bank transfer)

View File

@@ -0,0 +1,46 @@
<?php
class stEservice {
const POST_URL_PROD = 'https://pay.eservice.com.pl/fim/eservicegate';
const POST_URL_TEST = 'https://testvpos.eservice.com.pl/fim/eservicegate';
const TOKEN_URL_PROD = 'https://pay.eservice.com.pl/pg/token';
const TOKEN_URL_TEST = 'https://testvpos.eservice.com.pl/pg/token';
const PAYMENT_PENDING = 'Pending';
const PAYMENT_APPROVED = 'Approved';
const PAYMENT_DECLINED = 'Declined';
public function __construct() {
$this->config = stPaymentType::getConfiguration(__CLASS__);
}
public function __call($method, $arguments) {
return stPaymentType::call($method, $this->config);
}
public function parseAmount($amount) {
return number_format($amount, 2, '.', '');
}
public function checkPaymentConfiguration() {
return $this->hasEnabled() && $this->hasClientId() && $this->hasPassword() && $this->hasStoreKey();
}
public function getPostUrl() {
return $this->getTest() ? self::POST_URL_TEST : self::POST_URL_PROD;
}
public function getTokenUrl() {
return $this->getTest() ? self::TOKEN_URL_TEST : self::TOKEN_URL_PROD;
}
public function getStoreType() {
return '3d_pay_hosting';
}
}

View File

@@ -0,0 +1,127 @@
<?php
class stEserviceBackendActions extends stActions
{
public function initializeParameters()
{
$this->config = stConfig::getInstance('stEserviceBackend');
$this->labels = $this->getLabels();
}
public function executeIndex()
{
$this->initializeParameters();
if ($this->getRequest()->getMethod() == sfRequest::POST)
{
$this->config->setFromRequest('config');
$this->config->save();
$modules = PaymentTypePeer::doSelectByModuleName('stEservice');
if (!$modules)
{
$modules = PaymentTypePeer::doSelectByModuleName('stEservice2');
}
/**
* @var PaymentType $module
*/
foreach ($modules as $module)
{
$module->setModuleName('stEservice');
$module->setIsActive($this->config->get('enabled'));
$module->save();
}
if ($this->config->get('enabled'))
{
$config = stConfig::getInstance('stEservice2Backend');
$config->set('enabled', false);
$config->save();
}
$this->setFlash('notice', $this->getContext()->getI18n()->__('Twoje zmiany zostały zapisane', null, 'stAdminGeneratorPlugin'));
}
$this->labels = $this->getLabels();
}
public function validateIndex()
{
if ($this->getRequest()->getMethod() == sfRequest::POST)
{
$i18n = $this->getContext()->getI18N();
stAuthUsersListener::checkModificationCredentials($this, $this->getRequest(), $this->getModuleName());
$data = $this->getRequestParameter('config');
if (isset($data['enabled']))
{
$postParameters = array(
'ClientId' => $data['client_id'],
'Password' => $data['password'],
'OrderId' => uniqid(),
'Total' => 500,
'Currency' => 'PLN',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, isset($data['test']) ? stEservice::TOKEN_URL_TEST : stEservice::TOKEN_URL_PROD);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postParameters, '', '&'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if ($response)
{
parse_str($response, $result);
if (strtolower($result['status']) != 'ok')
{
if ($result['msg'] == 'merchant-invalid')
{
$this->getRequest()->setError('{eService}', $i18n->__('Podane dane są nieprawidłowe'));
}
else
{
$this->getRequest()->setError('{eService}', $i18n->__('Wystąpił problem podczas próby weryfikacji danych (zwrócony błąd: "%msg%")', array('%msg%' => $result['msg'])));
}
}
}
else
{
$this->getRequest()->setError('{eService}', $i18n->__('Wystąpił nieznany problem podczas weryfikacji danych'));
}
}
}
return !$this->getRequest()->hasErrors();
}
/*public function handleErrorIndex()
{
$this->initializeParameters();
return sfView::SUCCESS;
}*/
public function handleErrorIndex()
{
$this->initializeParameters();
$this->config = stConfig::getInstance('stEserviceBackend');
return sfView::SUCCESS;
}
protected function getLabels()
{
$i18n = $this->getContext()->getI18N();
return array('config{client_id}' => $i18n->__('Numer sprzedawcy'),'config{password}' => $i18n->__('Hasło sprzedawcy'),'config{store_key}' => $i18n->__('Klucz sklepu'),'{eService}' => 'eService');
}
}

View File

@@ -0,0 +1,13 @@
<?php
class stEserviceBackendComponents extends sfComponents
{
public function executeListMenu()
{
}
}
?>

View File

@@ -0,0 +1,19 @@
<div class="list-menu">
<ul>
<li class="selected">
<?php echo link_to(__('eService'),'stEserviceBackend/index')?>
</li>
<li>
<?php if (sfContext::getInstance()->getUser()->getCulture() == 'pl_PL'): ?>
<a href="https://www.sote.pl/docs/eservice" target="_blank"><?php echo __('Dokumentacja'); ?></a>
<?php else: ?>
<a href="https://www.soteshop.com/docs/eservice" target="_blank"><?php echo __('Documentation'); ?></a>
<?php endif; ?>
</li>
</ul>
</div>
<div class="clr"></div>

View File

@@ -0,0 +1,72 @@
<?php use_helper('I18N', 'stAdminGenerator', 'Validation');?>
<?php echo st_get_admin_head('stEservicePlugin', __('eService', array()), __('',array()),array('stPayment')); ?>
<?php st_view_slot_start('application-menu') ?>
<?php st_include_component('stEserviceBackend', 'listMenu') ?>
<?php st_view_slot_end() ?>
<?php st_include_partial('stAdminGenerator/message', array('labels' => $labels, 'i18n_catalogue' => 'stEserviceBackend')); ?>
<?php echo form_tag('eservice/index', array('id' => 'sf_admin_config_form', 'name' => 'sf_admin_config_form', 'class' => 'admin_form'));?>
<fieldset>
<div class="content">
<div class="form-row <?php if($sf_request->hasError('config{client_id}')):?> form-error<?php endif;?>">
<label for="config_client_id" class="required"><?php echo __('Numer sprzedawcy') ?></label>
<div class="field">
<?php if($sf_request->hasErrors()):?>
<div class="form-error-msg">
<div class="form_error" id="error_for_client_id"> ↓&nbsp;<?php echo $sf_request->getError('config{client_id}') ?>&nbsp;↓</div>
</div>
<?php echo input_tag('config[client_id]', $sf_params->get('config[client_id]'), array('size' => '50'));?>
<?php else:?>
<?php echo input_tag('config[client_id]', $config->get('client_id'), array('size' => '50'));?>
<?php endif;?>
</div>
<div class="clr"></div>
</div>
<div class="form-row <?php if($sf_request->hasError('config{password}')):?> form-error<?php endif;?>">
<label for="config_password" class="required"><?php echo __('Hasło sprzedawcy') ?></label>
<div class="field">
<?php if($sf_request->hasErrors()):?>
<div class="form-error-msg">
<div class="form_error" id="error_for_password"> ↓&nbsp;<?php echo $sf_request->getError('config{password}') ?>&nbsp;↓</div>
</div>
<?php echo input_password_tag('config[password]', $sf_params->get('config[password]'), array('size' => '50'));?>
<?php else:?>
<?php echo input_password_tag('config[password]', $config->get('password'), array('size' => '50'));?>
<?php endif;?>
</div>
<div class="clr"></div>
</div>
<div class="form-row <?php if($sf_request->hasError('config{store_key}')):?> form-error<?php endif;?>">
<label for="config_store_key" class="required" ><?php echo __('Klucz sklepu') ?></label>
<div class="field">
<?php if($sf_request->hasErrors()):?>
<div class="form-error-msg">
<div class="form_error" id="error_for_store_key"> ↓&nbsp;<?php echo $sf_request->getError('config{store_key}') ?>&nbsp;↓</div>
</div>
<?php echo input_password_tag('config[store_key]', $sf_params->get('config[store_key]'), array('size' => '50'));?>
<?php else:?>
<?php echo input_password_tag('config[store_key]', $config->get('store_key'), array('size' => '50'));?>
<?php endif;?>
</div>
<div class="clr"></div>
</div>
<?php if (SF_ENVIRONMENT == 'dev' || $sf_request->hasParameter('debug')): ?>
<div class="form-row">
<label for="config_test"><?php echo __('Aktywuj tryb testowy') ?></label>
<div class="field">
<?php if($sf_request->hasErrors()):?>
<?php echo st_admin_checkbox_tag('config[test]', true, $sf_params->get('config[test]'));?>
<?php else:?>
<?php echo st_admin_checkbox_tag('config[test]', true, $config->get('test'));?>
<?php endif;?>
</div>
<div class="clr"></div>
</div>
<?php endif ?>
</div>
</fieldset>
<?php echo st_get_admin_actions(array(
array('type' => 'save', 'label' => __('Zapisz', null, 'stAdminGeneratorPlugin'))
)) ?>
</form>
<div class="clr"></div>
<?php echo st_get_admin_foot();?>

View File

@@ -0,0 +1,10 @@
fields:
config{client_id}:
required:
msg: Proszę uzupełnić pole.
config{password}:
required:
msg: Proszę uzupełnić pole.
config{store_key}:
required:
msg: Proszę uzupełnić pole.

View File

@@ -0,0 +1,88 @@
<?php
class stEserviceFrontendActions extends stActions {
public function executeReturnSuccess() {
$this->smarty = new stSmarty($this->getModuleName());
$this->processPaymentByRequest();
}
public function executeReturnFail() {
$this->smarty = new stSmarty($this->getModuleName());
$this->processPaymentByRequest();
$this->contactPage = WebpagePeer::retrieveByState('CONTACT');
}
public function executeReturnPending() {
$this->smarty = new stSmarty($this->getModuleName());
$this->processPaymentByRequest();
}
protected function processPaymentByRequest() {
if ($this->getRequest()->getMethod() == sfRequest::POST) {
list(, $orderId) = explode('-', $this->getRequestParameter('OrderId'));
$amount = $this->getRequestParameter('Total');
$status = ucfirst($this->getRequestParameter('Response'));
if ($this->checkHash()) {
$stPayment = new stPayment();
$order = OrderPeer::retrieveByPK($orderId);
if ($order) {
$payment = $order->getOrderPayment();
if ($payment) {
switch ($status) {
case stEservice::PAYMENT_PENDING:
break;
case stEservice::PAYMENT_APPROVED:
$stPayment->confirmPayment($payment->getHash());
break;
case stEservice::PAYMENT_DECLINED:
$stPayment->cancelPayment($payment->getHash());
break;
}
}
}
}
}
}
protected function checkHash()
{
$stEservice = new stEservice();
$storeKey = $stEservice->getStoreKey();
$sep = "|";
$secureCount = 0;
$params = array();
foreach(explode($sep, $this->getRequestParameter('HASHPARAMS')) as $hashParam)
{
if($hashParam == "ClientId" || $hashParam == "Response" || $hashParam == "OrderId")
{
$secureCount++;
}
$params[] = $this->getRequestParameter($hashParam, '');
}
$hashParamsVal = implode($sep, $params);
$hash = base64_encode(hash('sha512', $hashParamsVal .$sep. $storeKey, true));
if($hashParamsVal != $this->getRequestParameter('HASHPARAMSVAL') || $hash != $this->getRequestParameter('HASH') || $secureCount != 3 || $this->getRequestParameter('TranType') != 'Auth') {
file_put_contents(sfConfig::get('sf_root_dir').'/log/eservice.txt', "[".date('d-m-Y H:i:s')."]\nHASHC: ".$hash."\nHASHO: ".$this->getRequestParameter('HASH')."\n"."\nPARAM1: ".$hashParamsVal."\nPARAM2: ".$this->getRequestParameter('HASHPARAMSVAL')."\n\nPOST:\n".var_export($_POST, true), FILE_APPEND);
return false;
}
return true;
}
}

View File

@@ -0,0 +1,42 @@
<?php
class stEserviceFrontendComponents extends sfComponents {
public function executeShowPayment() {
$this->smarty = new stSmarty('stEserviceFrontend');
if (stPaymentType::hasOrderInSummary()) {
$this->stEservice = new stEservice();
$this->stWebRequest = new stWebRequest();
$this->order = stPaymentType::getOrderInSummary();
$this->user = $this->order->getOrderUserDataBilling();
$this->lang = stPaymentType::getLanguage(array('PL', 'EN'), false);
$this->currency = stPaymentType::getCurrency($this->order->getId());
$this->orderId = time().'-'.$this->order->getId();
$postParameters = array(
'ClientId' => $this->stEservice->getClientId(),
'Password' => $this->stEservice->getPassword(),
'OrderId' => $this->orderId,
'Total' => $this->stEservice->parseAmount(stPayment::getUnpayedAmountByOrder($this->order)),
'Currency' => $this->currency->getCode(),
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->stEservice->getTokenUrl());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postParameters, '', '&'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
list($status, $message) = explode('&', $response);
$this->tokenStatus = preg_match('/=ok$/i', $status);
$this->token = preg_replace('/^msg=/', '', $message);
}
$this->isSecure = $this->getRequest()->isSecure();
}
}

View File

@@ -0,0 +1,24 @@
<?php
st_theme_use_stylesheet('stPayment.css');
$smarty->assign('check_configuration', ($stEservice->checkPaymentConfiguration() && $tokenStatus));
if ($stEservice->checkPaymentConfiguration() && $tokenStatus) {
$smarty->assign('params', array(
'ClientId' => $stEservice->getClientId(),
'StoreType' => $stEservice->getStoreType(),
'Token' => $token,
'TranType' => 'Auth',
'Total' => $stEservice->parseAmount(stPayment::getUnpayedAmountByOrder($order)),
'Currency' => $currency->getCode(),
'OrderId' => $orderId,
'ConsumerName' => $user->getName(),
'ConsumerSurname' => $user->getSurname(),
'okUrl' => $sf_context->getController()->genUrl('@stEservicePlugin?action=returnSuccess', true),
'failUrl' => $sf_context->getController()->genUrl('@stEservicePlugin?action=returnFail', true),
'pendingUrl' => $sf_context->getController()->genUrl('@stEservicePlugin?action=returnPending', true),
'lang' => $lang,
'hashAlgorithm' => 'ver2',
));
$smarty->assign('url', $stEservice->getPostUrl());
$smarty->assign('description', stPaymentType::getSummaryDescriptionByOrderIdAndHash($order->getId()));
}
$smarty->display('eservice_show_payment.html');

View File

@@ -0,0 +1,4 @@
<?php
st_theme_use_stylesheet('stPayment.css');
$smarty->assign('contactLink', is_object($contactPage) ? url_for('stWebpageFrontend/index?url='.$contactPage->getFriendlyUrl()) : null);
$smarty->display('eservice_return_fail.html');

View File

@@ -0,0 +1,3 @@
<?php
st_theme_use_stylesheet('stPayment.css');
$smarty->display('eservice_return_pending.html');

View File

@@ -0,0 +1,3 @@
<?php
st_theme_use_stylesheet('stPayment.css');
$smarty->display('eservice_return_success.html');

View File

@@ -0,0 +1,8 @@
<div id="stPayment_return" class="box roundies">
<div class="title">
<h2>{__ text="Płatność"}</h2>
</div>
<div class="content">
<p>{__ text="Płatność nie została zrealizowana."}</p>
</div>
</div>

View File

@@ -0,0 +1,8 @@
<div id="stPayment_return" class="box roundies">
<div class="title">
<h2>{__ text="Płatność"}</h2>
</div>
<div class="content">
<p>{__ text="Płatność jest w trakcie realizacji."}</p>
</div>
</div>

View File

@@ -0,0 +1,8 @@
<div id="stPayment_return" class="box roundies">
<div class="title">
<h2>{__ text="Płatność"}</h2>
</div>
<div class="content">
<p>{__ text="Dziękujemy za dokonanie płatności."}</p>
</div>
</div>

View File

@@ -0,0 +1,21 @@
<div id="st_box_payment">
<img id="st_home" src="/images/frontend/theme/default2/stEservicePlugin/logo.png" alt="" style="margin: 20px 0px" />
<div>
{$description}
</div>
{if $check_configuration}
<form action="{$url}" method="get">
{foreach key=name item=value from=$params}
<input type="hidden" name="{$name}" value="{$value}" />
{/foreach}
<div class="buttons">
<button type="submit" class="important roundies">
<span class="arrow_right">{__ text="Zapłać"}</span>
</button>
</div>
<br class="clear" />
</form>
{else}
<br />{__ text="Płatność została błędnie skonfigurowana."}
{/if}
</div>

View File

@@ -0,0 +1,20 @@
{set layout="one_column"}
<div id="payment">
<div class="title">
<h1>{__ text="Płatność"}</h1>
</div>
<div class="panel panel-default center-block">
<div class="panel-heading">
{__ text="eService"}
</div>
<div class="panel-body text-center">
<p>
{__ text="Płatność nie została zrealizowana."}<br/>
{__ text="Skontaktuj się z nami." langCatalogue="stPayment"}
</p>
{if $contactLink}
<a href="{$contactLink}" class="btn btn-primary">{__ text="Kontakt" langCatalogue="stPayment"}</a>
{/if}
</div>
</div>
</div>

View File

@@ -0,0 +1,15 @@
{set layout="one_column"}
<div id="payment">
<div class="title">
<h1>{__ text="Płatność"}</h1>
</div>
<div class="panel panel-default center-block">
<div class="panel-heading">
{__ text="eService"}
</div>
<div class="panel-body text-center">
<p>{__ text="Płatność jest w trakcie realizacji."}</p>
<a href="/" class="btn btn-primary">{__ text="Wróć do zakupów" langCatalogue="stPayment"}</a>
</div>
</div>
</div>

View File

@@ -0,0 +1,15 @@
{set layout="one_column"}
<div id="payment">
<div class="title">
<h1>{__ text="Płatność"}</h1>
</div>
<div class="panel panel-default center-block">
<div class="panel-heading">
{__ text="eService"}
</div>
<div class="panel-body text-center">
<p>{__ text="Dziękujemy za dokonanie płatności."}</p>
<a href="/" class="btn btn-primary">{__ text="Wróć do zakupów" langCatalogue="stPayment"}</a>
</div>
</div>
</div>

View File

@@ -0,0 +1,23 @@
<div class="panel panel-default center-block">
<div class="panel-heading">
{__ text="eService"}
</div>
<div class="panel-body text-center">
{if $check_configuration}
<img src="/images/frontend/theme/default2/stEservicePlugin/logo.png" alt="{__ text="eService"}" style="margin: 20px 0px" />
<div>
{$description}
</div>
<form action="{$url}" method="get">
{foreach key=name item=value from=$params}
<input type="hidden" name="{$name}" value="{$value}" />
{/foreach}
<button type="submit" class="btn btn-primary">
{__ text="Zapłać"}
</button>
</form>
{else}
{__ text="Płatność została błędnie skonfigurowana."}
{/if}
</div>
</div>