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