@@ 132-155 (lines=24) @@ | ||
129 | * |
|
130 | * @return bool |
|
131 | */ |
|
132 | public function complete(int $cartId) |
|
133 | { |
|
134 | if (empty($cartId)) { |
|
135 | throw new InvalidArgumentException('Cart id cannot be empty'); |
|
136 | } |
|
137 | ||
138 | $response = $this->httpPut("/api/v1/checkouts/complete/{$cartId}"); |
|
139 | ||
140 | // Use any valid status code here |
|
141 | if (204 !== $response->getStatusCode()) { |
|
142 | switch ($response->getStatusCode()) { |
|
143 | case 400: |
|
144 | throw new DomainExceptions\ValidationException(); |
|
145 | break; |
|
146 | default: |
|
147 | $this->handleErrors($response); |
|
148 | ||
149 | break; |
|
150 | } |
|
151 | } |
|
152 | ||
153 | return true; |
|
154 | } |
|
155 | ||
156 | /** |
|
157 | * @param int $cartId |
|
158 | * |
|
@@ 164-187 (lines=24) @@ | ||
161 | * |
|
162 | * @return ShipmentCollection |
|
163 | */ |
|
164 | public function getShippingMethods(int $cartId): ShipmentCollection |
|
165 | { |
|
166 | if (empty($cartId)) { |
|
167 | throw new InvalidArgumentException('Cart id cannot be empty'); |
|
168 | } |
|
169 | ||
170 | $response = $this->httpGet("/api/v1/checkouts/select-shipping/{$cartId}"); |
|
171 | ||
172 | // Use any valid status code here |
|
173 | if (200 !== $response->getStatusCode()) { |
|
174 | switch ($response->getStatusCode()) { |
|
175 | case 400: |
|
176 | throw new DomainExceptions\ValidationException(); |
|
177 | break; |
|
178 | default: |
|
179 | $this->handleErrors($response); |
|
180 | ||
181 | break; |
|
182 | } |
|
183 | } |
|
184 | ||
185 | return $this->hydrator->hydrate($response, ShipmentCollection::class); |
|
186 | } |
|
187 | ||
188 | /** |
|
189 | * @param int $cartId |
|
190 | * |
|
@@ 196-219 (lines=24) @@ | ||
193 | * |
|
194 | * @return PaymentCollection |
|
195 | */ |
|
196 | public function getPaymentMethods(int $cartId): PaymentCollection |
|
197 | { |
|
198 | if (empty($cartId)) { |
|
199 | throw new InvalidArgumentException('Cart id cannot be empty'); |
|
200 | } |
|
201 | ||
202 | $response = $this->httpGet("/api/v1/checkouts/select-payment/{$cartId}"); |
|
203 | ||
204 | // Use any valid status code here |
|
205 | if (200 !== $response->getStatusCode()) { |
|
206 | switch ($response->getStatusCode()) { |
|
207 | case 400: |
|
208 | throw new DomainExceptions\ValidationException(); |
|
209 | break; |
|
210 | default: |
|
211 | $this->handleErrors($response); |
|
212 | ||
213 | break; |
|
214 | } |
|
215 | } |
|
216 | ||
217 | return $this->hydrator->hydrate($response, PaymentCollection::class); |
|
218 | } |
|
219 | } |
|
220 |