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,17 @@
<?php
stPluginHelper::addConfigValue('stPaymentType', 'stCashBillPlugin', array('name' => 'stCashBill', 'description' => 'Płatność przez serwis CashBill'));
if (SF_APP == 'backend') {
stPluginHelper::addEnableModule('stCashBillBackend', 'backend');
stPluginHelper::addRouting('stCashBillPlugin', '/cashbill', 'stCashBillBackend', 'index', 'backend');
stConfiguration::addModule('stCashBillPlugin', 'group_3', 1);
} elseif (SF_APP == 'frontend') {
stLanguage::addModuleToRemoveLangParameter('stCashBillFrontend', 'return');
stPluginHelper::addRouting('stCashBillPlugin', '/cashbill/:action/*', 'stCashBillFrontend', 'index', 'frontend');
stPluginHelper::addRouting('stCashBillPluginNewPayment', '/cashbill/newPayment/:id/:hash', 'stCashBillFrontend', 'newPayment', 'frontend');
stPluginHelper::addRouting('stCashBillPluginNewPaymentFail', '/cashbill/newPaymentFail', 'stCashBillFrontend', 'newPaymentFail', 'frontend');
stPluginHelper::addEnableModule('stCashBillFrontend', 'frontend');
}
stSecurity::addCSPException('https://*.cashbill.pl');

View File

@@ -0,0 +1,40 @@
<?php
class stCashBill {
const SOAP_URI_PROD = 'https://pay.cashbill.pl/ws/soap/PaymentService?wsdl';
const SOAP_URI_TEST = 'https://pay.cashbill.pl/testws/soap/PaymentService?wsdl';
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() {
if (!$this->hasShopId()) return false;
if (!$this->hasSecretKey()) return false;
if (SF_APP == 'frontend' && stCurrency::getInstance(sfContext::getInstance())->get()->getShortcut() != 'PLN') return false;
return true;
}
public function getSoapUri() {
return $this->getTest() ? self::SOAP_URI_TEST : self::SOAP_URI_PROD;
}
public function getPaymentChannels() {
try {
$client = new stCashBillSoapClient($this->getSoapUri());
$response = $client->availablePaymentChannels(array('languageCode' => stPaymentType::getLanguage(array('PL', 'EN'))));
return is_object($response->return) ? array($response->return) : $response->return;
} catch (SoapFault $e) { }
return array();
}
}

View File

@@ -0,0 +1,28 @@
<?php
class stCashBillSoapClient extends SoapClient {
public function __doRequest($request, $location, $action, $version, $oneWay = 0) {
$stCashBill = new stCashBill();
$sec = <<<EOS
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1">
<wsse:Username>{$stCashBill->getShopId()}</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">{$stCashBill->getSecretKey()}</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
EOS;
$xml = new DOMDocument();
$xml->loadXML($request);
$header = $xml->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'Header');
$node = $xml->createDocumentFragment();
$node->appendXML($sec);
$header->appendChild($node);
$xml->firstChild->insertBefore($header, $xml->firstChild->firstChild);
$request = $xml->saveXML();
return parent::__doRequest($request, $location, $action, $version, $oneWay);
}
}

View File

