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