first commit
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user