@@ -0,0 +1,64 @@
<?php
class stCashBillBackendActions extends stActions {
public function initializeParameters() {
$this->webRequest = new stWebRequest();
$this->config = stConfig::getInstance('stCashBillBackend');
if ($this->config->get('shop_id', $this->getRequestParameter('config[shop_id]'), true) != '' && $this->config->get('secret_key', $this->getRequestParameter('config[secret_key]'), true) != '')
{
$this->configuration_check = true;
} else {
$this->configuration_check = false;
}
$i18n = $this->getContext()->getI18n();
$this->labels = array(
'config{shop_id}' => $i18n->__('Identyfikator'),
'config{secret_key}' => $i18n->__('Klucz'),
);
}
public function executeIndex() {
$this->initializeParameters();
if ($this->getRequest()->getMethod() == sfRequest::POST) {
$this->config->setFromRequest('config');
$this->config->save();
$this->setFlash('notice', $this->getContext()->getI18n()->__('Twoje zmiany zostały zapisane', null, 'stAdminGeneratorPlugin'));
}
if ($this->config->get('shop_id', $this->getRequestParameter('config[shop_id]'), true) != '' && $this->config->get('secret_key', $this->getRequestParameter('config[secret_key]'), true) != '')
{
$this->configuration_check = true;
} else {
$notice = $this->getContext()->getI18n()->__('Zobacz')."&nbsp;".$this->getContext()->getI18n()->__('krótki przewodnik uruchomienia płatności CashBill.')."&nbsp;".'<a href="http://www.cashbill.pl/download/integracje/Platnosci/PlatnosciCashBillSOTE.pdf" target="_blank">'.$this->getContext()->getI18n()->__('krótki przewodnik uruchomienia płatności CashBill.').'</a>'."&nbsp;".$this->getContext()->getI18n()->__('Sprawdź promocyjne warunki dla klientów SOTE.');
$this->setFlash("info", $notice, false);
$this->configuration_check = false;
}
}
public function validateIndex() {
if ($this->getRequest()->getMethod() == sfRequest::POST)
stAuthUsersListener::checkModificationCredentials($this, $this->getRequest(), $this->getModuleName());
return true;
}
public function handleErrorIndex() {
$this->initializeParameters();
return sfView::SUCCESS;
}
}

View File

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

View File

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

View File

@@ -0,0 +1,37 @@
<?php use_helper('I18N', 'stAdminGenerator', 'Validation');?>
<?php echo st_get_admin_head('stCashBillPlugin', __('CashBill'), '', array('stPayment'));?>
<?php st_view_slot_start('application-menu') ?>
<?php st_include_component('stCashBillBackend', 'listMenu') ?>
<?php st_view_slot_end() ?>
<?php echo form_tag('cashbill/index', array('id' => 'sf_admin_config_form', 'name' => 'sf_admin_config_form', 'class' => 'admin_form'));?>
<?php st_include_partial('stAdminGenerator/message', array('labels' => $labels, 'i18n_catalogue' => 'stLukasBackend'));?>
<fieldset>
<div class="content">
<?php echo st_admin_get_form_field('config[shop_id]', __('Identyfikator punktu płatności'), $config->get('shop_id'), 'input_tag', array('required' => true, 'autocomplete' => "off")) ?>
<?php echo st_admin_get_form_field('config[secret_key]', __('Klucz punktu płatności'), $config->get('secret_key'), 'input_tag', array('required' => true, 'autocomplete' => "off")) ?>
<?php if (SF_ENVIRONMENT == 'dev' || $sf_request->hasParameter('debug')): ?>
<?php echo st_admin_get_form_field('config[test]', __('Aktywuj tryb testowy'), 1, 'checkbox_tag', array('checked' => $config->get('test'))) ?>
<?php endif;?>
<?php echo st_admin_get_form_field('config[show_variant]', __('Wybierz kanału płatności'), array('none' => __('W serwisie CashBill (zalecana)'), 'image' => __('W sklepie - graficzna'), 'text' => __('W sklepie - tekstowa')), 'select_tag', array('selected' => $config->get('show_variant'))) ?>
</div>
</fieldset>
<fieldset>
<div class="content">
<?php echo st_admin_get_form_field('url_report', __('Adres serwerowego potwierdzenia transakcji'), "http://".$webRequest->getHost()."/cashbill/reportStatus", 'input_tag', array('readonly' => true, 'size' => 80, 'clipboard' => true)) ?>
</div>
</fieldset>
<?php echo st_get_admin_actions(array(
array('type' => 'download', 'label' => __('Pobierz przewodnik'), 'action' => 'http://www.cashbill.pl/download/integracje/Platnosci/PlatnosciCashBillSOTE.pdf', 'params' => array('target' => '_blank')),
array('type' => 'save', 'label' => __('Zapisz', null, 'stAdminGeneratorPlugin'))
)) ?>
</form>
<br class="st_clear_all">
<?php echo st_get_admin_foot();?>

