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 SprykerEco\Shared\Amazonpay\AmazonpayConstants; |
11
|
|
|
use Spryker\Shared\Kernel\Transfer\AbstractTransfer; |
12
|
|
|
use SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\Logger\IpnRequestLoggerInterface; |
13
|
|
|
use SprykerEco\Zed\Amazonpay\Dependency\Facade\AmazonpayToOmsInterface; |
14
|
|
|
use SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface; |
15
|
|
|
|
16
|
|
|
class IpnRequestFactory implements IpnRequestFactoryInterface |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \SprykerEco\Zed\Amazonpay\Dependency\Facade\AmazonpayToOmsInterface $omsFacade |
21
|
|
|
*/ |
22
|
|
|
protected $omsFacade; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var \SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface $amazonpayQueryContainer |
26
|
|
|
*/ |
27
|
|
|
protected $amazonpayQueryContainer; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\Logger\IpnRequestLoggerInterface $ipnRequestLogger |
31
|
|
|
*/ |
32
|
|
|
protected $ipnRequestLogger; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param \SprykerEco\Zed\Amazonpay\Dependency\Facade\AmazonpayToOmsInterface $omsFacade |
36
|
|
|
* @param \SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface $amazonpayQueryContainer |
37
|
|
|
* @param \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\Logger\IpnRequestLoggerInterface $ipnRequestLogger |
38
|
|
|
*/ |
39
|
|
|
public function __construct( |
40
|
|
|
AmazonpayToOmsInterface $omsFacade, |
41
|
|
|
AmazonpayQueryContainerInterface $amazonpayQueryContainer, |
42
|
|
|
IpnRequestLoggerInterface $ipnRequestLogger |
43
|
|
|
) { |
44
|
|
|
$this->omsFacade = $omsFacade; |
45
|
|
|
$this->amazonpayQueryContainer = $amazonpayQueryContainer; |
46
|
|
|
$this->ipnRequestLogger = $ipnRequestLogger; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer | \Generated\Shared\Transfer\AmazonpayIpnPaymentAuthorizeRequestTransfer $ipnRequest |
|
|
|
|
51
|
|
|
* |
52
|
|
|
* @throws IpnHandlerNotFoundException |
53
|
|
|
* |
54
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\IpnRequestHandlerInterface |
55
|
|
|
*/ |
56
|
|
|
public function createConcreteIpnRequestHandler(AbstractTransfer $ipnRequest) |
57
|
|
|
{ |
58
|
|
|
switch ($ipnRequest->getMessage()->getNotificationType()) { |
|
|
|
|
59
|
|
|
case AmazonpayConstants::IPN_REQUEST_TYPE_PAYMENT_AUTHORIZE: |
60
|
|
|
return $this->createIpnPaymentAuthorizeHandler($ipnRequest); |
61
|
|
|
|
62
|
|
|
case AmazonpayConstants::IPN_REQUEST_TYPE_PAYMENT_CAPTURE: |
63
|
|
|
return $this->createIpnPaymentCaptureHandler($ipnRequest); |
64
|
|
|
|
65
|
|
|
case AmazonpayConstants::IPN_REQUEST_TYPE_PAYMENT_REFUND: |
66
|
|
|
return $this->createIpnPaymentRefundHandler($ipnRequest); |
67
|
|
|
|
68
|
|
|
case AmazonpayConstants::IPN_REQUEST_TYPE_ORDER_REFERENCE_NOTIFICATION: |
69
|
|
|
return $this->createIpnOrderReferenceHandler($ipnRequest); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
throw new IpnHandlerNotFoundException('Unknown IPN Notification type: ' . |
73
|
|
|
$ipnRequest->getMessage()->getNotificationType()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer | \Generated\Shared\Transfer\AmazonpayIpnPaymentAuthorizeRequestTransfer $ipnRequest |
78
|
|
|
* |
79
|
|
|
* @throws IpnHandlerNotFoundException |
80
|
|
|
* |
81
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\IpnRequestHandlerInterface |
82
|
|
|
*/ |
83
|
|
|
protected function createIpnPaymentAuthorizeHandler(AbstractTransfer $ipnRequest) |
84
|
|
|
{ |
85
|
|
|
if ($ipnRequest->getAuthorizationDetails()->getAuthorizationStatus()->getIsSuspended()) { |
|
|
|
|
86
|
|
|
return new IpnPaymentAuthorizeSuspendedHandler( |
87
|
|
|
$this->omsFacade, |
88
|
|
|
$this->amazonpayQueryContainer, |
89
|
|
|
$this->ipnRequestLogger |
90
|
|
|
); |
91
|
|
|
} elseif ($ipnRequest->getAuthorizationDetails()->getAuthorizationStatus()->getIsDeclined()) { |
92
|
|
|
return new IpnPaymentAuthorizeDeclineHandler( |
93
|
|
|
$this->omsFacade, |
94
|
|
|
$this->amazonpayQueryContainer, |
95
|
|
|
$this->ipnRequestLogger |
96
|
|
|
); |
97
|
|
|
} elseif ($ipnRequest->getAuthorizationDetails()->getAuthorizationStatus()->getIsOpen()) { |
98
|
|
|
return new IpnPaymentAuthorizeOpenHandler( |
99
|
|
|
$this->omsFacade, |
100
|
|
|
$this->amazonpayQueryContainer, |
101
|
|
|
$this->ipnRequestLogger |
102
|
|
|
); |
103
|
|
|
} elseif ($ipnRequest->getAuthorizationDetails()->getAuthorizationStatus()->getIsClosed()) { |
104
|
|
|
return new IpnPaymentAuthorizeClosedHandler( |
105
|
|
|
$this->omsFacade, |
106
|
|
|
$this->amazonpayQueryContainer, |
107
|
|
|
$this->ipnRequestLogger |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
throw new IpnHandlerNotFoundException('No IPN handler for auth payment and status ' . |
112
|
|
|
$ipnRequest->getAuthorizationDetails()->getAuthorizationStatus()->getState()); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer | \Generated\Shared\Transfer\AmazonpayIpnPaymentCaptureRequestTransfer $ipnRequest |
|
|
|
|
117
|
|
|
* |
118
|
|
|
* @throws IpnHandlerNotFoundException |
119
|
|
|
* |
120
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\IpnRequestHandlerInterface |
121
|
|
|
*/ |
122
|
|
|
protected function createIpnPaymentCaptureHandler(AbstractTransfer $ipnRequest) |
123
|
|
|
{ |
124
|
|
|
if ($ipnRequest->getCaptureDetails()->getCaptureStatus()->getIsDeclined()) { |
|
|
|
|
125
|
|
|
return new IpnPaymentCaptureDeclineHandler( |
126
|
|
|
$this->omsFacade, |
127
|
|
|
$this->amazonpayQueryContainer, |
128
|
|
|
$this->ipnRequestLogger |
129
|
|
|
); |
130
|
|
|
} elseif ($ipnRequest->getCaptureDetails()->getCaptureStatus()->getIsCompleted()) { |
131
|
|
|
return new IpnPaymentCaptureCompletedHandler( |
132
|
|
|
$this->omsFacade, |
133
|
|
|
$this->amazonpayQueryContainer, |
134
|
|
|
$this->ipnRequestLogger |
135
|
|
|
); |
136
|
|
|
} elseif ($ipnRequest->getCaptureDetails()->getCaptureStatus()->getIsClosed()) { |
137
|
|
|
return new IpnEmptyHandler(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
throw new IpnHandlerNotFoundException('No IPN handler for capture and status ' . |
141
|
|
|
$ipnRequest->getCaptureDetails()->getCaptureStatus()->getState()); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer | \Generated\Shared\Transfer\AmazonpayIpnPaymentRefundRequestTransfer $ipnRequest |
|
|
|
|
146
|
|
|
* |
147
|
|
|
* @throws IpnHandlerNotFoundException |
148
|
|
|
* |
149
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\IpnRequestHandlerInterface |
150
|
|
|
*/ |
151
|
|
|
protected function createIpnPaymentRefundHandler(AbstractTransfer $ipnRequest) |
152
|
|
|
{ |
153
|
|
|
if ($ipnRequest->getRefundDetails()->getRefundStatus()->getIsDeclined()) { |
|
|
|
|
154
|
|
|
return new IpnPaymentRefundDeclineHandler( |
155
|
|
|
$this->omsFacade, |
156
|
|
|
$this->amazonpayQueryContainer, |
157
|
|
|
$this->ipnRequestLogger |
158
|
|
|
); |
159
|
|
|
} elseif ($ipnRequest->getRefundDetails()->getRefundStatus()->getIsCompleted()) { |
160
|
|
|
return new IpnPaymentRefundCompletedHandler( |
161
|
|
|
$this->omsFacade, |
162
|
|
|
$this->amazonpayQueryContainer, |
163
|
|
|
$this->ipnRequestLogger |
164
|
|
|
); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
throw new IpnHandlerNotFoundException('No IPN handler for payment refund and status ' . |
168
|
|
|
$ipnRequest->getRefundDetails()->getRefundStatus()->getState()); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer | \Generated\Shared\Transfer\AmazonpayIpnOrderReferenceNotificationTransfer $ipnRequest |
|
|
|
|
173
|
|
|
* |
174
|
|
|
* @throws IpnHandlerNotFoundException |
175
|
|
|
* |
176
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\IpnRequestHandlerInterface |
177
|
|
|
*/ |
178
|
|
|
protected function createIpnOrderReferenceHandler(AbstractTransfer $ipnRequest) |
179
|
|
|
{ |
180
|
|
|
if ($ipnRequest->getOrderReferenceStatus()->getIsOpen()) { |
|
|
|
|
181
|
|
|
return new IpnOrderReferenceOpenHandler( |
182
|
|
|
$this->omsFacade, |
183
|
|
|
$this->amazonpayQueryContainer, |
184
|
|
|
$this->ipnRequestLogger |
185
|
|
|
); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
if ($ipnRequest->getOrderReferenceStatus()->getIsClosed()) { |
189
|
|
|
if ($ipnRequest->getOrderReferenceStatus()->getIsClosedByAmazon()) { |
190
|
|
|
return new IpnOrderReferenceClosedHandler( |
191
|
|
|
$this->omsFacade, |
192
|
|
|
$this->amazonpayQueryContainer, |
193
|
|
|
$this->ipnRequestLogger |
194
|
|
|
); |
195
|
|
|
} else { |
196
|
|
|
return new IpnEmptyHandler( |
197
|
|
|
$this->omsFacade, |
|
|
|
|
198
|
|
|
$this->amazonpayQueryContainer, |
199
|
|
|
$this->ipnRequestLogger |
200
|
|
|
); |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
if ($ipnRequest->getOrderReferenceStatus()->getIsSuspended()) { |
205
|
|
|
return new IpnOrderReferenceSuspendedHandler( |
206
|
|
|
$this->omsFacade, |
207
|
|
|
$this->amazonpayQueryContainer, |
208
|
|
|
$this->ipnRequestLogger |
209
|
|
|
); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
throw new IpnHandlerNotFoundException('No IPN handler for order reference and status ' . |
213
|
|
|
$ipnRequest->getOrderReferenceStatus()->getState()); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
} |
217
|
|
|
|
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