From 77c68dd333ce087bd8da60b132249bbec2a17897 Mon Sep 17 00:00:00 2001 From: Tom Lorentsen Date: Sat, 30 Sep 2017 19:42:18 +0100 Subject: [PATCH] Catch card failiers --- src/Exception/CardException.php | 8 ++++++++ src/Stripe.php | 20 +++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 src/Exception/CardException.php 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; }