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 SprykerEco\Shared\Amazonpay\AmazonpayConfigInterface; |
11
|
|
|
use SprykerEco\Zed\Amazonpay\Business\Api\Adapter\AdapterFactoryInterface; |
12
|
|
|
use SprykerEco\Zed\Amazonpay\Business\Converter\AmazonpayConverterInterface; |
13
|
|
|
use SprykerEco\Zed\Amazonpay\Business\Converter\AmazonpayTransferToEntityConverterInterface; |
14
|
|
|
use SprykerEco\Zed\Amazonpay\Business\Order\RefundOrderInterface; |
15
|
|
|
use SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\Logger\TransactionLoggerInterface; |
16
|
|
|
use SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface; |
17
|
|
|
|
18
|
|
|
class TransactionFactory implements TransactionFactoryInterface |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \SprykerEco\Zed\Amazonpay\Business\Api\Adapter\AdapterFactoryInterface |
23
|
|
|
*/ |
24
|
|
|
protected $adapterFactory; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \SprykerEco\Shared\Amazonpay\AmazonpayConfigInterface |
28
|
|
|
*/ |
29
|
|
|
protected $config; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var \SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface |
33
|
|
|
*/ |
34
|
|
|
protected $amazonpayQueryContainer; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\Logger\TransactionLoggerInterface |
38
|
|
|
*/ |
39
|
|
|
protected $transactionLogger; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var \SprykerEco\Zed\Amazonpay\Business\Converter\AmazonpayConverterInterface |
43
|
|
|
*/ |
44
|
|
|
protected $converter; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var \SprykerEco\Zed\Amazonpay\Business\Converter\AmazonpayTransferToEntityConverterInterface |
48
|
|
|
*/ |
49
|
|
|
protected $toEntityConverter; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var \SprykerEco\Zed\Amazonpay\Business\Order\RefundOrderInterface |
53
|
|
|
*/ |
54
|
|
|
protected $refundOrderModel; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param \SprykerEco\Zed\Amazonpay\Business\Api\Adapter\AdapterFactoryInterface $adapterFactory |
58
|
|
|
* @param \SprykerEco\Shared\Amazonpay\AmazonpayConfigInterface $config |
59
|
|
|
* @param \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\Logger\TransactionLoggerInterface $transactionLogger |
60
|
|
|
* @param \SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface $amazonpayQueryContainer |
61
|
|
|
* @param \SprykerEco\Zed\Amazonpay\Business\Converter\AmazonpayConverterInterface $converter |
62
|
|
|
* @param \SprykerEco\Zed\Amazonpay\Business\Converter\AmazonpayTransferToEntityConverterInterface $toEntityConverter |
63
|
|
|
* @param \SprykerEco\Zed\Amazonpay\Business\Order\RefundOrderInterface $refundOrderModel |
64
|
|
|
*/ |
65
|
|
|
public function __construct( |
66
|
|
|
AdapterFactoryInterface $adapterFactory, |
67
|
|
|
AmazonpayConfigInterface $config, |
68
|
|
|
TransactionLoggerInterface $transactionLogger, |
69
|
|
|
AmazonpayQueryContainerInterface $amazonpayQueryContainer, |
70
|
|
|
AmazonpayConverterInterface $converter, |
71
|
|
|
AmazonpayTransferToEntityConverterInterface $toEntityConverter, |
72
|
|
|
RefundOrderInterface $refundOrderModel |
73
|
|
|
) { |
74
|
|
|
$this->adapterFactory = $adapterFactory; |
75
|
|
|
$this->config = $config; |
76
|
|
|
$this->transactionLogger = $transactionLogger; |
77
|
|
|
$this->amazonpayQueryContainer = $amazonpayQueryContainer; |
78
|
|
|
$this->converter = $converter; |
79
|
|
|
$this->toEntityConverter = $toEntityConverter; |
80
|
|
|
$this->refundOrderModel = $refundOrderModel; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
85
|
|
|
*/ |
86
|
|
|
public function createConfirmOrderReferenceTransaction() |
87
|
|
|
{ |
88
|
|
|
return new ConfirmOrderReferenceTransaction( |
89
|
|
|
$this->adapterFactory->createConfirmOrderReferenceAmazonpayAdapter(), |
90
|
|
|
$this->config, |
91
|
|
|
$this->transactionLogger, |
92
|
|
|
$this->amazonpayQueryContainer, |
93
|
|
|
$this->toEntityConverter |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
99
|
|
|
*/ |
100
|
|
|
public function createSetOrderReferenceTransaction() |
101
|
|
|
{ |
102
|
|
|
return new SetOrderReferenceDetailsTransaction( |
103
|
|
|
$this->adapterFactory->createSetOrderReferenceDetailsAmazonpayAdapter(), |
104
|
|
|
$this->config, |
105
|
|
|
$this->transactionLogger, |
106
|
|
|
$this->amazonpayQueryContainer, |
107
|
|
|
$this->toEntityConverter |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
113
|
|
|
*/ |
114
|
|
|
public function createGetOrderReferenceDetailsTransaction() |
115
|
|
|
{ |
116
|
|
|
return new GetOrderReferenceDetailsTransaction( |
117
|
|
|
$this->adapterFactory->createGetOrderReferenceDetailsAmazonpayAdapter(), |
118
|
|
|
$this->config, |
119
|
|
|
$this->transactionLogger, |
120
|
|
|
$this->amazonpayQueryContainer, |
121
|
|
|
$this->toEntityConverter |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
127
|
|
|
*/ |
128
|
|
|
public function createCancelOrderTransactionSequence() |
129
|
|
|
{ |
130
|
|
|
return new TransactionSequence( |
131
|
|
|
[ |
132
|
|
|
$this->createRefundOrderTransaction(), |
133
|
|
|
$this->createCancelOrderTransaction(), |
134
|
|
|
] |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
140
|
|
|
*/ |
141
|
|
|
protected function createCancelOrderTransaction() |
142
|
|
|
{ |
143
|
|
|
return new CancelOrderTransaction( |
144
|
|
|
$this->adapterFactory->createCancelOrderAdapter(), |
145
|
|
|
$this->config, |
146
|
|
|
$this->transactionLogger, |
147
|
|
|
$this->amazonpayQueryContainer, |
148
|
|
|
$this->toEntityConverter |
149
|
|
|
); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
154
|
|
|
*/ |
155
|
|
|
public function createAuthorizeTransaction() |
156
|
|
|
{ |
157
|
|
|
return new AuthorizeTransaction( |
158
|
|
|
$this->adapterFactory->createAuthorizeAdapter(), |
159
|
|
|
$this->config, |
160
|
|
|
$this->transactionLogger, |
161
|
|
|
$this->amazonpayQueryContainer, |
162
|
|
|
$this->toEntityConverter |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
168
|
|
|
*/ |
169
|
|
|
public function createReauthorizeExpiredOrderTransaction() |
170
|
|
|
{ |
171
|
|
|
return new TransactionSequence( |
172
|
|
|
[ |
173
|
|
|
$this->createReauthorizeOrderTransaction(), |
174
|
|
|
$this->createUpdateOrderAuthorizationStatusTransaction(), |
175
|
|
|
] |
176
|
|
|
); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
181
|
|
|
*/ |
182
|
|
|
public function createReauthorizeOrderTransaction() |
183
|
|
|
{ |
184
|
|
|
return new ReauthorizeOrderTransaction( |
185
|
|
|
$this->adapterFactory->createAuthorizeAdapter(), |
186
|
|
|
$this->config, |
187
|
|
|
$this->transactionLogger, |
188
|
|
|
$this->amazonpayQueryContainer, |
189
|
|
|
$this->toEntityConverter |
190
|
|
|
); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
195
|
|
|
*/ |
196
|
|
|
protected function createCaptureOrderTransaction() |
197
|
|
|
{ |
198
|
|
|
return new CaptureOrderTransaction( |
199
|
|
|
$this->adapterFactory->createCaptureOrderAdapter(), |
200
|
|
|
$this->config, |
201
|
|
|
$this->transactionLogger, |
202
|
|
|
$this->amazonpayQueryContainer, |
203
|
|
|
$this->toEntityConverter |
204
|
|
|
); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
209
|
|
|
*/ |
210
|
|
|
protected function createAuthorizeCaptureNowTransaction() |
211
|
|
|
{ |
212
|
|
|
return new AuthorizeOrderIfRequiredTransaction( |
213
|
|
|
$this->adapterFactory->createAuthorizeCaptureNowAdapter(), |
214
|
|
|
$this->config, |
215
|
|
|
$this->transactionLogger, |
216
|
|
|
$this->amazonpayQueryContainer, |
217
|
|
|
$this->toEntityConverter |
218
|
|
|
); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
223
|
|
|
*/ |
224
|
|
|
public function createCaptureAuthorizedTransaction() |
225
|
|
|
{ |
226
|
|
|
return new TransactionSequence( |
227
|
|
|
[ |
228
|
|
|
$this->createAuthorizeCaptureNowTransaction(), |
229
|
|
|
$this->createUpdateOrderCaptureStatusTransaction(), |
230
|
|
|
$this->createCaptureOrderTransaction(), |
231
|
|
|
] |
232
|
|
|
); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
237
|
|
|
*/ |
238
|
|
|
public function createCloseCapturedOrderTransaction() |
239
|
|
|
{ |
240
|
|
|
return new TransactionSequence( |
241
|
|
|
[ |
242
|
|
|
$this->createGetOrderReferenceDetailsTransaction(), |
243
|
|
|
$this->createCloseOrderTransaction(), |
244
|
|
|
] |
245
|
|
|
); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
250
|
|
|
*/ |
251
|
|
|
protected function createCloseOrderTransaction() |
252
|
|
|
{ |
253
|
|
|
return new CloseOrderTransaction( |
254
|
|
|
$this->adapterFactory->createCloseOrderAdapter(), |
255
|
|
|
$this->config, |
256
|
|
|
$this->transactionLogger, |
257
|
|
|
$this->amazonpayQueryContainer, |
258
|
|
|
$this->toEntityConverter |
259
|
|
|
); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
264
|
|
|
*/ |
265
|
|
|
public function createRefundOrderTransaction() |
266
|
|
|
{ |
267
|
|
|
return new RefundOrderTransaction( |
268
|
|
|
$this->adapterFactory->createRefundOrderAdapter(), |
269
|
|
|
$this->config, |
270
|
|
|
$this->transactionLogger, |
271
|
|
|
$this->amazonpayQueryContainer, |
272
|
|
|
$this->toEntityConverter |
273
|
|
|
); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
278
|
|
|
*/ |
279
|
|
|
public function createUpdateOrderRefundStatusTransaction() |
280
|
|
|
{ |
281
|
|
|
return new UpdateOrderRefundStatusTransaction( |
282
|
|
|
$this->adapterFactory->createGetOrderRefundDetailsAdapter(), |
283
|
|
|
$this->config, |
284
|
|
|
$this->transactionLogger, |
285
|
|
|
$this->amazonpayQueryContainer, |
286
|
|
|
$this->toEntityConverter, |
287
|
|
|
$this->refundOrderModel |
288
|
|
|
); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
293
|
|
|
*/ |
294
|
|
|
public function createUpdateOrderAuthorizationStatusTransaction() |
295
|
|
|
{ |
296
|
|
|
return new UpdateOrderAuthorizationStatusTransaction( |
297
|
|
|
$this->adapterFactory->createGetOrderAuthorizationDetailsAdapter(), |
298
|
|
|
$this->config, |
299
|
|
|
$this->transactionLogger, |
300
|
|
|
$this->amazonpayQueryContainer, |
301
|
|
|
$this->toEntityConverter |
302
|
|
|
); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
307
|
|
|
*/ |
308
|
|
|
public function createUpdateOrderCaptureStatusHandler() |
309
|
|
|
{ |
310
|
|
|
return new TransactionSequence( |
311
|
|
|
[ |
312
|
|
|
$this->createUpdateOrderAuthorizationStatusTransaction(), |
313
|
|
|
$this->createUpdateOrderCaptureStatusTransaction(), |
314
|
|
|
] |
315
|
|
|
); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
320
|
|
|
*/ |
321
|
|
|
public function createUpdateOrderCaptureStatusTransaction() |
322
|
|
|
{ |
323
|
|
|
return new UpdateOrderCaptureStatusTransaction( |
324
|
|
|
$this->adapterFactory->createGetOrderCaptureDetailsAdapter(), |
325
|
|
|
$this->config, |
326
|
|
|
$this->transactionLogger, |
327
|
|
|
$this->amazonpayQueryContainer, |
328
|
|
|
$this->toEntityConverter |
329
|
|
|
); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface |
334
|
|
|
*/ |
335
|
|
|
public function createHandleDeclinedOrderTransaction() |
336
|
|
|
{ |
337
|
|
|
return new HandleDeclinedOrderTransaction( |
338
|
|
|
$this->createGetOrderReferenceDetailsTransaction(), |
339
|
|
|
$this->createCancelOrderTransaction() |
340
|
|
|
); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\TransactionCollectionInterface |
345
|
|
|
*/ |
346
|
|
|
public function createConfirmPurchaseTransaction() |
347
|
|
|
{ |
348
|
|
|
return new TransactionCollection( |
349
|
|
|
[ |
350
|
|
|
$this->createSetOrderReferenceTransaction(), |
351
|
|
|
$this->createConfirmOrderReferenceTransaction(), |
352
|
|
|
$this->createGetOrderReferenceDetailsTransaction(), |
353
|
|
|
$this->createAuthorizeTransaction(), |
354
|
|
|
$this->createHandleDeclinedOrderTransaction(), |
355
|
|
|
], |
356
|
|
|
$this->converter |
357
|
|
|
); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
} |
361
|
|
|
|