Search code examples
laravellaravel-cashier

Laravel Cashier (Stripe) Custom Webhook not receiving $payload


We are trying to create a custom webhook to handle Stripe Checkout with Laravel Cashier. The problem is that we are following Laravel Cashier docs, but we are not receiving the payload from Stripe.

We are trying to hook to checkout.session.completed.

namespace App\Http\Controllers;

use Laravel\Cashier\Http\Controllers\WebhookController as CashierController;

class StripeWebhookController extends CashierController
{

    /**
     * Handle Checkout Session Completed.
     *
     * @param  array  $payload
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function handleCheckoutSessionCompleted(array $payload) // Line 12
    {
    // Code...
    }

// Error: ArgumentCountError: Too few arguments to function App\Http\Controllers\StripeWebhookController::handleCheckoutSessionCompleted(), 0 passed in /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php on line 54 and exactly 1 expected in file /var/www/html/app/Http/Controllers/StripeWebhookController.php on line 12

We also created the route in web.php

use App\Http\Controllers\StripeWebhookController;

Route::post('/stripe/webhook', [StripeWebhookController::class, 'handleCheckoutSessionCompleted']);

We did add inside App\Http\Middleware\VerifyCsrfToken

protected $except = [
    'stripe/*',
];

Finally we also added our webhook secret inside the .env file.


Solution

  • Change

    Route::post('/stripe/webhook', [StripeWebhookController::class, 'handleCheckoutSessionCompleted']);
    

    for

    Route::post('/stripe/webhook', [StripeWebhookController::class, 'handleWebhook']);