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

connecteev's avatar

Stripe Webhooks using Laravel Cashier and spatie/laravel-stripe-webhooks

Really stuck on this and hope someone's able to help me out!

I'm using Laravel Cashier and just installed https://github.com/spatie/laravel-stripe-webhooks - I'd like to use it to listen to and respond to webhook events from Stripe.

I have 2 problems / questions:

  1. Once you set the webhooks URL, how do you disable the default Cashier URL of /stripe/webhook?

According to the installation steps, you define your webhook APi endpoint like this:

In routes/web.php:

Route::stripeWebhooks('my_stripe_webhooks_endpoint');

In the VerifyCsrfToken middleware:

protected $except = [
    'my_stripe_webhooks_endpoint',
];

Now, when I use the stripe-cli (on localhost) and run stripe listen (and forward events to http://localhost:8000/my_stripe_webhooks_endpoint, as specified in the Stripe docs, I see a 500 POST response. Why, and how do i turn it to a 200 response that Stripe needs to see?

^COneStepAtATime:kb_backend_apis_laravel$ stripe listen --forward-to http://localhost:8000/my_stripe_webhooks_endpoint
> Ready! Your webhook signing secret is whsec_ER94Uk56z5nlcKrD1OREbX2Q9e1LgEXg (^C to quit)
2020-05-11 17:33:48   --> payment_intent.created [evt_0Ghm46DXGF9cqh5pIZatClX2]
2020-05-11 17:33:48  <--  [500] POST http://localhost:8000/my_stripe_webhooks_endpoint [evt_0Ghm46DXGF9cqh5pIZatClX2]
2020-05-11 17:35:58   --> payment_intent.created [evt_0Ghm6DDXGF9cqh5pdW88RL1W]
2020-05-11 17:35:58  <--  [500] POST http://localhost:8000/my_stripe_webhooks_endpoint [evt_0Ghm6DDXGF9cqh5pdW88RL1W]

On the other hand, this (Default) Cashier webhook route: stripe/webhook is still enabled, and responds with a 200 status code! Logs below from performing the same operation, except I forward the webhook events to /stripe/webhook:

Which brings me to question #2:

2 How can I disable this default Cashier route, and make the one I want to use return a 200 response?

^COneStepAtATime:kb_backend_apis_laravel $ stripe listen --forward-to http://localhost:8000/stripe/webhook
> Ready! Your webhook signing secret is whsec_Ex94Uk56z5nlcKrD1OREbXVQ9e1LgEXg (^C to quit)
2020-05-11 17:51:46   --> payment_method.attached [evt_0GhmLTDXGF9cqh5p67406apI]
2020-05-11 17:51:46  <--  [200] POST http://localhost:8000/stripe/webhook [evt_0GhmLTDXGF9cqh5p67406apI]
2020-05-11 17:51:50   --> customer.source.created [evt_0GhmLTDXGF9cqh5pUVdieeIT]
2020-05-11 17:51:50  <--  [200] POST http://localhost:8000/stripe/webhook [evt_0GhmLTDXGF9cqh5pUVdieeIT]

0 likes
2 replies
connecteev's avatar
connecteev
OP
Best Answer
Level 11

Here's the answer for anyone looking:

  1. To disable cashier's routes: Add Cashier::ignoreRoutes(); in the boot method of your AppServiceProvider

  2. To fix the 500 error: When trying to override the Stripe Webhook job to perform custom logic as specified in https://github.com/spatie/laravel-stripe-webhooks#performing-custom-logic Use

use Spatie\StripeWebhooks\ProcessStripeWebhookJob;

class MyCustomStripeWebhookJob extends ProcessStripeWebhookJob
{
    public function handle()
    {
        // do some custom stuff beforehand

        parent::handle();

        // do some custom stuff afterwards
    }
}

You cannot have a __construct() function (which gets created by default if you run php artisan make:job) in this job, which will throw the 500 exception

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

Exception:

[2020-05-12 17:08:26] local.ERROR: Typed property Spatie\WebhookClient\ProcessWebhookJob::$webhookCall must not be accessed before initialization {"exception":"[object] (Error(code: 0): Typed property Spatie\WebhookClient\ProcessWebhookJob::$webhookCall must not be accessed before initialization at 
1 like
max_fletcher's avatar

Hello and Good Evening(from where I am currently). I am working with this package with laravel 7. Problem is, it says something like it can't verify stripe signature (or something borderline of that) which is showing me a status code of 500(same as you). Can you advise me on what to do or what you did specifically in order to get rid of the 500 status code ?? If you can show me your code, I would really appreciate it. I am currently stuck in a rut with this. Also, I found some guys on github who have encountered the same problem.

Please or to participate in this conversation.