first commit
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
class stEservice2FrontendActions 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 executeReturn()
|
||||
{
|
||||
if(!$this->getRequestParameter('merchantTxId') || !$this->getRequestParameter('order_id') || !$this->getRequestParameter('hash'))
|
||||
{
|
||||
return $this->redirect('@stEservice2Plugin?action=returnFail');
|
||||
}
|
||||
|
||||
$order = OrderPeer::retrieveByIdAndHashCode($this->getRequestParameter('order_id'), $this->getRequestParameter('hash'));
|
||||
|
||||
$merchantTxId = rawurldecode($this->getRequestParameter('merchantTxId'));
|
||||
|
||||
stPayment::log('eservice', sprintf('Return from payment for order: '.$order->getNumber()));
|
||||
|
||||
stPayment::log('eservice', 'Checking payment status: '. $merchantTxId);
|
||||
|
||||
$api = new stEservice2();
|
||||
$response = $api->checkStatusByMerchantTxId($merchantTxId);
|
||||
|
||||
stPayment::log('eservice', 'Payment status response: '. stEservice2::format($response));
|
||||
|
||||
if ($response->result == 'success' && in_array($response->status, array('SET_FOR_CAPTURE', 'CAPTURED')))
|
||||
{
|
||||
$this->updatePaymentStatus($order, $response);
|
||||
return $this->redirect('@stEservice2Plugin?action=returnSuccess');
|
||||
}
|
||||
|
||||
return $this->redirect('@stEservice2Plugin?action=returnFail');
|
||||
}
|
||||
|
||||
public function executeNotify()
|
||||
{
|
||||
$order = OrderPeer::retrieveByIdAndHashCode($this->getRequestParameter('order_id'), $this->getRequestParameter('hash'));
|
||||
|
||||
stPayment::log('eservice', 'Payment notification for order ' . $order->getNumber() . ' with parameters: ' . json_encode($this->getRequest()->getParameterHolder()->getAll(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
|
||||
stPayment::log('eservice', 'Checking payment status: '. $this->getRequestParameter('txId'));
|
||||
|
||||
$api = new stEservice2();
|
||||
$response = $api->checkStatusByTxId($this->getRequestParameter('txId'));
|
||||
|
||||
stPayment::log('eservice', 'Payment status response: '. stEservice2::format($response));
|
||||
|
||||
if ($response->result == 'success')
|
||||
{
|
||||
$this->updatePaymentStatus($order, $response);
|
||||
}
|
||||
|
||||
return $this->renderText('OK');
|
||||
}
|
||||
|
||||
public function executeProcessPayment()
|
||||
{
|
||||
$smarty = new stSmarty('stEservice2Frontend');
|
||||
$api = new stEservice2();
|
||||
$order = OrderPeer::retrieveByIdAndHashCode($this->getRequestParameter('id'), $this->getRequestParameter('hash'));
|
||||
$response = $api->getToken($order);
|
||||
|
||||
if ($response)
|
||||
{
|
||||
$smarty->assign('logo', $api->getLogoPath());
|
||||
$smarty->assign('url', $api->getPaymentUrl());
|
||||
$smarty->assign('params', array(
|
||||
'merchantId' => $response->merchantId,
|
||||
'token' => $response->token,
|
||||
'integrationMode' => 'hostedPayPage',
|
||||
));
|
||||
|
||||
return $this->renderJSON(array(
|
||||
'content' => $smarty->fetch('show_payment.html'),
|
||||
));
|
||||
}
|
||||
|
||||
return $this->renderJSON(array(
|
||||
'redirect' => $this->getController()->genUrl('@stEservice2Plugin?action=returnFail')
|
||||
));
|
||||
}
|
||||
|
||||
protected function updatePaymentStatus(Order $order, $status)
|
||||
{
|
||||
|
||||
if (in_array($status->status, array('SET_FOR_CAPTURE','CAPTURED')))
|
||||
{
|
||||
$payment = $order->getOrderPayment();
|
||||
|
||||
if (null === $payment)
|
||||
{
|
||||
stPayment::log('eservice', sprintf('Payment for order "%s" doest not exist', $order->getNumber()));
|
||||
}
|
||||
else
|
||||
{
|
||||
$payment->setStatus(1);
|
||||
$payment->save();
|
||||
|
||||
stPayment::log('eservice', sprintf('Payment succefull for order "%s"', $order->getNumber()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
class stEservice2FrontendComponents extends sfComponents
|
||||
{
|
||||
|
||||
public function executeShowPayment()
|
||||
{
|
||||
$smarty = new stSmarty('stEservice2Frontend');
|
||||
$api = new stEservice2();
|
||||
$response = $api->getToken($this->order);
|
||||
|
||||
if ($response)
|
||||
{
|
||||
$smarty->assign('logo', $api->getLogoPath());
|
||||
$smarty->assign('url', $api->getPaymentUrl());
|
||||
$smarty->assign('params', array(
|
||||
'merchantId' => $response->merchantId,
|
||||
'token' => $response->token,
|
||||
'integrationMode' => 'hostedPayPage',
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->getController()->redirect($this->getController()->genUrl('@stEservice2Plugin?action=returnFail'));
|
||||
}
|
||||
|
||||
return $smarty;
|
||||
}
|
||||
}
|
||||
@@ -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('return_fail.html');
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
st_theme_use_stylesheet('stPayment.css');
|
||||
$smarty->display('return_success.html');
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,21 @@
|
||||
<div class="panel panel-default center-block">
|
||||
<div class="panel-heading">
|
||||
{__ text="eService"}
|
||||
</div>
|
||||
<div class="panel-body text-center">
|
||||
|
||||
<img src="{$logo}" alt="{__ text="eService"}" style="margin: 20px 0px" />
|
||||
<div>
|
||||
{$description}
|
||||
</div>
|
||||
<form action="{$url}" method="post">
|
||||
{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>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user