Skip to content

Commit

Permalink
Catch card failiers
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaslorentsen committed Sep 30, 2017
1 parent 166a02e commit 77c68dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/Exception/CardException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace RoundPartner\Stripe\Exception;

class CardException extends \Exception
{

}
20 changes: 15 additions & 5 deletions src/Stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace RoundPartner\Stripe;

use GuzzleHttp\Exception\ClientException;
use RoundPartner\Stripe\Exception\CardException;
use RoundPartner\Stripe\Exception\CustomerNotFoundException;

class Stripe extends RestClient
Expand Down Expand Up @@ -86,9 +87,18 @@ public function newCustomer($account, $description, $email, $token = null, $disc
'token' => $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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 77c68dd

Please sign in to comment.