-
Notifications
You must be signed in to change notification settings - Fork 0
/
Callbackv2.php
90 lines (63 loc) · 3.25 KB
/
Callbackv2.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace Cardinity\Magento\Controller\Payment;
class Callbackv2 extends \Cardinity\Magento\Controller\Payment
{
public function execute()
{
$this->_log("Executing callback v2");
if (!$this->getRequest()->isPost() || empty($this->getRequest()->getPost('cres')) || empty($this->getRequest()->getPost('threeDSSessionData'))) {
$this->_log('Invalid callback notification received. Wrong request type or missing mandatory parameters.');
$this->_log('redirecting buyer to authv1 page');
$this->_forceRedirect('cardinity/payment/auth');
return $this->_forceRedirect('checkout');
}else{
$this->_log("Cres : ".$this->getRequest()->getPost('cres'));
$this->_log("TDSData : ".$this->getRequest()->getPost('threeDSSessionData'));
}
$authModel = $this->_getAuthModel();
$orderModel = $this->_getOrderModel();
$order = $orderModel->load($authModel->getOrderId());
$cres = $this->getRequest()->getPost('cres');
$orderId = $this->getRequest()->getPost('threeDSSessionData');
if (!$order->getId()
|| $order->getId() !== $authModel->getOrderId()
|| $order->getRealOrderId() !== $orderId
|| $order->getState() !== $orderModel::STATE_PENDING_PAYMENT
) {
$this->_log('Invalid callback data received. Order validation failed.');
$authModel->cleanup();
return $this->_forceRedirect('checkout');
}
$this->_log('Finalizing payment', $order->getRealOrderId());
$model = $this->_getPaymentModel();
$finalize = $model->finalize($authModel->getPaymentId(), $cres, true);
if ($finalize) {
$status = $finalize->getStatus();
if($status == "approved"){
$this->_log('Payment finalized successfully', $order->getRealOrderId());
$authModel->setThreeDSecureVHistory('3D Secure version 2');
$authModel->setSuccess(true);
$this->_success();
$this->_forceRedirect('checkout/onepage/success');
}else if($status == "pending"){
$this->_log('Payment finalization pending, redirecting to authv1 page', $order->getRealOrderId());
$authModel->setThreeDSecureV2Needed(false);
$authData = $finalize->getAuthorizationInformation();
$authModel->setThreeDSecureNeeded(true);
$authModel->setUrl($authData->getUrl());
$authModel->setData($authData->getData());
$this->_forceRedirect('cardinity/payment/auth');
}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');
}
}
}