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

scottybowl's avatar

Catch Stripe Cashier errors when on queue

We're running a Job via a queue which sends a charge to Stripe, but the try/catch approach in the Job isn't capturing the error, instead the error gets thrown in ApiRequester which prevents the job from proceeding.

Stripe\Error\Card: Your card has insufficient funds. in /home/forge/****/vendor/stripe/stripe-php/lib/ApiRequestor.php:128 from API request 'req_*/**'

Snippet from our job:

                try { // Attempt to charge the card
                    $response = $team->charge($metadata->total);
                } catch (Stripe\Error\Base $e) {
                    // Update the charge status
                    $charge->status = 3;
                    $charge->status_message = $e->getMessage();
                    $charge->attempts++;

                    if($charge->attempts >= 3) {
                        $charge->status = 4; // Don't attempt any further charges as we've failed 3 times
                    }

                    $charge->save();
                    return;
                } catch (Exception $e) {
                    $charge->status = 3;
                    $charge->status_message = $e->getMessage();
                    $charge->attempts++;
                }

We never get past the try { } attempt - any ideas? I'm a but stuck...

0 likes
0 replies

Please or to participate in this conversation.