-
Notifications
You must be signed in to change notification settings - Fork 0
/
Callback.php
67 lines (50 loc) · 2.34 KB
/
Callback.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Cardinity\Magento\Controller\Payment;
class Callback extends \Cardinity\Magento\Controller\Payment
{
public function execute()
{
$this->_log("Executing callback v1");
if (!$this->getRequest()->isPost() || empty($this->getRequest()->getPost('PaRes')) || empty($this->getRequest()->getPost('MD'))) {
$this->_log('Invalid callback notification received. Wrong request type or missing mandatory parameters.');
return $this->_forceRedirect('checkout');
}
$authModel = $this->_getAuthModel();
$orderModel = $this->_getOrderModel();
$order = $orderModel->load($authModel->getOrderId());
$pares = $this->getRequest()->getPost('PaRes');
$orderId = $this->getRequest()->getPost('MD');
if (!$order->getId()
|| $order->getId() !== $authModel->getOrderId()
|| $order->getRealOrderId() !== $orderId
|| $order->getState() !== $orderModel::STATE_PENDING_PAYMENT
) {
$this->_log('Invalid callback notification received. Order validation failed.');
$authModel->cleanup();
return $this->_forceRedirect('checkout');
}
$this->_log('Finalizing payment', $order->getRealOrderId());
$model = $this->_getPaymentModel();
$finalize = $model->finalize($authModel->getPaymentId(), $pares);
if ($finalize) {
$status = $finalize->getStatus();
if($status == "approved"){
$this->_log('Payment finalized successfully', $order->getRealOrderId());
$authModel->setThreeDSecureVHistory('3D Secure version 1');
$authModel->setSuccess(true);
$this->_success();
$this->_forceRedirect('checkout/onepage/success');
}else{
$this->_log('Payment finalization failed', $order->getRealOrderId());
$authModel->setFailure(true);
$this->_cancel();
$this->_forceRedirect('checkout/cart');
}
} else {
$this->_log('Unable to finalize payment, error occured', $order->getRealOrderId());
$authModel->setFailure(true);
$this->_cancel();
$this->_forceRedirect('checkout/cart');
}
}
}