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