View File

@@ -0,0 +1,7 @@
fields:
config{shop_id}:
required:
msg: Proszę uzupełnić pole.
config{secret_key}:
required:
msg: Proszę uzupełnić pole.

View File

@@ -0,0 +1,114 @@
<?php
class stCashBillFrontendActions extends stActions {
public function executeReturnSuccess() {
$this->smarty = new stSmarty($this->getModuleName());
}
public function executeReturnFail() {
$this->smarty = new stSmarty($this->getModuleName());
$this->contactPage = WebpagePeer::retrieveByState('CONTACT');
}
public function executeNewPaymentFail() {
$this->smarty = new stSmarty($this->getModuleName());
$this->contactPage = WebpagePeer::retrieveByState('CONTACT');
}
public function executeReportStatus() {
$this->setLayout(false);
$cmd = $this->getRequest()->getParameter('cmd');
$args = $this->getRequest()->getParameter('args');
$sign = $this->getRequest()->getParameter('sign');
$stCashBill = new stCashBill();
$shopSign = md5($cmd.$args.$stCashBill->getSecretKey());
if ($shopSign == $sign) {
try {
$client = new stCashBillSoapClient($stCashBill->getSoapUri());
$response = $client->getPayment(array('id' => $args));
} catch (SoapFault $e) {
$response = null;
}
if ($response !== null) {
$data = unserialize($response->return->additionalData);
if (false === $data) {
$stPayment = new stPayment();
if ($response->return->status == 'PositiveFinish')
$stPayment->confirmPayment($response->return->additionalData);
elseif ($response->return->status == 'NegativeFinish')
$stPayment->cancelPayment($response->return->additionalData);
} elseif ($response->return->status == 'PositiveFinish') {
$payment = PaymentPeer::retrieveByIdAndHash($data['id'], $data['hash']);
if ($payment)
{
$payment->setStatus(true);
$payment->save();
}
else
{
file_put_contents(sfConfig::get('sf_root_dir').'/log/cashbill.txt', '['.date('d-m-Y H:i:s').'] No Payment instance for:'.var_export($response->return, true)."\n", FILE_APPEND);
}
}
}
}
}
public function executeNewPayment() {
$url = '@stCashBillPluginNewPaymentFail';
if ($this->getRequest()->hasParameter('id') && $this->getRequest()->hasParameter('hash')) {
$id = $this->getRequest()->getParameter('id');
$hash = $this->getRequest()->getParameter('hash');
$order = OrderPeer::retrieveByIdAndHashCode($id, $hash);
$channelId = $this->getRequest()->getParameter('channelId', null);
if (is_object($order)) {
$stCashBill = new stCashBill();
$stWebRequest = new stWebRequest();
$user = $order->getOrderUserDataBilling();
$payment = $order->getOrderPayment();
try {
$client = new stCashBillSoapClient($stCashBill->getSoapUri());
$parameters = array(
'title' => $this->getContext()->getI18n()->__('Zamówienie numer:').' '.$order->getNumber(),
'amount' => array(
'value' => $stCashBill->parseAmount(stPayment::getUnpayedAmountByOrder($order)),
'currencyCode' => stPaymentType::getCurrency($order->getId())->getShortcut(),
),
'languageCode' => stPaymentType::getLanguage(array('PL', 'EN')),
'returnUrl' => 'http://'.$stWebRequest->getHost().'/cashbill/returnSuccess',
'negativeReturnUrl' => 'http://'.$stWebRequest->getHost().'/cashbill/returnFail',
'personalData' => array(
'firstName' => $user->getName(),
'surname' => $user->getSurname(),
'email' => $order->getGuardUser()->getUsername(),
),
'additionalData' => serialize(array('id' => $payment->getId(), 'hash' => $payment->getHash())),
'referer' => 'SOTE',
);
if ($channelId !== null)
$parameters['paymentChannel'] = $channelId;
$response = $client->newPayment($parameters);
if(is_object($response))
$url = $response->return->redirectUrl;
} catch (SoapFault $e) {
file_put_contents(sfConfig::get('sf_root_dir').'/log/cashbill.txt', '['.date('d-m-Y H:i:s').'] Order number '.$order->getNumber().':'.var_export($e->getMessage(), true)."\n", FILE_APPEND);
}
}
}
$this->redirect($url);
exit();
}
}

