|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Apache OSL-2 |
|
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Transaction; |
|
9
|
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\AmazonpayCallTransfer; |
|
|
|
|
|
|
11
|
|
|
use SprykerEco\Shared\AmazonPay\AmazonPayConfig; |
|
12
|
|
|
use SprykerEco\Shared\AmazonPay\AmazonPayConfigInterface; |
|
13
|
|
|
use SprykerEco\Zed\AmazonPay\Business\Api\Adapter\CallAdapterInterface; |
|
14
|
|
|
use SprykerEco\Zed\AmazonPay\Business\Order\PaymentProcessorInterface; |
|
15
|
|
|
use SprykerEco\Zed\AmazonPay\Business\Order\RefundOrderInterface; |
|
16
|
|
|
use SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Transaction\Logger\TransactionLoggerInterface; |
|
17
|
|
|
|
|
18
|
|
|
class UpdateOrderRefundStatusTransaction extends AbstractAmazonpayTransaction |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var \SprykerEco\Zed\AmazonPay\Business\Order\RefundOrderInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $refundOrderModel; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param \SprykerEco\Zed\AmazonPay\Business\Api\Adapter\CallAdapterInterface $executionAdapter |
|
27
|
|
|
* @param \SprykerEco\Shared\AmazonPay\AmazonPayConfigInterface $config |
|
28
|
|
|
* @param \SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Transaction\Logger\TransactionLoggerInterface $transactionLogger |
|
29
|
|
|
* @param \SprykerEco\Zed\AmazonPay\Business\Order\PaymentProcessorInterface $paymentProcessor |
|
30
|
|
|
* @param \SprykerEco\Zed\AmazonPay\Business\Order\RefundOrderInterface $refundOrderModel |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct( |
|
33
|
|
|
CallAdapterInterface $executionAdapter, |
|
34
|
|
|
AmazonPayConfigInterface $config, |
|
35
|
|
|
TransactionLoggerInterface $transactionLogger, |
|
36
|
|
|
PaymentProcessorInterface $paymentProcessor, |
|
37
|
|
|
RefundOrderInterface $refundOrderModel |
|
38
|
|
|
) { |
|
39
|
|
|
|
|
40
|
|
|
parent::__construct($executionAdapter, $config, $transactionLogger, $paymentProcessor); |
|
41
|
|
|
|
|
42
|
|
|
$this->refundOrderModel = $refundOrderModel; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer |
|
47
|
|
|
* |
|
48
|
|
|
* @return \Generated\Shared\Transfer\AmazonpayCallTransfer |
|
49
|
|
|
*/ |
|
50
|
|
|
public function execute(AmazonpayCallTransfer $amazonPayCallTransfer) |
|
51
|
|
|
{ |
|
52
|
|
|
if (!$this->isAllowed($amazonPayCallTransfer)) { |
|
53
|
|
|
return $amazonPayCallTransfer; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$amazonPayCallTransfer = parent::execute($amazonPayCallTransfer); |
|
57
|
|
|
|
|
58
|
|
|
$this->updatePayment($amazonPayCallTransfer); |
|
59
|
|
|
|
|
60
|
|
|
return $amazonPayCallTransfer; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer |
|
65
|
|
|
* |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function isAllowed(AmazonpayCallTransfer $amazonPayCallTransfer) |
|
69
|
|
|
{ |
|
70
|
|
|
return !empty($amazonPayCallTransfer->getAmazonpayPayment()->getRefundDetails()->getAmazonRefundId()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer |
|
75
|
|
|
* |
|
76
|
|
|
* @return void |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function updatePayment(AmazonpayCallTransfer $amazonPayCallTransfer) |
|
79
|
|
|
{ |
|
80
|
|
|
if (!$this->apiResponse->getResponseHeader()->getIsSuccess()) { |
|
81
|
|
|
return; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$isPartialProcessing = $this->isPartialProcessing($this->paymentEntity, $amazonPayCallTransfer); |
|
85
|
|
|
|
|
86
|
|
|
if ($isPartialProcessing) { |
|
87
|
|
|
$this->paymentEntity = $this->paymentProcessor->duplicatePaymentEntity($this->paymentEntity); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$status = $this->apiResponse->getRefundDetails()->getRefundStatus()->getState(); |
|
91
|
|
|
|
|
92
|
|
|
$refundIsRequired = ($status === AmazonPayConfig::STATUS_COMPLETED |
|
93
|
|
|
&& $this->paymentEntity->getStatus() !== $status); |
|
94
|
|
|
|
|
95
|
|
|
$this->paymentEntity->setStatus($status); |
|
96
|
|
|
$this->paymentEntity->save(); |
|
97
|
|
|
|
|
98
|
|
|
if ($isPartialProcessing) { |
|
99
|
|
|
$this->paymentProcessor->assignAmazonpayPaymentToItems($this->paymentEntity, $amazonPayCallTransfer); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
if ($refundIsRequired) { |
|
103
|
|
|
$this->refundOrderModel->refundPayment($this->paymentEntity); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
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