I'm not sure but I think Stripe will throw it's own exception and you can catch that exception
Handling stripe errors in Laravel 5 Billing
I'm trying to handle error cases with Billing in Laravel 5 (declined cards, etc). I'm using a the charge() method as follows within a command handler. The documentation says that the charge() method should return false on failure, however, the application is throwing the following:
Stripe_CardError (in ApiRequestor.php line 153 at Stripe_ApiRequestor->handleApiError('{ "error": { "message": "Your card was declined.", "type": "card_error", "code": "card_declined" } } ', '402', array('error' => array('message' => 'Your card was declined.', 'type' => 'card_error', 'code' => 'card_declined'))) in ApiRequestor.php line 268
How do I go about throwing and catching an exception for the declined charge that I can return to the view? I've tried the following, but it still returns the Stripe_CardError above to the browser:
in handler():
if(!$this->user->charge($price)){
throw new Exception('Your card was declined');
}
in controller:
try{
$this->dispatch(new CreateCharge($user));
} catch (Exception $e){
return Redirect::refresh()->withErrors(['msg',$e->getMessage])->withInput();
}
Any help would be appreciated.
For anyone encountering this issue -- the createStripeCustomer() method in StripeGateway.php was not catching the Stripe_CardError for some reason. Was able to work around it by placing the Stripe_Customer::create call in its own try/catch block. Should probably be fixed.
Please or to participate in this conversation.