Passed
Pull Request — develop (#423)
by nikos
09:13
created

CartsActionBuilder::setCartTotalTax()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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\Carts\Command\CartAddCustomLineItemAction;
8
use Commercetools\Core\Request\Carts\Command\CartAddDiscountCodeAction;
9
use Commercetools\Core\Request\Carts\Command\CartAddItemShippingAddressAction;
10
use Commercetools\Core\Request\Carts\Command\CartAddLineItemAction;
11
use Commercetools\Core\Request\Carts\Command\CartAddPaymentAction;
12
use Commercetools\Core\Request\Carts\Command\CartAddShoppingListAction;
13
use Commercetools\Core\Request\Carts\Command\CartApplyDeltaToCustomLineItemShippingDetailsTargetsAction;
14
use Commercetools\Core\Request\Carts\Command\CartApplyDeltaToLineItemShippingDetailsTargetsAction;
15
use Commercetools\Core\Request\Carts\Command\CartChangeCustomLineItemMoneyAction;
16
use Commercetools\Core\Request\Carts\Command\CartChangeCustomLineItemQuantityAction;
17
use Commercetools\Core\Request\Carts\Command\CartChangeLineItemQuantityAction;
18
use Commercetools\Core\Request\Carts\Command\CartChangeTaxCalculationModeAction;
19
use Commercetools\Core\Request\Carts\Command\CartChangeTaxModeAction;
20
use Commercetools\Core\Request\Carts\Command\CartChangeTaxRoundingModeAction;
21
use Commercetools\Core\Request\Carts\Command\CartRecalculateAction;
22
use Commercetools\Core\Request\Carts\Command\CartRemoveCustomLineItemAction;
23
use Commercetools\Core\Request\Carts\Command\CartRemoveDiscountCodeAction;
24
use Commercetools\Core\Request\Carts\Command\CartRemoveItemShippingAddressAction;
25
use Commercetools\Core\Request\Carts\Command\CartRemoveLineItemAction;
26
use Commercetools\Core\Request\Carts\Command\CartRemovePaymentAction;
27
use Commercetools\Core\Request\Carts\Command\CartSetAnonymousIdAction;
28
use Commercetools\Core\Request\Carts\Command\CartSetBillingAddressAction;
29
use Commercetools\Core\Request\Carts\Command\CartSetCartTotalTaxAction;
30
use Commercetools\Core\Request\Carts\Command\CartSetCountryAction;
31
use Commercetools\Core\Request\Carts\Command\CartSetCustomFieldAction;
32
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemCustomFieldAction;
33
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemCustomTypeAction;
34
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemShippingDetailsAction;
35
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemTaxAmountAction;
36
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemTaxRateAction;
37
use Commercetools\Core\Request\Carts\Command\CartSetCustomShippingMethodAction;
38
use Commercetools\Core\Request\Carts\Command\CartSetCustomTypeAction;
39
use Commercetools\Core\Request\Carts\Command\CartSetCustomerEmailAction;
40
use Commercetools\Core\Request\Carts\Command\CartSetCustomerGroupAction;
41
use Commercetools\Core\Request\Carts\Command\CartSetCustomerIdAction;
42
use Commercetools\Core\Request\Carts\Command\CartSetDeleteDaysAfterLastModificationAction;
43
use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomFieldAction;
44
use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomTypeAction;
45
use Commercetools\Core\Request\Carts\Command\CartSetLineItemPriceAction;
46
use Commercetools\Core\Request\Carts\Command\CartSetLineItemShippingDetailsAction;
47
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxAmountAction;
48
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxRateAction;
49
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTotalPriceAction;
50
use Commercetools\Core\Request\Carts\Command\CartSetLocaleAction;
51
use Commercetools\Core\Request\Carts\Command\CartSetShippingAddressAction;
52
use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodAction;
53
use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodTaxAmountAction;
54
use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodTaxRateAction;
55
use Commercetools\Core\Request\Carts\Command\CartSetShippingRateInputAction;
56
use Commercetools\Core\Request\Carts\Command\CartUpdateItemShippingAddressAction;
57
58
class CartsActionBuilder
59
{
60
    private $actions = [];
61
62
    /**
63
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-customlineitem
64
     * @param CartAddCustomLineItemAction|callable $action
65
     * @return $this
66
     */
67 1
    public function addCustomLineItem($action = null)
68
    {
69 1
        $this->addAction($this->resolveAction(CartAddCustomLineItemAction::class, $action));
70 1
        return $this;
71
    }
72
73
    /**
74
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-discountcode
75
     * @param CartAddDiscountCodeAction|callable $action
76
     * @return $this
77
     */
78 1
    public function addDiscountCode($action = null)
79
    {
80 1
        $this->addAction($this->resolveAction(CartAddDiscountCodeAction::class, $action));
81 1
        return $this;
82
    }
83
84
    /**
85
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-itemshippingaddress
86
     * @param CartAddItemShippingAddressAction|callable $action
87
     * @return $this
88
     */
89 1
    public function addItemShippingAddress($action = null)
90
    {
91 1
        $this->addAction($this->resolveAction(CartAddItemShippingAddressAction::class, $action));
92 1
        return $this;
93
    }
94
95
    /**
96
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-lineitem
97
     * @param CartAddLineItemAction|callable $action
98
     * @return $this
99
     */
100 1
    public function addLineItem($action = null)
101
    {
102 1
        $this->addAction($this->resolveAction(CartAddLineItemAction::class, $action));
103 1
        return $this;
104
    }
105
106
    /**
107
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-payment
108
     * @param CartAddPaymentAction|callable $action
109
     * @return $this
110
     */
111 1
    public function addPayment($action = null)
112
    {
113 1
        $this->addAction($this->resolveAction(CartAddPaymentAction::class, $action));
114 1
        return $this;
115
    }
116
117
    /**
118
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-shoppinglist
119
     * @param CartAddShoppingListAction|callable $action
120
     * @return $this
121
     */
122 1
    public function addShoppingList($action = null)
123
    {
124 1
        $this->addAction($this->resolveAction(CartAddShoppingListAction::class, $action));
125 1
        return $this;
126
    }
127
128
    /**
129
     * @link https://docs.commercetools.com/http-api-projects-carts.html#apply-deltatocustomlineitemshippingdetailstargets
130
     * @param CartApplyDeltaToCustomLineItemShippingDetailsTargetsAction|callable $action
131
     * @return $this
132
     */
133 1
    public function applyDeltaToCustomLineItemShippingDetailsTargets($action = null)
134
    {
135
        // @codingStandardsIgnoreLine
136 1
        $this->addAction($this->resolveAction(CartApplyDeltaToCustomLineItemShippingDetailsTargetsAction::class, $action));
137 1
        return $this;
138
    }
139
140
    /**
141
     * @link https://docs.commercetools.com/http-api-projects-carts.html#apply-deltatolineitemshippingdetailstargets
142
     * @param CartApplyDeltaToLineItemShippingDetailsTargetsAction|callable $action
143
     * @return $this
144
     */
145 1
    public function applyDeltaToLineItemShippingDetailsTargets($action = null)
146
    {
147 1
        $this->addAction($this->resolveAction(CartApplyDeltaToLineItemShippingDetailsTargetsAction::class, $action));
148 1
        return $this;
149
    }
150
151
    /**
152
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-customlineitem-money
153
     * @param CartChangeCustomLineItemMoneyAction|callable $action
154
     * @return $this
155
     */
156 1
    public function changeCustomLineItemMoney($action = null)
157
    {
158 1
        $this->addAction($this->resolveAction(CartChangeCustomLineItemMoneyAction::class, $action));
159 1
        return $this;
160
    }
161
162
    /**
163
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-customlineitem-quantity
164
     * @param CartChangeCustomLineItemQuantityAction|callable $action
165
     * @return $this
166
     */
167 1
    public function changeCustomLineItemQuantity($action = null)
168
    {
169 1
        $this->addAction($this->resolveAction(CartChangeCustomLineItemQuantityAction::class, $action));
170 1
        return $this;
171
    }
172
173
    /**
174
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-lineitem-quantity
175
     * @param CartChangeLineItemQuantityAction|callable $action
176
     * @return $this
177
     */
178 1
    public function changeLineItemQuantity($action = null)
179
    {
180 1
        $this->addAction($this->resolveAction(CartChangeLineItemQuantityAction::class, $action));
181 1
        return $this;
182
    }
183
184
    /**
185
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-tax-calculationmode
186
     * @param CartChangeTaxCalculationModeAction|callable $action
187
     * @return $this
188
     */
189 1
    public function changeTaxCalculationMode($action = null)
190
    {
191 1
        $this->addAction($this->resolveAction(CartChangeTaxCalculationModeAction::class, $action));
192 1
        return $this;
193
    }
194
195
    /**
196
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-taxmode
197
     * @param CartChangeTaxModeAction|callable $action
198
     * @return $this
199
     */
200 1
    public function changeTaxMode($action = null)
201
    {
202 1
        $this->addAction($this->resolveAction(CartChangeTaxModeAction::class, $action));
203 1
        return $this;
204
    }
205
206
    /**
207
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-tax-roundingmode
208
     * @param CartChangeTaxRoundingModeAction|callable $action
209
     * @return $this
210
     */
211 1
    public function changeTaxRoundingMode($action = null)
212
    {
213 1
        $this->addAction($this->resolveAction(CartChangeTaxRoundingModeAction::class, $action));
214 1
        return $this;
215
    }
216
217
    /**
218
     * @link https://docs.commercetools.com/http-api-projects-carts.html#recalculate
219
     * @param CartRecalculateAction|callable $action
220
     * @return $this
221
     */
222 1
    public function recalculate($action = null)
223
    {
224 1
        $this->addAction($this->resolveAction(CartRecalculateAction::class, $action));
225 1
        return $this;
226
    }
227
228
    /**
229
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-customlineitem
230
     * @param CartRemoveCustomLineItemAction|callable $action
231
     * @return $this
232
     */
233 1
    public function removeCustomLineItem($action = null)
234
    {
235 1
        $this->addAction($this->resolveAction(CartRemoveCustomLineItemAction::class, $action));
236 1
        return $this;
237
    }
238
239
    /**
240
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-discountcode
241
     * @param CartRemoveDiscountCodeAction|callable $action
242
     * @return $this
243
     */
244 1
    public function removeDiscountCode($action = null)
245
    {
246 1
        $this->addAction($this->resolveAction(CartRemoveDiscountCodeAction::class, $action));
247 1
        return $this;
248
    }
249
250
    /**
251
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-itemshippingaddress
252
     * @param CartRemoveItemShippingAddressAction|callable $action
253
     * @return $this
254
     */
255 1
    public function removeItemShippingAddress($action = null)
256
    {
257 1
        $this->addAction($this->resolveAction(CartRemoveItemShippingAddressAction::class, $action));
258 1
        return $this;
259
    }
260
261
    /**
262
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-lineitem
263
     * @param CartRemoveLineItemAction|callable $action
264
     * @return $this
265
     */
266 1
    public function removeLineItem($action = null)
267
    {
268 1
        $this->addAction($this->resolveAction(CartRemoveLineItemAction::class, $action));
269 1
        return $this;
270
    }
271
272
    /**
273
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-payment
274
     * @param CartRemovePaymentAction|callable $action
275
     * @return $this
276
     */
277 1
    public function removePayment($action = null)
278
    {
279 1
        $this->addAction($this->resolveAction(CartRemovePaymentAction::class, $action));
280 1
        return $this;
281
    }
282
283
    /**
284
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-anonymous-id
285
     * @param CartSetAnonymousIdAction|callable $action
286
     * @return $this
287
     */
288 1
    public function setAnonymousId($action = null)
289
    {
290 1
        $this->addAction($this->resolveAction(CartSetAnonymousIdAction::class, $action));
291 1
        return $this;
292
    }
293
294
    /**
295
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-billing-address
296
     * @param CartSetBillingAddressAction|callable $action
297
     * @return $this
298
     */
299 1
    public function setBillingAddress($action = null)
300
    {
301 1
        $this->addAction($this->resolveAction(CartSetBillingAddressAction::class, $action));
302 1
        return $this;
303
    }
304
305
    /**
306
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-cart-total-tax
307
     * @param CartSetCartTotalTaxAction|callable $action
308
     * @return $this
309
     */
310 1
    public function setCartTotalTax($action = null)
311
    {
312 1
        $this->addAction($this->resolveAction(CartSetCartTotalTaxAction::class, $action));
313 1
        return $this;
314
    }
315
316
    /**
317
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-country
318
     * @param CartSetCountryAction|callable $action
319
     * @return $this
320
     */
321 1
    public function setCountry($action = null)
322
    {
323 1
        $this->addAction($this->resolveAction(CartSetCountryAction::class, $action));
324 1
        return $this;
325
    }
326
327
    /**
328
     *
329
     * @param CartSetCustomFieldAction|callable $action
330
     * @return $this
331
     */
332 1
    public function setCustomField($action = null)
333
    {
334 1
        $this->addAction($this->resolveAction(CartSetCustomFieldAction::class, $action));
335 1
        return $this;
336
    }
337
338
    /**
339
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-customfield
340
     * @param CartSetCustomLineItemCustomFieldAction|callable $action
341
     * @return $this
342
     */
343 1
    public function setCustomLineItemCustomField($action = null)
344
    {
345 1
        $this->addAction($this->resolveAction(CartSetCustomLineItemCustomFieldAction::class, $action));
346 1
        return $this;
347
    }
348
349
    /**
350
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-custom-type
351
     * @param CartSetCustomLineItemCustomTypeAction|callable $action
352
     * @return $this
353
     */
354 1
    public function setCustomLineItemCustomType($action = null)
355
    {
356 1
        $this->addAction($this->resolveAction(CartSetCustomLineItemCustomTypeAction::class, $action));
357 1
        return $this;
358
    }
359
360
    /**
361
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitemshippingdetails
362
     * @param CartSetCustomLineItemShippingDetailsAction|callable $action
363
     * @return $this
364
     */
365 1
    public function setCustomLineItemShippingDetails($action = null)
366
    {
367 1
        $this->addAction($this->resolveAction(CartSetCustomLineItemShippingDetailsAction::class, $action));
368 1
        return $this;
369
    }
370
371
    /**
372
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-taxamount
373
     * @param CartSetCustomLineItemTaxAmountAction|callable $action
374
     * @return $this
375
     */
376 1
    public function setCustomLineItemTaxAmount($action = null)
377
    {
378 1
        $this->addAction($this->resolveAction(CartSetCustomLineItemTaxAmountAction::class, $action));
379 1
        return $this;
380
    }
381
382
    /**
383
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-taxrate
384
     * @param CartSetCustomLineItemTaxRateAction|callable $action
385
     * @return $this
386
     */
387 1
    public function setCustomLineItemTaxRate($action = null)
388
    {
389 1
        $this->addAction($this->resolveAction(CartSetCustomLineItemTaxRateAction::class, $action));
390 1
        return $this;
391
    }
392
393
    /**
394
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-custom-shippingmethod
395
     * @param CartSetCustomShippingMethodAction|callable $action
396
     * @return $this
397
     */
398 1
    public function setCustomShippingMethod($action = null)
399
    {
400 1
        $this->addAction($this->resolveAction(CartSetCustomShippingMethodAction::class, $action));
401 1
        return $this;
402
    }
403
404
    /**
405
     *
406
     * @param CartSetCustomTypeAction|callable $action
407
     * @return $this
408
     */
409 1
    public function setCustomType($action = null)
410
    {
411 1
        $this->addAction($this->resolveAction(CartSetCustomTypeAction::class, $action));
412 1
        return $this;
413
    }
414
415
    /**
416
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customer-email
417
     * @param CartSetCustomerEmailAction|callable $action
418
     * @return $this
419
     */
420 1
    public function setCustomerEmail($action = null)
421
    {
422 1
        $this->addAction($this->resolveAction(CartSetCustomerEmailAction::class, $action));
423 1
        return $this;
424
    }
425
426
    /**
427
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customer-group
428
     * @param CartSetCustomerGroupAction|callable $action
429
     * @return $this
430
     */
431 1
    public function setCustomerGroup($action = null)
432
    {
433 1
        $this->addAction($this->resolveAction(CartSetCustomerGroupAction::class, $action));
434 1
        return $this;
435
    }
436
437
    /**
438
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customer-id
439
     * @param CartSetCustomerIdAction|callable $action
440
     * @return $this
441
     */
442 1
    public function setCustomerId($action = null)
443
    {
444 1
        $this->addAction($this->resolveAction(CartSetCustomerIdAction::class, $action));
445 1
        return $this;
446
    }
447
448
    /**
449
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-deletedaysafterlastmodification-beta
450
     * @param CartSetDeleteDaysAfterLastModificationAction|callable $action
451
     * @return $this
452
     */
453 1
    public function setDeleteDaysAfterLastModification($action = null)
454
    {
455 1
        $this->addAction($this->resolveAction(CartSetDeleteDaysAfterLastModificationAction::class, $action));
456 1
        return $this;
457
    }
458
459
    /**
460
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-customfield
461
     * @param CartSetLineItemCustomFieldAction|callable $action
462
     * @return $this
463
     */
464 1
    public function setLineItemCustomField($action = null)
465
    {
466 1
        $this->addAction($this->resolveAction(CartSetLineItemCustomFieldAction::class, $action));
467 1
        return $this;
468
    }
469
470
    /**
471
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-custom-type
472
     * @param CartSetLineItemCustomTypeAction|callable $action
473
     * @return $this
474
     */
475 1
    public function setLineItemCustomType($action = null)
476
    {
477 1
        $this->addAction($this->resolveAction(CartSetLineItemCustomTypeAction::class, $action));
478 1
        return $this;
479
    }
480
481
    /**
482
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-totalprice
483
     * @param CartSetLineItemPriceAction|callable $action
484
     * @return $this
485
     */
486 1
    public function setLineItemPrice($action = null)
487
    {
488 1
        $this->addAction($this->resolveAction(CartSetLineItemPriceAction::class, $action));
489 1
        return $this;
490
    }
491
492
    /**
493
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-totalprice
494
     * @param CartSetLineItemShippingDetailsAction|callable $action
495
     * @return $this
496
     */
497 1
    public function setLineItemShippingDetails($action = null)
498
    {
499 1
        $this->addAction($this->resolveAction(CartSetLineItemShippingDetailsAction::class, $action));
500 1
        return $this;
501
    }
502
503
    /**
504
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-taxamount
505
     * @param CartSetLineItemTaxAmountAction|callable $action
506
     * @return $this
507
     */
508 1
    public function setLineItemTaxAmount($action = null)
509
    {
510 1
        $this->addAction($this->resolveAction(CartSetLineItemTaxAmountAction::class, $action));
511 1
        return $this;
512
    }
513
514
    /**
515
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-taxrate
516
     * @param CartSetLineItemTaxRateAction|callable $action
517
     * @return $this
518
     */
519 1
    public function setLineItemTaxRate($action = null)
520
    {
521 1
        $this->addAction($this->resolveAction(CartSetLineItemTaxRateAction::class, $action));
522 1
        return $this;
523
    }
524
525
    /**
526
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-totalprice
527
     * @param CartSetLineItemTotalPriceAction|callable $action
528
     * @return $this
529
     */
530 1
    public function setLineItemTotalPrice($action = null)
531
    {
532 1
        $this->addAction($this->resolveAction(CartSetLineItemTotalPriceAction::class, $action));
533 1
        return $this;
534
    }
535
536
    /**
537
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-locale
538
     * @param CartSetLocaleAction|callable $action
539
     * @return $this
540
     */
541 1
    public function setLocale($action = null)
542
    {
543 1
        $this->addAction($this->resolveAction(CartSetLocaleAction::class, $action));
544 1
        return $this;
545
    }
546
547
    /**
548
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shipping-address
549
     * @param CartSetShippingAddressAction|callable $action
550
     * @return $this
551
     */
552 1
    public function setShippingAddress($action = null)
553
    {
554 1
        $this->addAction($this->resolveAction(CartSetShippingAddressAction::class, $action));
555 1
        return $this;
556
    }
557
558
    /**
559
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shippingmethod
560
     * @param CartSetShippingMethodAction|callable $action
561
     * @return $this
562
     */
563 1
    public function setShippingMethod($action = null)
564
    {
565 1
        $this->addAction($this->resolveAction(CartSetShippingMethodAction::class, $action));
566 1
        return $this;
567
    }
568
569
    /**
570
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shippingmethod-taxamount
571
     * @param CartSetShippingMethodTaxAmountAction|callable $action
572
     * @return $this
573
     */
574 1
    public function setShippingMethodTaxAmount($action = null)
575
    {
576 1
        $this->addAction($this->resolveAction(CartSetShippingMethodTaxAmountAction::class, $action));
577 1
        return $this;
578
    }
579
580
    /**
581
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shippingmethod-taxrate
582
     * @param CartSetShippingMethodTaxRateAction|callable $action
583
     * @return $this
584
     */
585 1
    public function setShippingMethodTaxRate($action = null)
586
    {
587 1
        $this->addAction($this->resolveAction(CartSetShippingMethodTaxRateAction::class, $action));
588 1
        return $this;
589
    }
590
591
    /**
592
     * @link https://dev.commercetools.com/http-api-projects-carts.html#set-shippingrateinput
593
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shippingrateinput
594
     * @param CartSetShippingRateInputAction|callable $action
595
     * @return $this
596
     */
597 1
    public function setShippingRateInput($action = null)
598
    {
599 1
        $this->addAction($this->resolveAction(CartSetShippingRateInputAction::class, $action));
600 1
        return $this;
601
    }
602
603
    /**
604
     * @link https://docs.commercetools.com/http-api-projects-carts.html#update-itemshippingaddress
605
     * @param CartUpdateItemShippingAddressAction|callable $action
606
     * @return $this
607
     */
608 1
    public function updateItemShippingAddress($action = null)
609
    {
610 1
        $this->addAction($this->resolveAction(CartUpdateItemShippingAddressAction::class, $action));
611 1
        return $this;
612
    }
613
614
    /**
615
     * @return CartsActionBuilder
616
     */
617
    public function of()
618
    {
619
        return new self();
620
    }
621
622
    /**
623
     * @param $class
624
     * @param $action
625
     * @return AbstractAction
626
     * @throws InvalidArgumentException
627
     */
628 50
    private function resolveAction($class, $action = null)
629
    {
630 50
        if (is_null($action) || is_callable($action)) {
631 50
            $callback = $action;
632 50
            $emptyAction = $class::of();
633 50
            $action = $this->callback($emptyAction, $callback);
634
        }
635 50
        if ($action instanceof $class) {
636 50
            return $action;
637
        }
638
        throw new InvalidArgumentException(
639
            sprintf('Expected method to be called with or callable to return %s', $class)
640
        );
641
    }
642
643
    /**
644
     * @param $action
645
     * @param callable $callback
646
     * @return AbstractAction
647
     */
648 50
    private function callback($action, callable $callback = null)
649
    {
650 50
        if (!is_null($callback)) {
651
            $action = $callback($action);
652
        }
653 50
        return $action;
654
    }
655
656
    /**
657
     * @param AbstractAction $action
658
     * @return $this;
659
     */
660 50
    public function addAction(AbstractAction $action)
661
    {
662 50
        $this->actions[] = $action;
663 50
        return $this;
664
    }
665
666
    /**
667
     * @return array
668
     */
669 50
    public function getActions()
670
    {
671 50
        return $this->actions;
672
    }
673
674
    /**
675
     * @param array $actions
676
     * @return $this
677
     */
678
    public function setActions(array $actions)
679
    {
680
        $this->actions = $actions;
681
        return $this;
682
    }
683
}
684