View File

@@ -0,0 +1,21 @@
<?php
class stCashBillFrontendComponents extends sfComponents {
public function executeShowPayment() {
$this->smarty = new stSmarty('stCashBillFrontend');
$this->stCashBill = new stCashBill();
$this->order = OrderPeer::retrieveByPK($this->getRequestParameter('id'));
if (in_array($this->stCashBill->getShowVariant(), array('text', 'image'))) {
$this->channels = $this->stCashBill->getPaymentChannels();
} else
$this->channels = array();
if ($this->getContext()->getModuleName() == 'stPayment' && $this->getContext()->getActionName() == 'pay')
$this->redirect = true;
else
$this->redirect = false;
}
}

View File

@@ -0,0 +1,13 @@
<?php
st_theme_use_stylesheet('stPayment.css');
st_theme_use_stylesheet('stCashBillPlugin.css');
$smarty->assign('check_configuration', $stCashBill->checkPaymentConfiguration());
if ($stCashBill->checkPaymentConfiguration()) {
$smarty->assign('form_start', form_tag('@stCashBillPluginNewPayment?id='.$order->getId().'&hash='.$order->getHashCode(), array('class' => 'st_form', 'id' => 'st_cashbill_form_new_payment')));
$smarty->assign('pay_submit', submit_tag(__('Zapłać')));
$smarty->assign('channels', $channels);
$smarty->assign('redirect', $redirect);
$smarty->assign('show_variant', $stCashBill->getShowVariant());
}
$smarty->assign('description', stPaymentType::getSummaryDescriptionByOrderIdAndHash($order->getId()));
$smarty->display('cashbill_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('cashbill_new_payment_fail.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('cashbill_return_fail.html');

View File

@@ -0,0 +1,3 @@
<?php
st_theme_use_stylesheet('stPayment.css');
$smarty->display('cashbill_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="Błąd podczas tworzenia nowej płatności."}</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ść 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="Dziękujemy za dokonanie płatności."}</p>
</div>
</div>

View File

@@ -0,0 +1,84 @@
{use_stylesheet src="stUser.css"}
<div id="privacy_overlay" style="height: auto">
<div class="privacy_overlay_content" style="text-align: center; height: auto">
<h2>CashBill</h2>
<p>{__ text="Za chwilę nastąpi przekierowanie na stronę płatności. Proszę czekać."}</p>
<p><img src="/images/frontend/theme/responsive/preloader.gif"></p>
</div>
</div>
<div id="st_box_payment">
<img id="st_home" src="/images/frontend/theme/default2/stCashBillPlugin/logo.png" alt=""/><br />
<span>
{$description}
</span>
{if $check_configuration}
<div id="cashbill_list">
{$form_start}
{if $show_variant == 'text'}
{assign var='i' value=0}
{foreach from=$channels item=channel}
{assign var='i' value=$i+1}
<div class="line">
<input type="radio" name="channelId" id="check_{$i}" value="{$channel->id}" class="radiobutton"/>
<label class="name" for="check_{$i}">{$channel->name}</label>
</div>
{/foreach}
{elseif $show_variant == 'image'}
{assign var='i' value=0}
{foreach from=$channels item=channel}
{assign var='i' value=$i+1}
<div class="item box_form img_list">
<label for="check_{$i}">
<img src="{$channel->logoUrl}" />
<h5 class="name">{$channel->name}</h5>
<input type="radio" name="channelId" id="check_{$i}" value="{$channel->id}" class="radiobutton"/>
</label>
</div>
{/foreach}
{elseif $show_variant == 'none' && $redirect}
{literal}
<script type="text/javascript">
jQuery(function($) {
$(document).ready(function () {
$("#st_cashbill_form_new_payment").submit(function() {
var form = $(this);
if (form.data('submited')) {
return false;
}
form.data('submited', true);
$('#privacy_overlay').overlay({
mask: {
color: '#000',
loadSpeed: 'fast',
opacity: 0.5
},
close: '.close',
closeOnClick: false,
closeOnEsc: false,
top: "20%",
speed: 'fast',
load: true,
oneInstance: true
});
}).submit();
});
});
</script>
{/literal}
{/if}
<div class="clear"></div>
<div class="buttons right">
<button type="submit" class="important roundies">
<span class="arrow_right">{__ text="Zapłać"}</span>
</button>
</div>
<div class="clear"></div>
</form>
</div>
{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="CashBill"}
</div>
<div class="panel-body text-center">
<p>
{__ text="Błąd podczas tworzenia nowej płatności."}<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,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="CashBill"}
</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="CashBill"}
</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,79 @@
<div class="modal fade modal-vertical-centered" id="order-process-modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<h3 class="text-center">{__ text="CashBill"}</h3>
<p class="text-center">{__ text="Za chwilę nastąpi przekierowanie na stronę płatności. Proszę czekać."}</p>
<div class="preloader"></div>
</div>
</div>
</div>
</div>
<div class="panel panel-default center-block"{if $show_variant == 'image'} id="payment-list"{elseif $show_variant == 'text'} id="payment-list-text"{/if}>
<div class="panel-heading">
{__ text="CashBill"}
</div>
<div class="panel-body text-center">
{if $check_configuration}
<img src="/images/frontend/theme/default2/stCashBillPlugin/logo.png" alt="{__ text="CashBill"}"/><br />
<span>
{$description}
</span>
{$form_start}
{$hidden_order_id}
{if $show_variant == 'text'}
{assign var='i' value=0}
<div class="row" data-equalizer>
{foreach from=$channels item=channel}
{assign var='i' value=$i+1}
<div class="col-sm-6 col-md-4 col-lg-3" data-equalizer-watch>
<label for="check_{$i}" class="btn btn-default">
<input type="radio" name="channelId" id="check_{$i}" value="{$channel->id}"/>
{$channel->name}
</label>
</div>
{/foreach}
</div>
{elseif $show_variant == 'image'}
{assign var='i' value=0}
<div class="row" data-equalizer>
{foreach from=$channels item=channel}
{assign var='i' value=$i+1}
<div class="col-xs-6 col-sm-3 col-md-2" data-equalizer-watch>
<label for="check_{$i}" class="text-center btn btn-default">
<img class="img-responsive" src="{$channel->logoUrl}" alt="{$channel->name}"/>
<input type="radio" name="channelId" id="check_{$i}" value="{$channel->id}"/>
</label>
</div>
{/foreach}
</div>
{elseif $show_variant == 'none' && $redirect}
{literal}
<script type="text/javascript">
jQuery(function($) {
$(document).ready(function () {
$("#st_cashbill_form_new_payment").submit(function() {
var form = $(this);
if (form.data('submited')) {
return false;
}
form.data('submited', true);
$('#order-process-modal').modal({ show: true });
}).submit();
});
});
</script>
{/literal}
{/if}
<button type="submit" class="btn btn-primary pull-right">
{__ text="Zapłać"}
</button>
</form>
{else}
{__ text="Płatność została błędnie skonfigurowana."}
{/if}
</div>
</div>