b2binpay /
magento2
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace B2Binpay\Payment\Controller\Callback; |
||||||
| 4 | |||||||
| 5 | use Magento\Sales\Model\Order; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 6 | use Magento\Framework\App\Action\Context; |
||||||
|
0 ignored issues
–
show
The type
Magento\Framework\App\Action\Context was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 7 | use Magento\Framework\Controller\Result\RawFactory; |
||||||
|
0 ignored issues
–
show
The type
Magento\Framework\Controller\Result\RawFactory was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 8 | use B2Binpay\Payment\Gateway\Validator\CallbackValidator; |
||||||
| 9 | use B2Binpay\AmountFactory; |
||||||
|
0 ignored issues
–
show
The type
B2Binpay\AmountFactory was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 10 | use Psr\Log\LoggerInterface; |
||||||
|
0 ignored issues
–
show
The type
Psr\Log\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 11 | |||||||
| 12 | class Index extends \Magento\Framework\App\Action\Action |
||||||
|
0 ignored issues
–
show
The type
Magento\Framework\App\Action\Action was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 13 | { |
||||||
| 14 | /** |
||||||
| 15 | * @var RawFactory |
||||||
| 16 | */ |
||||||
| 17 | protected $rawResultFactory; |
||||||
| 18 | |||||||
| 19 | /** |
||||||
| 20 | * @var Context |
||||||
| 21 | */ |
||||||
| 22 | protected $context; |
||||||
| 23 | |||||||
| 24 | /** |
||||||
| 25 | * @var CallbackValidator |
||||||
| 26 | */ |
||||||
| 27 | protected $validator; |
||||||
| 28 | |||||||
| 29 | /** |
||||||
| 30 | * @var LoggerInterface |
||||||
| 31 | */ |
||||||
| 32 | protected $logger; |
||||||
| 33 | |||||||
| 34 | /** |
||||||
| 35 | * @var AmountFactory |
||||||
| 36 | */ |
||||||
| 37 | private $amountFactory; |
||||||
| 38 | |||||||
| 39 | /** |
||||||
| 40 | * Callback controller. |
||||||
| 41 | * |
||||||
| 42 | * @param Context $context |
||||||
| 43 | * @param RawFactory $rawResultFactory |
||||||
| 44 | * @param CallbackValidator $validator |
||||||
| 45 | * @param AmountFactory $amountFactory |
||||||
| 46 | * @param LoggerInterface $logger |
||||||
| 47 | */ |
||||||
| 48 | public function __construct( |
||||||
| 49 | Context $context, |
||||||
| 50 | RawFactory $rawResultFactory, |
||||||
| 51 | CallbackValidator $validator, |
||||||
| 52 | AmountFactory $amountFactory, |
||||||
| 53 | LoggerInterface $logger |
||||||
| 54 | ) { |
||||||
| 55 | $this->context = $context; |
||||||
| 56 | $this->rawResultFactory = $rawResultFactory; |
||||||
| 57 | $this->validator = $validator; |
||||||
| 58 | $this->amountFactory = $amountFactory; |
||||||
| 59 | $this->logger = $logger; |
||||||
| 60 | parent::__construct($context); |
||||||
| 61 | } |
||||||
| 62 | |||||||
| 63 | /** |
||||||
| 64 | * {@inheritdoc} |
||||||
| 65 | */ |
||||||
| 66 | public function execute() |
||||||
| 67 | { |
||||||
| 68 | $request = $this->context->getRequest(); |
||||||
| 69 | $result = $this->rawResultFactory->create(); |
||||||
| 70 | |||||||
| 71 | $validationResult = $this->validator->validate(['request' => $request]); |
||||||
| 72 | |||||||
| 73 | $validation = $validationResult->getFailsDescription(); |
||||||
| 74 | |||||||
| 75 | if (!$validationResult->isValid()) { |
||||||
| 76 | $result->setStatusHeader($validation['status'], '1.1', $validation['message']); |
||||||
| 77 | |||||||
| 78 | return $result; |
||||||
| 79 | } |
||||||
| 80 | |||||||
| 81 | $order = $validation['order']; |
||||||
| 82 | $payment = $order->getPayment(); |
||||||
| 83 | $params = $request->getParams(); |
||||||
| 84 | |||||||
| 85 | $billStatus = (string)$params['status']; |
||||||
| 86 | |||||||
| 87 | if ('2' === $billStatus) { |
||||||
| 88 | if ($params['amount'] === $params['actual_amount']) { |
||||||
| 89 | $totalDue = $order->getTotalDue(); |
||||||
| 90 | |||||||
| 91 | $payment->authorize(false, $totalDue); |
||||||
| 92 | $payment->registerCaptureNotification($totalDue); |
||||||
| 93 | |||||||
| 94 | $order->addStatusToHistory( |
||||||
| 95 | $order::STATE_PROCESSING, |
||||||
| 96 | __('B2BinPay payment complete!') |
||||||
|
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 97 | ); |
||||||
| 98 | } else { |
||||||
| 99 | $actualAmount = $this->amountFactory->create( |
||||||
| 100 | $params['actual_amount'], |
||||||
| 101 | $params['currency']['iso'], |
||||||
| 102 | $params['pow'] |
||||||
| 103 | )->getValue(); |
||||||
| 104 | |||||||
| 105 | $order->addStatusToHistory( |
||||||
| 106 | $order::STATE_PAYMENT_REVIEW, |
||||||
| 107 | __('B2BinPay received payment: ' . $actualAmount . $params['currency']['alpha']) |
||||||
| 108 | ); |
||||||
| 109 | } |
||||||
| 110 | } |
||||||
| 111 | |||||||
| 112 | $stateList = $this->getStateDesc(); |
||||||
| 113 | |||||||
| 114 | if (!empty($stateList[$billStatus])) { |
||||||
| 115 | $order->addStatusToHistory( |
||||||
| 116 | $stateList[$billStatus]['state'], |
||||||
| 117 | $stateList[$billStatus]['message'] |
||||||
| 118 | ); |
||||||
| 119 | } |
||||||
| 120 | |||||||
| 121 | $order->save(); |
||||||
| 122 | |||||||
| 123 | $result->setStatusHeader('200', '1.1', 'OK'); |
||||||
| 124 | $result->setContents('OK'); |
||||||
| 125 | |||||||
| 126 | return $result; |
||||||
| 127 | } |
||||||
| 128 | |||||||
| 129 | /** |
||||||
| 130 | * @return array |
||||||
| 131 | */ |
||||||
| 132 | private function getStateDesc() |
||||||
| 133 | { |
||||||
| 134 | return [ |
||||||
| 135 | '-2' => [ |
||||||
| 136 | 'state' => Order::STATE_CLOSED, |
||||||
| 137 | 'message' => __('B2BinPay payment error!') |
||||||
|
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 138 | ], |
||||||
| 139 | '-1' => [ |
||||||
| 140 | 'state' => Order::STATE_CANCELED, |
||||||
| 141 | 'message' => __('B2BinPay payment expired!') |
||||||
| 142 | ], |
||||||
| 143 | '3' => [ |
||||||
| 144 | 'state' => Order::STATE_PAYMENT_REVIEW, |
||||||
| 145 | 'message' => __('B2BinPay payment freeze!') |
||||||
| 146 | ], |
||||||
| 147 | '4' => [ |
||||||
| 148 | 'state' => Order::STATE_CLOSED, |
||||||
| 149 | 'message' => __('B2BinPay payment closed!') |
||||||
| 150 | ] |
||||||
| 151 | ]; |
||||||
| 152 | } |
||||||
| 153 | } |
||||||
| 154 |
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