1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace B2Binpay\Payment\Controller\Callback; |
4
|
|
|
|
5
|
|
|
use Magento\Sales\Model\Order; |
|
|
|
|
6
|
|
|
use Magento\Framework\App\Action\Context; |
|
|
|
|
7
|
|
|
use Magento\Framework\App\Action\Action; |
|
|
|
|
8
|
|
|
use Magento\Framework\App\CsrfAwareActionInterface; |
|
|
|
|
9
|
|
|
use Magento\Framework\App\Request\InvalidRequestException; |
|
|
|
|
10
|
|
|
use Magento\Framework\App\RequestInterface; |
|
|
|
|
11
|
|
|
use Magento\Framework\Controller\Result\RawFactory; |
|
|
|
|
12
|
|
|
use B2Binpay\Payment\Gateway\Validator\CallbackValidator; |
13
|
|
|
use B2Binpay\AmountFactory; |
|
|
|
|
14
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
15
|
|
|
|
16
|
|
|
class Index extends Action implements CsrfAwareActionInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var RawFactory |
20
|
|
|
*/ |
21
|
|
|
protected $rawResultFactory; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Context |
25
|
|
|
*/ |
26
|
|
|
protected $context; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var CallbackValidator |
30
|
|
|
*/ |
31
|
|
|
protected $validator; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var LoggerInterface |
35
|
|
|
*/ |
36
|
|
|
protected $logger; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var AmountFactory |
40
|
|
|
*/ |
41
|
|
|
private $amountFactory; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Callback controller. |
45
|
|
|
* |
46
|
|
|
* @param Context $context |
47
|
|
|
* @param RawFactory $rawResultFactory |
48
|
|
|
* @param CallbackValidator $validator |
49
|
|
|
* @param AmountFactory $amountFactory |
50
|
|
|
* @param LoggerInterface $logger |
51
|
|
|
*/ |
52
|
|
|
public function __construct( |
53
|
|
|
Context $context, |
54
|
|
|
RawFactory $rawResultFactory, |
55
|
|
|
CallbackValidator $validator, |
56
|
|
|
AmountFactory $amountFactory, |
57
|
|
|
LoggerInterface $logger |
58
|
|
|
) { |
59
|
|
|
$this->context = $context; |
60
|
|
|
$this->rawResultFactory = $rawResultFactory; |
61
|
|
|
$this->validator = $validator; |
62
|
|
|
$this->amountFactory = $amountFactory; |
63
|
|
|
$this->logger = $logger; |
64
|
|
|
parent::__construct($context); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @inheritDoc |
69
|
|
|
*/ |
70
|
|
|
public function createCsrfValidationException( |
71
|
|
|
RequestInterface $request |
72
|
|
|
): ?InvalidRequestException { |
73
|
|
|
return null; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritDoc |
78
|
|
|
*/ |
79
|
|
|
public function validateForCsrf(RequestInterface $request): ?bool |
80
|
|
|
{ |
81
|
|
|
return true; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
|
|
public function execute() |
88
|
|
|
{ |
89
|
|
|
$request = $this->context->getRequest(); |
90
|
|
|
$result = $this->rawResultFactory->create(); |
91
|
|
|
|
92
|
|
|
$validationResult = $this->validator->validate(['request' => $request]); |
93
|
|
|
|
94
|
|
|
$validation = $validationResult->getFailsDescription(); |
95
|
|
|
|
96
|
|
|
if (!$validationResult->isValid()) { |
97
|
|
|
$result->setStatusHeader($validation['status'], '1.1', $validation['message']); |
98
|
|
|
|
99
|
|
|
return $result; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$order = $validation['order']; |
103
|
|
|
$payment = $order->getPayment(); |
104
|
|
|
$params = $request->getParams(); |
105
|
|
|
|
106
|
|
|
$billStatus = (string)$params['status']; |
107
|
|
|
|
108
|
|
|
if ('2' === $billStatus) { |
109
|
|
|
if ($params['amount'] === $params['actual_amount']) { |
110
|
|
|
$totalDue = $order->getTotalDue(); |
111
|
|
|
|
112
|
|
|
$payment->authorize(false, $totalDue); |
113
|
|
|
$payment->registerCaptureNotification($totalDue); |
114
|
|
|
|
115
|
|
|
$order->addStatusToHistory( |
116
|
|
|
$order::STATE_PROCESSING, |
117
|
|
|
__('B2BinPay payment complete!') |
|
|
|
|
118
|
|
|
); |
119
|
|
|
} else { |
120
|
|
|
$actualAmount = $this->amountFactory->create( |
121
|
|
|
$params['actual_amount'], |
122
|
|
|
$params['currency']['iso'], |
123
|
|
|
$params['pow'] |
124
|
|
|
)->getValue(); |
125
|
|
|
|
126
|
|
|
$order->addStatusToHistory( |
127
|
|
|
$order::STATE_PAYMENT_REVIEW, |
128
|
|
|
__('B2BinPay received payment: ' . $actualAmount . $params['currency']['alpha']) |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$stateList = $this->getStateDesc(); |
134
|
|
|
|
135
|
|
|
if (!empty($stateList[$billStatus])) { |
136
|
|
|
$order->addStatusToHistory( |
137
|
|
|
$stateList[$billStatus]['state'], |
138
|
|
|
$stateList[$billStatus]['message'] |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
$order->save(); |
143
|
|
|
|
144
|
|
|
$result->setStatusHeader('200', '1.1', 'OK'); |
145
|
|
|
$result->setContents('OK'); |
146
|
|
|
|
147
|
|
|
return $result; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return array |
152
|
|
|
*/ |
153
|
|
|
private function getStateDesc() |
154
|
|
|
{ |
155
|
|
|
return [ |
156
|
|
|
'-2' => [ |
157
|
|
|
'state' => Order::STATE_CLOSED, |
158
|
|
|
'message' => __('B2BinPay payment error!') |
|
|
|
|
159
|
|
|
], |
160
|
|
|
'-1' => [ |
161
|
|
|
'state' => Order::STATE_CANCELED, |
162
|
|
|
'message' => __('B2BinPay payment expired!') |
163
|
|
|
], |
164
|
|
|
'3' => [ |
165
|
|
|
'state' => Order::STATE_PAYMENT_REVIEW, |
166
|
|
|
'message' => __('B2BinPay payment freeze!') |
167
|
|
|
], |
168
|
|
|
'4' => [ |
169
|
|
|
'state' => Order::STATE_CLOSED, |
170
|
|
|
'message' => __('B2BinPay payment closed!') |
171
|
|
|
] |
172
|
|
|
]; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths