|
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\Ipn; |
|
9
|
|
|
|
|
10
|
|
|
use Exception; |
|
11
|
|
|
use Generated\Shared\Transfer\AmazonpayIpnPaymentRequestTransfer; |
|
|
|
|
|
|
12
|
|
|
use Orm\Zed\AmazonPay\Persistence\SpyPaymentAmazonpay; |
|
|
|
|
|
|
13
|
|
|
use Propel\Runtime\Collection\ObjectCollection; |
|
14
|
|
|
use Propel\Runtime\Propel; |
|
15
|
|
|
use Spryker\Zed\PropelOrm\Business\Transaction\DatabaseTransactionHandlerTrait; |
|
16
|
|
|
use SprykerEco\Shared\AmazonPay\AmazonPayConfigInterface; |
|
17
|
|
|
use SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Ipn\Logger\IpnRequestLoggerInterface; |
|
18
|
|
|
use SprykerEco\Zed\AmazonPay\Dependency\Facade\AmazonPayToOmsInterface; |
|
19
|
|
|
use SprykerEco\Zed\AmazonPay\Persistence\AmazonPayQueryContainerInterface; |
|
20
|
|
|
|
|
21
|
|
|
abstract class IpnAbstractTransferRequestHandler implements IpnRequestHandlerInterface |
|
22
|
|
|
{ |
|
23
|
|
|
use DatabaseTransactionHandlerTrait; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var \SprykerEco\Zed\AmazonPay\Dependency\Facade\AmazonPayToOmsInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $omsFacade; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \SprykerEco\Zed\AmazonPay\Persistence\AmazonPayQueryContainerInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $queryContainer; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var \SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Ipn\Logger\IpnRequestLoggerInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $ipnRequestLogger; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var \SprykerEco\Shared\AmazonPay\AmazonPayConfigInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $config; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param \SprykerEco\Zed\AmazonPay\Dependency\Facade\AmazonPayToOmsInterface $omsFacade |
|
47
|
|
|
* @param \SprykerEco\Zed\AmazonPay\Persistence\AmazonPayQueryContainerInterface $queryContainer |
|
48
|
|
|
* @param \SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Ipn\Logger\IpnRequestLoggerInterface $ipnRequestLogger |
|
49
|
|
|
* @param \SprykerEco\Shared\AmazonPay\AmazonPayConfigInterface $config |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct( |
|
52
|
|
|
AmazonPayToOmsInterface $omsFacade, |
|
53
|
|
|
AmazonPayQueryContainerInterface $queryContainer, |
|
54
|
|
|
IpnRequestLoggerInterface $ipnRequestLogger, |
|
55
|
|
|
AmazonPayConfigInterface $config |
|
56
|
|
|
) { |
|
57
|
|
|
$this->omsFacade = $omsFacade; |
|
58
|
|
|
$this->queryContainer = $queryContainer; |
|
59
|
|
|
$this->ipnRequestLogger = $ipnRequestLogger; |
|
60
|
|
|
$this->config = $config; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayIpnPaymentRequestTransfer $paymentRequestTransfer |
|
65
|
|
|
* |
|
66
|
|
|
* @return void |
|
67
|
|
|
*/ |
|
68
|
|
|
public function handle(AmazonpayIpnPaymentRequestTransfer $paymentRequestTransfer) |
|
69
|
|
|
{ |
|
70
|
|
|
$repeatable = 2; |
|
71
|
|
|
while ($repeatable-- > 0) { |
|
72
|
|
|
try { |
|
73
|
|
|
$this->handleDatabaseTransaction(function () use ($paymentRequestTransfer) { |
|
74
|
|
|
if ($this->config->getEnableIsolateLevelRead()) { |
|
75
|
|
|
Propel::getConnection()->exec('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;'); |
|
76
|
|
|
} |
|
77
|
|
|
Propel::disableInstancePooling(); |
|
78
|
|
|
|
|
79
|
|
|
$this->handleTransactional($paymentRequestTransfer); |
|
80
|
|
|
}); |
|
81
|
|
|
|
|
82
|
|
|
break; |
|
83
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayIpnPaymentRequestTransfer $paymentRequestTransfer |
|
90
|
|
|
* |
|
91
|
|
|
* @return void |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function handleTransactional(AmazonpayIpnPaymentRequestTransfer $paymentRequestTransfer) |
|
94
|
|
|
{ |
|
95
|
|
|
$paymentEntity = $this->retrievePaymentEntity($paymentRequestTransfer); |
|
96
|
|
|
|
|
97
|
|
|
if ($paymentEntity === null) { |
|
98
|
|
|
return; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$paymentEntity->setStatus($this->getStatusName()); |
|
102
|
|
|
$paymentEntity->save(); |
|
103
|
|
|
|
|
104
|
|
|
$this->omsFacade->triggerEvent( |
|
105
|
|
|
$this->getOmsEventId(), |
|
106
|
|
|
$this->getAffectedSalesOrderItems($paymentEntity), |
|
107
|
|
|
[] |
|
108
|
|
|
); |
|
109
|
|
|
$this->omsFacade->checkConditions(); |
|
110
|
|
|
|
|
111
|
|
|
$this->ipnRequestLogger->log($paymentRequestTransfer, $paymentEntity); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param \Orm\Zed\AmazonPay\Persistence\SpyPaymentAmazonpay $paymentEntity |
|
116
|
|
|
* |
|
117
|
|
|
* @return \Propel\Runtime\Collection\ObjectCollection | \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function getAffectedSalesOrderItems(SpyPaymentAmazonpay $paymentEntity) |
|
120
|
|
|
{ |
|
121
|
|
|
$items = new ObjectCollection(); |
|
122
|
|
|
|
|
123
|
|
|
foreach ($paymentEntity->getSpyPaymentAmazonpaySalesOrderItems() as $amazonpaySalesOrderItem) { |
|
124
|
|
|
$items[] = $amazonpaySalesOrderItem->getSpySalesOrderItem(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return $items; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param \Generated\Shared\Transfer\AmazonpayIpnPaymentRequestTransfer $paymentRequestTransfer |
|
132
|
|
|
* |
|
133
|
|
|
* @return \Orm\Zed\AmazonPay\Persistence\SpyPaymentAmazonpay|null |
|
134
|
|
|
*/ |
|
135
|
|
|
abstract protected function retrievePaymentEntity(AmazonpayIpnPaymentRequestTransfer $paymentRequestTransfer); |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return string |
|
139
|
|
|
*/ |
|
140
|
|
|
abstract protected function getOmsEventId(); |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return string |
|
144
|
|
|
*/ |
|
145
|
|
|
abstract protected function getStatusName(); |
|
146
|
|
|
} |
|
147
|
|
|
|
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