1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Commercetools\Core\Builder\Update; |
4
|
|
|
|
5
|
|
|
use Commercetools\Core\Error\InvalidArgumentException; |
6
|
|
|
use Commercetools\Core\Request\AbstractAction; |
7
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentAddInterfaceInteractionAction; |
8
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentAddTransactionAction; |
9
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentChangeAmountPlannedAction; |
10
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentChangeTransactionInteractionIdAction; |
11
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentChangeTransactionStateAction; |
12
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentChangeTransactionTimestampAction; |
13
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetAmountPaidAction; |
14
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetAmountRefundedAction; |
15
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetAuthorizationAction; |
16
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomFieldAction; |
17
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomTypeAction; |
18
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomerAction; |
19
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetExternalIdAction; |
20
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetInterfaceIdAction; |
21
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetKeyAction; |
22
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoInterfaceAction; |
23
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoMethodAction; |
24
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoNameAction; |
25
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetStatusInterfaceCodeAction; |
26
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentSetStatusInterfaceTextAction; |
27
|
|
|
use Commercetools\Core\Request\Payments\Command\PaymentTransitionStateAction; |
28
|
|
|
|
29
|
|
|
class PaymentsActionBuilder |
30
|
|
|
{ |
31
|
|
|
private $actions = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#add-interfaceinteraction |
35
|
|
|
* @param PaymentAddInterfaceInteractionAction|callable $action |
36
|
|
|
* @return $this |
37
|
|
|
*/ |
38
|
1 |
|
public function addInterfaceInteraction($action = null) |
39
|
|
|
{ |
40
|
1 |
|
$this->addAction($this->resolveAction(PaymentAddInterfaceInteractionAction::class, $action)); |
41
|
1 |
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#add-transaction |
46
|
|
|
* @param PaymentAddTransactionAction|callable $action |
47
|
|
|
* @return $this |
48
|
|
|
*/ |
49
|
1 |
|
public function addTransaction($action = null) |
50
|
|
|
{ |
51
|
1 |
|
$this->addAction($this->resolveAction(PaymentAddTransactionAction::class, $action)); |
52
|
1 |
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#change-amountplanned |
57
|
|
|
* @param PaymentChangeAmountPlannedAction|callable $action |
58
|
|
|
* @return $this |
59
|
|
|
*/ |
60
|
1 |
|
public function changeAmountPlanned($action = null) |
61
|
|
|
{ |
62
|
1 |
|
$this->addAction($this->resolveAction(PaymentChangeAmountPlannedAction::class, $action)); |
63
|
1 |
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#change-transactioninteractionid |
68
|
|
|
* @param PaymentChangeTransactionInteractionIdAction|callable $action |
69
|
|
|
* @return $this |
70
|
|
|
*/ |
71
|
1 |
|
public function changeTransactionInteractionId($action = null) |
72
|
|
|
{ |
73
|
1 |
|
$this->addAction($this->resolveAction(PaymentChangeTransactionInteractionIdAction::class, $action)); |
74
|
1 |
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#change-transactionstate |
79
|
|
|
* @param PaymentChangeTransactionStateAction|callable $action |
80
|
|
|
* @return $this |
81
|
|
|
*/ |
82
|
1 |
|
public function changeTransactionState($action = null) |
83
|
|
|
{ |
84
|
1 |
|
$this->addAction($this->resolveAction(PaymentChangeTransactionStateAction::class, $action)); |
85
|
1 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#change-transactiontimestamp |
90
|
|
|
* @param PaymentChangeTransactionTimestampAction|callable $action |
91
|
|
|
* @return $this |
92
|
|
|
*/ |
93
|
1 |
|
public function changeTransactionTimestamp($action = null) |
94
|
|
|
{ |
95
|
1 |
|
$this->addAction($this->resolveAction(PaymentChangeTransactionTimestampAction::class, $action)); |
96
|
1 |
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-amountpaid |
101
|
|
|
* @param PaymentSetAmountPaidAction|callable $action |
102
|
|
|
* @return $this |
103
|
|
|
*/ |
104
|
1 |
|
public function setAmountPaid($action = null) |
105
|
|
|
{ |
106
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetAmountPaidAction::class, $action)); |
107
|
1 |
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-amountrefunded |
112
|
|
|
* @param PaymentSetAmountRefundedAction|callable $action |
113
|
|
|
* @return $this |
114
|
|
|
*/ |
115
|
1 |
|
public function setAmountRefunded($action = null) |
116
|
|
|
{ |
117
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetAmountRefundedAction::class, $action)); |
118
|
1 |
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-authorization |
123
|
|
|
* @param PaymentSetAuthorizationAction|callable $action |
124
|
|
|
* @return $this |
125
|
|
|
*/ |
126
|
1 |
|
public function setAuthorization($action = null) |
127
|
|
|
{ |
128
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetAuthorizationAction::class, $action)); |
129
|
1 |
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-customfield |
134
|
|
|
* @param PaymentSetCustomFieldAction|callable $action |
135
|
|
|
* @return $this |
136
|
|
|
*/ |
137
|
1 |
|
public function setCustomField($action = null) |
138
|
|
|
{ |
139
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetCustomFieldAction::class, $action)); |
140
|
1 |
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-custom-type |
145
|
|
|
* @param PaymentSetCustomTypeAction|callable $action |
146
|
|
|
* @return $this |
147
|
|
|
*/ |
148
|
1 |
|
public function setCustomType($action = null) |
149
|
|
|
{ |
150
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetCustomTypeAction::class, $action)); |
151
|
1 |
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-customer |
156
|
|
|
* @param PaymentSetCustomerAction|callable $action |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
1 |
|
public function setCustomer($action = null) |
160
|
|
|
{ |
161
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetCustomerAction::class, $action)); |
162
|
1 |
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-externalid |
167
|
|
|
* @param PaymentSetExternalIdAction|callable $action |
168
|
|
|
* @return $this |
169
|
|
|
*/ |
170
|
1 |
|
public function setExternalId($action = null) |
171
|
|
|
{ |
172
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetExternalIdAction::class, $action)); |
173
|
1 |
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-interfaceid |
178
|
|
|
* @param PaymentSetInterfaceIdAction|callable $action |
179
|
|
|
* @return $this |
180
|
|
|
*/ |
181
|
1 |
|
public function setInterfaceId($action = null) |
182
|
|
|
{ |
183
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetInterfaceIdAction::class, $action)); |
184
|
1 |
|
return $this; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-key |
189
|
|
|
* @param PaymentSetKeyAction|callable $action |
190
|
|
|
* @return $this |
191
|
|
|
*/ |
192
|
1 |
|
public function setKey($action = null) |
193
|
|
|
{ |
194
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetKeyAction::class, $action)); |
195
|
1 |
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-methodinfointerface |
200
|
|
|
* @param PaymentSetMethodInfoInterfaceAction|callable $action |
201
|
|
|
* @return $this |
202
|
|
|
*/ |
203
|
1 |
|
public function setMethodInfoInterface($action = null) |
204
|
|
|
{ |
205
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetMethodInfoInterfaceAction::class, $action)); |
206
|
1 |
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-methodinfomethod |
211
|
|
|
* @param PaymentSetMethodInfoMethodAction|callable $action |
212
|
|
|
* @return $this |
213
|
|
|
*/ |
214
|
1 |
|
public function setMethodInfoMethod($action = null) |
215
|
|
|
{ |
216
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetMethodInfoMethodAction::class, $action)); |
217
|
1 |
|
return $this; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-methodinfoname |
222
|
|
|
* @param PaymentSetMethodInfoNameAction|callable $action |
223
|
|
|
* @return $this |
224
|
|
|
*/ |
225
|
1 |
|
public function setMethodInfoName($action = null) |
226
|
|
|
{ |
227
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetMethodInfoNameAction::class, $action)); |
228
|
1 |
|
return $this; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-statusinterfacecode |
233
|
|
|
* @param PaymentSetStatusInterfaceCodeAction|callable $action |
234
|
|
|
* @return $this |
235
|
|
|
*/ |
236
|
1 |
|
public function setStatusInterfaceCode($action = null) |
237
|
|
|
{ |
238
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetStatusInterfaceCodeAction::class, $action)); |
239
|
1 |
|
return $this; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-statusinterfacetext |
244
|
|
|
* @param PaymentSetStatusInterfaceTextAction|callable $action |
245
|
|
|
* @return $this |
246
|
|
|
*/ |
247
|
1 |
|
public function setStatusInterfaceText($action = null) |
248
|
|
|
{ |
249
|
1 |
|
$this->addAction($this->resolveAction(PaymentSetStatusInterfaceTextAction::class, $action)); |
250
|
1 |
|
return $this; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @link https://docs.commercetools.com/http-api-projects-payments.html#transition-state |
255
|
|
|
* @param PaymentTransitionStateAction|callable $action |
256
|
|
|
* @return $this |
257
|
|
|
*/ |
258
|
1 |
|
public function transitionState($action = null) |
259
|
|
|
{ |
260
|
1 |
|
$this->addAction($this->resolveAction(PaymentTransitionStateAction::class, $action)); |
261
|
1 |
|
return $this; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @return PaymentsActionBuilder |
266
|
|
|
*/ |
267
|
|
|
public function of() |
268
|
|
|
{ |
269
|
|
|
return new self(); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @param $class |
274
|
|
|
* @param $action |
275
|
|
|
* @return AbstractAction |
276
|
|
|
* @throws InvalidArgumentException |
277
|
|
|
*/ |
278
|
21 |
|
private function resolveAction($class, $action = null) |
279
|
|
|
{ |
280
|
21 |
|
if (is_null($action) || is_callable($action)) { |
281
|
21 |
|
$callback = $action; |
282
|
21 |
|
$emptyAction = $class::of(); |
283
|
21 |
|
$action = $this->callback($emptyAction, $callback); |
284
|
|
|
} |
285
|
21 |
|
if ($action instanceof $class) { |
286
|
21 |
|
return $action; |
287
|
|
|
} |
288
|
|
|
throw new InvalidArgumentException( |
289
|
|
|
sprintf('Expected method to be called with or callable to return %s', $class) |
290
|
|
|
); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* @param $action |
295
|
|
|
* @param callable $callback |
296
|
|
|
* @return AbstractAction |
297
|
|
|
*/ |
298
|
21 |
|
private function callback($action, callable $callback = null) |
299
|
|
|
{ |
300
|
21 |
|
if (!is_null($callback)) { |
301
|
|
|
$action = $callback($action); |
302
|
|
|
} |
303
|
21 |
|
return $action; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @param AbstractAction $action |
308
|
|
|
* @return $this; |
309
|
|
|
*/ |
310
|
21 |
|
public function addAction(AbstractAction $action) |
311
|
|
|
{ |
312
|
21 |
|
$this->actions[] = $action; |
313
|
21 |
|
return $this; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* @return array |
318
|
|
|
*/ |
319
|
21 |
|
public function getActions() |
320
|
|
|
{ |
321
|
21 |
|
return $this->actions; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* @param array $actions |
326
|
|
|
* @return $this |
327
|
|
|
*/ |
328
|
|
|
public function setActions(array $actions) |
329
|
|
|
{ |
330
|
|
|
$this->actions = $actions; |
331
|
|
|
return $this; |
332
|
|
|
} |
333
|
|
|
} |
334
|
|
|
|