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 Generated\Shared\Transfer\AmazonpayStatusTransfer; |
12
|
|
|
use SprykerEco\Shared\Amazonpay\AmazonpayConstants; |
13
|
|
|
|
14
|
|
|
class UpdateOrderAuthorizationStatusTransaction extends AbstractAmazonpayTransaction |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonpayCallTransfer |
19
|
|
|
* |
20
|
|
|
* @return \Generated\Shared\Transfer\AmazonpayCallTransfer |
21
|
|
|
*/ |
22
|
|
|
public function execute(AmazonpayCallTransfer $amazonpayCallTransfer) |
23
|
|
|
{ |
24
|
|
|
if (!$amazonpayCallTransfer->getAmazonpayPayment() |
25
|
|
|
->getAuthorizationDetails() |
26
|
|
|
->getAmazonAuthorizationId()) { |
27
|
|
|
return $amazonpayCallTransfer; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$amazonpayCallTransfer = parent::execute($amazonpayCallTransfer); |
31
|
|
|
|
32
|
|
|
$amazonPayment = $amazonpayCallTransfer->getAmazonpayPayment(); |
33
|
|
|
|
34
|
|
|
if (!$amazonPayment->getResponseHeader()->getIsSuccess()) { |
35
|
|
|
return $amazonpayCallTransfer; |
36
|
|
|
} |
37
|
|
|
$status = $amazonPayment->getAuthorizationDetails()->getAuthorizationStatus(); |
38
|
|
|
|
39
|
|
|
if ($amazonPayment->getAuthorizationDetails()->getIdList()) { |
40
|
|
|
$this->paymentEntity->setAmazonCaptureId( |
41
|
|
|
$amazonPayment->getAuthorizationDetails()->getIdList() |
42
|
|
|
) |
43
|
|
|
->setStatus( |
44
|
|
|
$status->getIsClosed() |
45
|
|
|
? AmazonpayConstants::OMS_STATUS_CLOSED |
46
|
|
|
: AmazonpayConstants::OMS_STATUS_CAPTURE_COMPLETED |
47
|
|
|
) |
48
|
|
|
->save(); |
49
|
|
|
|
50
|
|
|
return $amazonpayCallTransfer; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($status->getIsPending()) { |
54
|
|
|
return $amazonpayCallTransfer; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$paymentStatus = $this->getPaymentStatus($status); |
58
|
|
|
|
59
|
|
|
if ($paymentStatus !== false) { |
60
|
|
|
$this->paymentEntity->setStatus($paymentStatus); |
61
|
|
|
} |
62
|
|
|
if ($this->apiResponse->getCaptureDetails() && |
63
|
|
|
$this->apiResponse->getCaptureDetails()->getAmazonCaptureId()) { |
64
|
|
|
$this->paymentEntity->setAmazonCaptureId( |
65
|
|
|
$this->apiResponse->getCaptureDetails()->getAmazonCaptureId() |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$this->paymentEntity->save(); |
70
|
|
|
|
71
|
|
|
return $amazonpayCallTransfer; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayStatusTransfer $status |
76
|
|
|
* |
77
|
|
|
* @return bool|string |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
protected function getPaymentStatus(AmazonpayStatusTransfer $status) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
if ($status->getIsDeclined()) { |
82
|
|
|
if ($status->getIsSuspended()) { |
83
|
|
|
return AmazonpayConstants::OMS_STATUS_AUTH_SUSPENDED; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if ($status->getIsTransactionTimedOut()) { |
87
|
|
|
return AmazonpayConstants::OMS_STATUS_AUTH_TRANSACTION_TIMED_OUT; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return AmazonpayConstants::OMS_STATUS_AUTH_DECLINED; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if ($status->getIsOpen()) { |
94
|
|
|
return AmazonpayConstants::OMS_STATUS_AUTH_OPEN; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
if ($status->getIsClosed()) { |
98
|
|
|
if ($status->getIsReauthorizable()) { |
99
|
|
|
return AmazonpayConstants::OMS_STATUS_AUTH_EXPIRED; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return AmazonpayConstants::OMS_STATUS_AUTH_CLOSED; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return false; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.