1 | <?php |
||
21 | final class Checkout extends HttpApi |
||
22 | { |
||
23 | const SHIPPING_ADDRESS_FIELDS = [ |
||
24 | 'firstName', |
||
25 | 'lastName', |
||
26 | 'city', |
||
27 | 'postcode', |
||
28 | 'street', |
||
29 | 'countryCode', |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * @throws Exception |
||
34 | * |
||
35 | * @return ResponseInterface|void |
||
36 | */ |
||
37 | public function updateAddress(int $cartId, array $shippingAddress, bool $differentBillingAddress = false, array $billingAddress = []) |
||
69 | |||
70 | /** |
||
71 | * @throws Exception |
||
72 | * |
||
73 | * @return ResponseInterface|void |
||
74 | */ |
||
75 | public function updatePaymentMethod(int $cartId, array $params = []) |
||
76 | { |
||
77 | if (empty($cartId)) { |
||
78 | throw new InvalidArgumentException('Cart id cannot be empty'); |
||
79 | } |
||
80 | |||
81 | $response = $this->httpPut('/api/v1/checkouts/select-payment/'.$cartId, $params); |
||
82 | if (!$this->hydrator) { |
||
83 | return $response; |
||
84 | } |
||
85 | |||
86 | // Use any valid status code here |
||
87 | if (204 !== $response->getStatusCode()) { |
||
88 | $this->handleErrors($response); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @throws Exception |
||
94 | * |
||
95 | * @return ResponseInterface|void |
||
96 | */ |
||
97 | public function complete(int $cartId) |
||
98 | { |
||
99 | if (empty($cartId)) { |
||
100 | throw new InvalidArgumentException('Cart id cannot be empty'); |
||
101 | } |
||
102 | |||
103 | $response = $this->httpPut('/api/v1/checkouts/complete/'.$cartId); |
||
104 | if (!$this->hydrator) { |
||
105 | return $response; |
||
106 | } |
||
107 | |||
108 | // Use any valid status code here |
||
109 | if (204 !== $response->getStatusCode()) { |
||
110 | $this->handleErrors($response); |
||
111 | } |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @throws Exception |
||
116 | * |
||
117 | * @return ResponseInterface|ShipmentCollection |
||
118 | */ |
||
119 | public function getShippingMethods(int $cartId) |
||
137 | |||
138 | /** |
||
139 | * @throws Exception |
||
140 | * |
||
141 | * @return PaymentCollection|ResponseInterface |
||
142 | */ |
||
143 | public function getPaymentMethods(int $cartId) |
||
161 | } |
||
162 |