diff --git a/src/Exception/CardException.php b/src/Exception/CardException.php new file mode 100644 index 0000000..e96ee9b --- /dev/null +++ b/src/Exception/CardException.php @@ -0,0 +1,8 @@ + $token, 'discount' => $discount, ]; - $response = $this->client->post('/customer', [ - 'json' => $data - ]); + try { + $response = $this->client->post('/customer', [ + 'json' => $data + ]); + } catch (ClientException $exception) { + $response = $exception->getResponse(); + $json = json_decode($response->getBody()); + if (402 === $json->error->status) { + throw new CardException($json->error->message, $json->error->status, $exception); + } + throw $exception; + } if (200 !== $response->getStatusCode()) { return false; } @@ -107,8 +117,8 @@ public function updateCustomerCard($id, $token) } catch (ClientException $exception) { $response = $exception->getResponse(); $json = json_decode($response->getBody()); - if (404 === $json->error->status) { - throw new CustomerNotFoundException($json->error->message, $json->error->status, $exception); + if (402 === $json->error->status) { + throw new CardException($json->error->message, $json->error->status, $exception); } throw $exception; }