|
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
|
|
|
|
|
13
|
|
|
class AuthorizeTransaction extends AbstractAmazonpayTransaction |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer |
|
17
|
|
|
* |
|
18
|
|
|
* @return \Generated\Shared\Transfer\AmazonpayCallTransfer |
|
19
|
|
|
*/ |
|
20
|
|
|
public function execute(AmazonpayCallTransfer $amazonPayCallTransfer) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->updateAuthorizationReferenceId($amazonPayCallTransfer); |
|
23
|
|
|
|
|
24
|
|
|
$amazonPayCallTransfer = parent::execute($amazonPayCallTransfer); |
|
25
|
|
|
|
|
26
|
|
|
$this->updatePaymentEntity($amazonPayCallTransfer); |
|
27
|
|
|
|
|
28
|
|
|
return $amazonPayCallTransfer; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonpayCallTransfer |
|
33
|
|
|
* |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function buildErrorMessage(AmazonpayCallTransfer $amazonpayCallTransfer) |
|
37
|
|
|
{ |
|
38
|
|
|
return AmazonPayConfig::PREFIX_AMAZONPAY_PAYMENT_ERROR . |
|
39
|
|
|
$amazonpayCallTransfer->getAmazonpayPayment() |
|
40
|
|
|
->getAuthorizationDetails() |
|
41
|
|
|
->getAuthorizationStatus() |
|
42
|
|
|
->getReasonCode(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer |
|
47
|
|
|
* |
|
48
|
|
|
* @return void |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function updateAuthorizationReferenceId(AmazonpayCallTransfer $amazonPayCallTransfer) |
|
51
|
|
|
{ |
|
52
|
|
|
$authReferenceId = $this->generateOperationReferenceId($amazonPayCallTransfer); |
|
53
|
|
|
$amazonPayCallTransfer->getAmazonpayPayment() |
|
54
|
|
|
->getAuthorizationDetails() |
|
55
|
|
|
->setAuthorizationReferenceId($authReferenceId); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer |
|
60
|
|
|
* |
|
61
|
|
|
* @return void |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function updatePaymentEntity(AmazonpayCallTransfer $amazonPayCallTransfer) |
|
64
|
|
|
{ |
|
65
|
|
|
if (!$this->isPaymentSuccess($amazonPayCallTransfer)) { |
|
66
|
|
|
return; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$isPartialProcessing = $this->paymentEntity && $this->isPartialProcessing($this->paymentEntity, $amazonPayCallTransfer); |
|
70
|
|
|
|
|
71
|
|
|
if ($isPartialProcessing) { |
|
72
|
|
|
$this->paymentEntity = $this->paymentProcessor->duplicatePaymentEntity($this->paymentEntity); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$statusDetails = $amazonPayCallTransfer->getAmazonpayPayment() |
|
76
|
|
|
->getAuthorizationDetails() |
|
77
|
|
|
->getAuthorizationStatus(); |
|
78
|
|
|
|
|
79
|
|
|
if ($this->isStateDeclined($statusDetails->getState())) { |
|
80
|
|
|
$amazonPayCallTransfer->getAmazonpayPayment()->getResponseHeader() |
|
81
|
|
|
->setIsSuccess(false) |
|
82
|
|
|
->setIsInvalidPaymentMethod($this->isInvalidPaymentMethod($amazonPayCallTransfer)) |
|
83
|
|
|
->setErrorMessage($this->buildErrorMessage($amazonPayCallTransfer)); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
if ($this->paymentEntity) { |
|
87
|
|
|
$this->paymentEntity->setStatus($statusDetails->getState()); |
|
88
|
|
|
$this->paymentEntity->save(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if ($isPartialProcessing) { |
|
92
|
|
|
$this->paymentProcessor->assignAmazonpayPaymentToItems( |
|
93
|
|
|
$this->paymentEntity, |
|
94
|
|
|
$amazonPayCallTransfer |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param string $stateName |
|
101
|
|
|
* |
|
102
|
|
|
* @return bool |
|
103
|
|
|
*/ |
|
104
|
|
|
protected function isStateDeclined($stateName) |
|
105
|
|
|
{ |
|
106
|
|
|
return in_array($stateName, [ |
|
107
|
|
|
AmazonPayConfig::STATUS_DECLINED, |
|
108
|
|
|
AmazonPayConfig::STATUS_TRANSACTION_TIMED_OUT, |
|
109
|
|
|
AmazonPayConfig::STATUS_CANCELLED, |
|
110
|
|
|
AmazonPayConfig::STATUS_SUSPENDED, |
|
111
|
|
|
AmazonPayConfig::STATUS_EXPIRED, |
|
112
|
|
|
AmazonPayConfig::STATUS_PAYMENT_METHOD_INVALID, |
|
113
|
|
|
], true); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer |
|
118
|
|
|
* |
|
119
|
|
|
* @return bool |
|
120
|
|
|
*/ |
|
121
|
|
|
protected function isInvalidPaymentMethod(AmazonpayCallTransfer $amazonPayCallTransfer) |
|
122
|
|
|
{ |
|
123
|
|
|
return ($amazonPayCallTransfer->getAmazonpayPayment() |
|
124
|
|
|
->getAuthorizationDetails() |
|
125
|
|
|
->getAuthorizationStatus() |
|
126
|
|
|
->getReasonCode() === AmazonPayConfig::REASON_CODE_PAYMENT_METHOD_INVALID); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
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