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\RefundTransactionHandler; |
32
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RefundTransactionHandlerInterface; |
33
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RevertTransactionHandler; |
34
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RevertTransactionHandlerInterface; |
35
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\PaymentTransactionMetaVisitor; |
36
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\TransactionMetaVisitorComposite; |
37
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\TransactionMetaVisitorInterface; |
38
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\PreCheckTransaction; |
39
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\RefundTransaction; |
40
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\RevertTransaction; |
41
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface; |
42
|
|
|
use SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToMoneyFacadeInterface; |
43
|
|
|
use SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToRefundFacadeInterface; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @method \SprykerEco\Zed\Braintree\Persistence\BraintreeQueryContainerInterface getQueryContainer() |
47
|
|
|
* @method \SprykerEco\Zed\Braintree\BraintreeConfig getConfig() |
48
|
|
|
* @method \SprykerEco\Zed\Braintree\Persistence\BraintreeRepositoryInterface getRepository() |
49
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
50
|
|
|
*/ |
51
|
|
|
class BraintreeBusinessFactory extends AbstractBusinessFactory |
52
|
|
|
{ |
53
|
|
|
/** |
54
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\AuthorizeTransactionHandlerInterface |
55
|
|
|
*/ |
56
|
|
|
public function createAuthorizeTransactionHandler(): AuthorizeTransactionHandlerInterface |
57
|
|
|
{ |
58
|
|
|
return new AuthorizeTransactionHandler( |
59
|
|
|
$this->createAuthorizeTransaction(), |
60
|
|
|
$this->createDefaultTransactionMetaVisitor() |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\CaptureItemsTransactionHandlerInterface |
66
|
|
|
*/ |
67
|
|
|
public function createCaptureItemsTransactionHandler(): CaptureItemsTransactionHandlerInterface |
68
|
|
|
{ |
69
|
|
|
return new CaptureItemsTransactionHandler( |
70
|
|
|
$this->createCaptureItemsTransaction(), |
71
|
|
|
$this->createDefaultTransactionMetaVisitor() |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\CaptureOrderTransactionHandlerInterface |
77
|
|
|
*/ |
78
|
|
|
public function createCaptureOrderTransactionHandler(): CaptureOrderTransactionHandlerInterface |
79
|
|
|
{ |
80
|
|
|
return new CaptureOrderTransactionHandler( |
81
|
|
|
$this->createCaptureOrderTransaction(), |
82
|
|
|
$this->createDefaultTransactionMetaVisitor() |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\PreCheckTransactionHandlerInterface |
88
|
|
|
*/ |
89
|
|
|
public function createPreCheckTransactionHandler(): PreCheckTransactionHandlerInterface |
90
|
|
|
{ |
91
|
|
|
return new PreCheckTransactionHandler( |
92
|
|
|
$this->createPreCheckTransaction(), |
93
|
|
|
$this->createDefaultTransactionMetaVisitor() |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RefundTransactionHandlerInterface |
99
|
|
|
*/ |
100
|
|
|
public function createRefundTransactionHandler(): RefundTransactionHandlerInterface |
101
|
|
|
{ |
102
|
|
|
return new RefundTransactionHandler( |
103
|
|
|
$this->createRefundTransaction(), |
104
|
|
|
$this->createDefaultTransactionMetaVisitor(), |
105
|
|
|
$this->getRefundFacade() |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\Handler\RevertTransactionHandlerInterface |
111
|
|
|
*/ |
112
|
|
|
public function createRevertTransactionHandler(): RevertTransactionHandlerInterface |
113
|
|
|
{ |
114
|
|
|
return new RevertTransactionHandler( |
115
|
|
|
$this->createRevertTransaction(), |
116
|
|
|
$this->createDefaultTransactionMetaVisitor() |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Order\SaverInterface |
122
|
|
|
*/ |
123
|
|
|
public function createOrderSaver(): SaverInterface |
124
|
|
|
{ |
125
|
|
|
return new Saver(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Log\TransactionStatusLogInterface |
130
|
|
|
*/ |
131
|
|
|
public function createTransactionStatusLog(): TransactionStatusLogInterface |
132
|
|
|
{ |
133
|
|
|
return new TransactionStatusLog($this->getRepository()); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Hook\PostSaveHookInterface |
138
|
|
|
*/ |
139
|
|
|
public function createPostSaveHook(): PostSaveHookInterface |
140
|
|
|
{ |
141
|
|
|
return new PostSaveHook($this->getRepository()); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
146
|
|
|
*/ |
147
|
|
|
public function createAuthorizeTransaction(): TransactionInterface |
148
|
|
|
{ |
149
|
|
|
return new AuthorizeTransaction($this->getConfig()); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\TransactionMetaVisitorInterface |
154
|
|
|
*/ |
155
|
|
|
public function createDefaultTransactionMetaVisitor(): TransactionMetaVisitorInterface |
156
|
|
|
{ |
157
|
|
|
$transactionMetaVisitorComposite = $this->createTransactionMetaVisitorComposite(); |
158
|
|
|
$transactionMetaVisitorComposite->addVisitor($this->createPaymentTransactionMetaVisitor()); |
159
|
|
|
|
160
|
|
|
return $transactionMetaVisitorComposite; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\TransactionMetaVisitorInterface |
165
|
|
|
*/ |
166
|
|
|
public function createTransactionMetaVisitorComposite(): TransactionMetaVisitorInterface |
167
|
|
|
{ |
168
|
|
|
return new TransactionMetaVisitorComposite(); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\TransactionMetaVisitorInterface |
173
|
|
|
*/ |
174
|
|
|
public function createPaymentTransactionMetaVisitor(): TransactionMetaVisitorInterface |
175
|
|
|
{ |
176
|
|
|
return new PaymentTransactionMetaVisitor($this->getRepository()); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
181
|
|
|
*/ |
182
|
|
|
public function createCaptureOrderTransaction(): TransactionInterface |
183
|
|
|
{ |
184
|
|
|
return new CaptureOrderTransaction($this->getConfig()); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
189
|
|
|
*/ |
190
|
|
|
public function createCaptureItemsTransaction(): TransactionInterface |
191
|
|
|
{ |
192
|
|
|
return new CaptureItemsTransaction($this->getConfig()); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
197
|
|
|
*/ |
198
|
|
|
public function createPreCheckTransaction(): TransactionInterface |
199
|
|
|
{ |
200
|
|
|
return new PreCheckTransaction($this->getConfig(), $this->getMoneyFacade()); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @return \SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToMoneyFacadeInterface |
205
|
|
|
*/ |
206
|
|
|
public function getMoneyFacade(): BraintreeToMoneyFacadeInterface |
207
|
|
|
{ |
208
|
|
|
return $this->getProvidedDependency(BraintreeDependencyProvider::FACADE_MONEY); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
213
|
|
|
*/ |
214
|
|
|
public function createRefundTransaction(): TransactionInterface |
215
|
|
|
{ |
216
|
|
|
return new RefundTransaction($this->getConfig(), $this->getMoneyFacade()); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface |
221
|
|
|
*/ |
222
|
|
|
public function createRevertTransaction(): TransactionInterface |
223
|
|
|
{ |
224
|
|
|
return new RevertTransaction($this->getConfig()); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return \SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToRefundFacadeInterface |
229
|
|
|
*/ |
230
|
|
|
public function getRefundFacade(): BraintreeToRefundFacadeInterface |
231
|
|
|
{ |
232
|
|
|
return $this->getProvidedDependency(BraintreeDependencyProvider::FACADE_REFUND); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @return \SprykerEco\Zed\Braintree\Business\Payment\Filter\PaypalExpressPaymentMethodFilterInterface |
237
|
|
|
*/ |
238
|
|
|
public function createPaypalExpressCheckoutPaymentMethod(): PaypalExpressPaymentMethodFilterInterface |
239
|
|
|
{ |
240
|
|
|
return new PaypalExpressPaymentMethodFilter(); |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|