Support the ongoing development of Laravel.io →
posted 9 years ago
Packages

Hello,

I am working on a small project with Laravel and Laravel Cashier. I have most things working correctly but I am having some trouble with handling stripes card errors. At the moment I am testing the declined card error which is giving me the standard "Whoops" page with the your card was declined message. I am trying to catch this exception so that I can return a view and display the error in a nicer way but for some reason it is not catching it. I have attached my try catch block of code below. Any help would be greatly appreciated.

try {
            $this->user->subscription(Input::get('plan'))->create(Input::get('stripeToken'),[
            'email' =>  $this->user->email
            ]);
        } 
        catch(Stripe_CardError $e)
        {
            $body = $e->getJsonBody();
            $err  = $body['error'];
            dd($err);
        }
Last updated 3 years ago.
0

All Stripe exceptions (on the current PHP lib) extend from \Stripe\Error\Base.

\Stripe\Error\Card
\Stripe\Error\Api
Stripe\Error\InvalidRequest
\Stripe\Error\RateLimit
\Stripe\Error\ApiConnection
\Stripe\Error\Authentication

Try catching \Stripe\Error\Card :)

Last updated 9 years ago.
0

Thanks for that :)

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

SirNessyUK sirnessyuk Joined 23 Mar 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.