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

vincent15000's avatar

Stripe webhook not working in production

Hello,

I have uploaded the project on a webserver to check if it works fine or not.

I have added this in the app.php file.

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->append(CleanParametersMiddleware::class);
        $middleware->validateCsrfTokens(except: [
            'stripe/*',
        ]);    
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

The subscription is created on stripe but not in the database.

When I check the stripe logs, I see a 403 error.

Do I have forgotten something ?

Thanks for your help.

V

0 likes
2 replies
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

When dealing with Stripe webhooks, a 403 error typically indicates a permission issue or that the request is being blocked. Here are some steps to troubleshoot and resolve the issue:

  1. Verify Webhook URL: Ensure that the webhook URL configured in your Stripe dashboard matches the endpoint in your application. It should be publicly accessible and correctly routed to handle the incoming requests.

  2. CSRF Protection: You mentioned that you have configured CSRF token validation to exclude the stripe/* routes. Double-check that the webhook endpoint is correctly excluded from CSRF protection. The path should match exactly as it appears in your routes.

  3. Firewall and Security Settings: Ensure that your server's firewall or any security settings are not blocking incoming requests from Stripe. You might need to whitelist Stripe's IP addresses.

  4. SSL/TLS Configuration: Stripe requires that webhooks are served over HTTPS. Make sure your server has a valid SSL certificate and that the webhook URL uses https.

  5. Stripe Secret Key: Ensure that your application is using the correct Stripe secret key for the environment (live or test). A mismatch can cause authentication issues.

  6. Webhook Secret: Verify that you are using the correct webhook secret to validate the incoming requests from Stripe. This is different from your Stripe secret key and is used to ensure the request is genuinely from Stripe.

  7. Logging: Add logging to your webhook handler to capture incoming requests and any errors that occur during processing. This can help identify where the issue might be.

Here's a basic example of how you might set up a Stripe webhook handler in PHP:

Make sure to replace 'your_webhook_secret' with your actual webhook secret from the Stripe dashboard. This code will help ensure that only valid requests from Stripe are processed.

1 like
vincent15000's avatar

Effectively I had to replace the webhook secret.

Please or to participate in this conversation.