Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ArchStanton's avatar

stripe not catching error

Below is my code when using the visa card no 4000000000000002, to simulate a card declined it does not catch the error but I get the Laravel error below

  try {

        $charge =  Stripe_Charge::create([
            //'amount' => Session::get('value')*100,
            'amount' => 100,
            'currency' => 'gbp',
            'description' => $data['email'],
            'card' => $data['token']
        ]);

      if ($charge) {
          DB::table('users')->where('id', Auth::user()->id)
              ->update(array('active' => 1));

          //$controller = new PagesController;
          //print $controller->getProgress();
          return Redirect::to('/intro');

      }
}
catch (Exception $e) {
  dd('card was declined1');
}
catch (Stripe_InvalidRequestError $e) {
    dd('card was declined2');
}

catch(StripeCardError $e) {
        dd('card was declined3');
    }
```

Stripe_CardError (card_declined) Your card was declined. Open: /httpdocs/vendor/stripe/stripe-php/lib/Stripe/ApiRequestor.php case 404: throw new Stripe_InvalidRequestError(isset($error['message']) ? $error['message'] : null, isset($error['param']) ? $error['param'] : null, $rcode, $rbody, $resp); case 401: throw new Stripe_AuthenticationError(isset($error['message']) ? $error['message'] : null, $rcode, $rbody, $resp); case 402: throw new Stripe_CardError(isset($error['message']) ? $error['message'] : null, isset($error['param']) ? $error['param'] : null, isset($error['code']) ? $error['code'] : null,

0 likes
1 reply
MThomas's avatar
MThomas
Best Answer
Level 35

In your code you catch StripeCardError the Exception thrown is Stripe_CardError though.

Please or to participate in this conversation.