|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\Braintree\Business; |
|
9
|
|
|
|
|
10
|
|
|
use Spryker\Zed\Kernel\Business\AbstractBusinessFactory; |
|
11
|
|
|
use SprykerEco\Zed\Braintree\BraintreeDependencyProvider; |
|
12
|
|
|
use SprykerEco\Zed\Braintree\Business\Hook\PostSaveHook; |
|
13
|
|
|
use SprykerEco\Zed\Braintree\Business\Hook\PostSaveHookInterface; |
|
14
|
|
|
use SprykerEco\Zed\Braintree\Business\Log\TransactionStatusLog; |
|
15
|
|
|
use SprykerEco\Zed\Braintree\Business\Log\TransactionStatusLogInterface; |
|
16
|
|
|
use SprykerEco\Zed\Braintree\Business\Order\Saver; |
|
17
|
|
|
use SprykerEco\Zed\Braintree\Business\Order\SaverInterface; |
|
18
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Filter\PaypalExpressPaymentMethodFilter; |
|
19
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Filter\PaypalExpressPaymentMethodFilterInterface; |
|
20
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\AuthorizeTransaction; |
|
21
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\CaptureItemsTransaction; |
|
22
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\CaptureOrderTransaction; |
|
23
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\AuthorizeTransactionHandler; |
|
24
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\AuthorizeTransactionHandlerInterface; |
|
25
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\CaptureItemsTransactionHandler; |
|
26
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\CaptureItemsTransactionHandlerInterface; |
|
27
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\CaptureOrderTransactionHandler; |
|
28
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\CaptureOrderTransactionHandlerInterface; |
|
29
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\PreCheckTransactionHandler; |
|
30
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\PreCheckTransactionHandlerInterface; |
|
31
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RefundItemsTransactionHandler; |
|
32
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RefundItemsTransactionHandlerInterface; |
|
33
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RefundOrderTransactionHandler; |
|
34
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RefundOrderTransactionHandlerInterface; |
|
35
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RevertTransactionHandler; |
|
36
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RevertTransactionHandlerInterface; |
|
37
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\ShipmentRefundTransactionHandler; |
|
38
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\ShipmentRefundTransactionHandlerInterface; |
|
39
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\ShipmentTransactionHandler; |
|
40
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\ShipmentTransactionHandlerInterface; |
|
41
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\PaymentTransactionMetaVisitor; |
|
42
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\TransactionMetaVisitorComposite; |
|
43
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\TransactionMetaVisitorInterface; |
|
44
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\PreCheckTransaction; |
|
45
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\RefundItemsTransaction; |
|
46
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\RefundOrderTransaction; |
|
47
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\RevertTransaction; |
|
48
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\ShipmentRefundTransaction; |
|
49
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\ShipmentTransaction; |
|
50
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface; |
|
51
|
|
|
use SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToMoneyFacadeInterface; |
|
52
|
|
|
use SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToRefundFacadeInterface; |
|
53
|
|
|
use SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToSalesFacadeInterface; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @method \SprykerEco\Zed\Braintree\Persistence\BraintreeQueryContainerInterface getQueryContainer() |
|
57
|
|
|
* @method \SprykerEco\Zed\Braintree\BraintreeConfig getConfig() |
|
58
|
|
|
* @method \SprykerEco\Zed\Braintree\Persistence\BraintreeRepositoryInterface getRepository() |
|
59
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
|
60
|
|
|
* @method \SprykerEco\Zed\Braintree\Persistence\BraintreeEntityManagerInterface getEntityManager() |
|
61
|
|
|
*/ |
|
62
|
|
|
class BraintreeBusinessFactory extends AbstractBusinessFactory |
|
63
|
|
|
{ |
|
64
|
|
|
/** |
|
65
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\AuthorizeTransactionHandlerInterface |
|
66
|
|
|
*/ |
|
67
|
|
|
public function createAuthorizeTransactionHandler(): AuthorizeTransactionHandlerInterface |
|
68
|
|
|
{ |
|
69
|
|
|
return new AuthorizeTransactionHandler( |
|
70
|
|
|
$this->createAuthorizeTransaction(), |
|
71
|
|
|
$this->createDefaultTransactionMetaVisitor() |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\CaptureItemsTransactionHandlerInterface |
|
77
|
|
|
*/ |
|
78
|
|
|
public function createCaptureItemsTransactionHandler(): CaptureItemsTransactionHandlerInterface |
|
79
|
|
|
{ |
|
80
|
|
|
return new CaptureItemsTransactionHandler( |
|
81
|
|
|
$this->createCaptureItemsTransaction(), |
|
82
|
|
|
$this->createDefaultTransactionMetaVisitor() |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\CaptureOrderTransactionHandlerInterface |
|
88
|
|
|
*/ |
|
89
|
|
|
public function createCaptureOrderTransactionHandler(): CaptureOrderTransactionHandlerInterface |
|
90
|
|
|
{ |
|
91
|
|
|
return new CaptureOrderTransactionHandler( |
|
92
|
|
|
$this->createCaptureOrderTransaction(), |
|
93
|
|
|
$this->createDefaultTransactionMetaVisitor() |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\PreCheckTransactionHandlerInterface |
|
99
|
|
|
*/ |
|
100
|
|
|
public function createPreCheckTransactionHandler(): PreCheckTransactionHandlerInterface |
|
101
|
|
|
{ |
|
102
|
|
|
return new PreCheckTransactionHandler( |
|
103
|
|
|
$this->createPreCheckTransaction(), |
|
104
|
|
|
$this->createDefaultTransactionMetaVisitor() |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RefundOrderTransactionHandlerInterface |
|
110
|
|
|
*/ |
|
111
|
|
|
public function createRefundOrderTransactionHandler(): RefundOrderTransactionHandlerInterface |
|
112
|
|
|
{ |
|
113
|
|
|
return new RefundOrderTransactionHandler( |
|
114
|
|
|
$this->createRefundOrderTransaction(), |
|
115
|
|
|
$this->createDefaultTransactionMetaVisitor(), |
|
116
|
|
|
$this->getRefundFacade() |
|
117
|
|
|
); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RefundItemsTransactionHandlerInterface |
|
122
|
|
|
*/ |
|
123
|
|
|
public function createRefundItemsTransactionHandler(): RefundItemsTransactionHandlerInterface |
|
124
|
|
|
{ |
|
125
|
|
|
return new RefundItemsTransactionHandler( |
|
126
|
|
|
$this->createRefundItemsTransaction(), |
|
127
|
|
|
$this->createDefaultTransactionMetaVisitor(), |
|
128
|
|
|
$this->getRefundFacade(), |
|
129
|
|
|
$this->getRepository() |
|
130
|
|
|
); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RevertTransactionHandlerInterface |
|
135
|
|
|
*/ |
|
136
|
|
|
public function createRevertTransactionHandler(): RevertTransactionHandlerInterface |
|
137
|
|
|
{ |
|
138
|
|
|
return new RevertTransactionHandler( |
|
139
|
|
|
$this->createRevertTransaction(), |
|
140
|
|
|
$this->createDefaultTransactionMetaVisitor() |
|
141
|
|
|
); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Order\SaverInterface |
|
146
|
|
|
*/ |
|
147
|
|
|
public function createOrderSaver(): SaverInterface |
|
148
|
|
|
{ |
|
149
|
|
|
return new Saver(); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Log\TransactionStatusLogInterface |
|
154
|
|
|
*/ |
|
155
|
|
|
public function createTransactionStatusLog(): TransactionStatusLogInterface |
|
156
|
|
|
{ |
|
157
|
|
|
return new TransactionStatusLog($this->getRepository()); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Hook\PostSaveHookInterface |
|
162
|
|
|
*/ |
|
163
|
|
|
public function createPostSaveHook(): PostSaveHookInterface |
|
164
|
|
|
{ |
|
165
|
|
|
return new PostSaveHook($this->getRepository()); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
|
170
|
|
|
*/ |
|
171
|
|
|
public function createAuthorizeTransaction(): TransactionInterface |
|
172
|
|
|
{ |
|
173
|
|
|
return new AuthorizeTransaction($this->getConfig()); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\TransactionMetaVisitorInterface |
|
178
|
|
|
*/ |
|
179
|
|
|
public function createDefaultTransactionMetaVisitor(): TransactionMetaVisitorInterface |
|
180
|
|
|
{ |
|
181
|
|
|
$transactionMetaVisitorComposite = $this->createTransactionMetaVisitorComposite(); |
|
182
|
|
|
$transactionMetaVisitorComposite->addVisitor($this->createPaymentTransactionMetaVisitor()); |
|
183
|
|
|
|
|
184
|
|
|
return $transactionMetaVisitorComposite; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\TransactionMetaVisitorInterface |
|
189
|
|
|
*/ |
|
190
|
|
|
public function createTransactionMetaVisitorComposite(): TransactionMetaVisitorInterface |
|
191
|
|
|
{ |
|
192
|
|
|
return new TransactionMetaVisitorComposite(); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\TransactionMetaVisitorInterface |
|
197
|
|
|
*/ |
|
198
|
|
|
public function createPaymentTransactionMetaVisitor(): TransactionMetaVisitorInterface |
|
199
|
|
|
{ |
|
200
|
|
|
return new PaymentTransactionMetaVisitor($this->getRepository()); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
|
205
|
|
|
*/ |
|
206
|
|
|
public function createCaptureOrderTransaction(): TransactionInterface |
|
207
|
|
|
{ |
|
208
|
|
|
return new CaptureOrderTransaction($this->getConfig()); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
|
213
|
|
|
*/ |
|
214
|
|
|
public function createCaptureItemsTransaction(): TransactionInterface |
|
215
|
|
|
{ |
|
216
|
|
|
return new CaptureItemsTransaction( |
|
217
|
|
|
$this->getConfig(), |
|
218
|
|
|
$this->getMoneyFacade(), |
|
219
|
|
|
$this->getRepository(), |
|
220
|
|
|
$this->getEntityManager(), |
|
221
|
|
|
$this->getSalesFacade(), |
|
222
|
|
|
$this->createShipmentTransactionHandler() |
|
223
|
|
|
); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
|
228
|
|
|
*/ |
|
229
|
|
|
public function createShipmentTransaction(): TransactionInterface |
|
230
|
|
|
{ |
|
231
|
|
|
return new ShipmentTransaction( |
|
232
|
|
|
$this->getConfig(), |
|
233
|
|
|
$this->getEntityManager() |
|
234
|
|
|
); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
|
239
|
|
|
*/ |
|
240
|
|
|
public function createShipmentRefundTransaction(): TransactionInterface |
|
241
|
|
|
{ |
|
242
|
|
|
return new ShipmentRefundTransaction( |
|
243
|
|
|
$this->getConfig(), |
|
244
|
|
|
$this->getEntityManager() |
|
245
|
|
|
); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\ShipmentTransactionHandlerInterface |
|
250
|
|
|
*/ |
|
251
|
|
|
public function createShipmentTransactionHandler(): ShipmentTransactionHandlerInterface |
|
252
|
|
|
{ |
|
253
|
|
|
return new ShipmentTransactionHandler( |
|
254
|
|
|
$this->createShipmentTransaction(), |
|
255
|
|
|
$this->createDefaultTransactionMetaVisitor() |
|
256
|
|
|
); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\ShipmentRefundTransactionHandlerInterface |
|
261
|
|
|
*/ |
|
262
|
|
|
public function createShipmentRefundTransactionHandler(): ShipmentRefundTransactionHandlerInterface |
|
263
|
|
|
{ |
|
264
|
|
|
return new ShipmentRefundTransactionHandler( |
|
265
|
|
|
$this->createShipmentRefundTransaction(), |
|
266
|
|
|
$this->createDefaultTransactionMetaVisitor() |
|
267
|
|
|
); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
|
272
|
|
|
*/ |
|
273
|
|
|
public function createPreCheckTransaction(): TransactionInterface |
|
274
|
|
|
{ |
|
275
|
|
|
return new PreCheckTransaction($this->getConfig(), $this->getMoneyFacade()); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* @return \SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToMoneyFacadeInterface |
|
280
|
|
|
*/ |
|
281
|
|
|
public function getMoneyFacade(): BraintreeToMoneyFacadeInterface |
|
282
|
|
|
{ |
|
283
|
|
|
return $this->getProvidedDependency(BraintreeDependencyProvider::FACADE_MONEY); |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
|
288
|
|
|
*/ |
|
289
|
|
|
public function createRefundOrderTransaction(): TransactionInterface |
|
290
|
|
|
{ |
|
291
|
|
|
return new RefundOrderTransaction( |
|
292
|
|
|
$this->getConfig(), |
|
293
|
|
|
$this->getMoneyFacade(), |
|
294
|
|
|
$this->createShipmentRefundTransactionHandler(), |
|
295
|
|
|
$this->getRepository() |
|
296
|
|
|
); |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
|
301
|
|
|
*/ |
|
302
|
|
|
public function createRefundItemsTransaction(): TransactionInterface |
|
303
|
|
|
{ |
|
304
|
|
|
return new RefundItemsTransaction( |
|
305
|
|
|
$this->getConfig(), |
|
306
|
|
|
$this->getMoneyFacade(), |
|
307
|
|
|
$this->createShipmentRefundTransactionHandler(), |
|
308
|
|
|
$this->getRepository() |
|
309
|
|
|
); |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
|
314
|
|
|
*/ |
|
315
|
|
|
public function createRevertTransaction(): TransactionInterface |
|
316
|
|
|
{ |
|
317
|
|
|
return new RevertTransaction($this->getConfig()); |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* @return \SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToRefundFacadeInterface |
|
322
|
|
|
*/ |
|
323
|
|
|
public function getRefundFacade(): BraintreeToRefundFacadeInterface |
|
324
|
|
|
{ |
|
325
|
|
|
return $this->getProvidedDependency(BraintreeDependencyProvider::FACADE_REFUND); |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Filter\PaypalExpressPaymentMethodFilterInterface |
|
330
|
|
|
*/ |
|
331
|
|
|
public function createPaypalExpressCheckoutPaymentMethod(): PaypalExpressPaymentMethodFilterInterface |
|
332
|
|
|
{ |
|
333
|
|
|
return new PaypalExpressPaymentMethodFilter(); |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* @return \SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToSalesFacadeInterface |
|
338
|
|
|
*/ |
|
339
|
|
|
public function getSalesFacade(): BraintreeToSalesFacadeInterface |
|
340
|
|
|
{ |
|
341
|
|
|
return $this->getProvidedDependency(BraintreeDependencyProvider::FACADE_SALES); |
|
342
|
|
|
} |
|
343
|
|
|
} |
|
344
|
|
|
|