VibeRescue · Blog

Stripe webhook not working in production: payment succeeds, nothing unlocks

October 19, 2026 · 12 min read

Your app takes money. Stripe shows the payment as Succeeded, the customer gets a receipt, and then nothing happens in your app: the account stays on the free plan, the order never appears, the credits never arrive. In test mode it all worked. In production the webhook fails, and Stripe's dashboard shows a row of red 400, 401 or timed-out deliveries.

This is one of the most common breaks in apps built with Lovable, Bolt, Cursor, v0 or Replit, because the AI wires up Checkout quickly but the webhook depends on settings that live outside the code: the right signing secret for the right mode, an endpoint Stripe can actually reach, and a handler that reads the request body exactly as Stripe sent it. This guide walks through each cause in the order you should check them. If the problem is that environment variables are missing in general, read Environment variables missing in production first.

Step 0: read the delivery log before touching code

Open your webhook endpoint in the Stripe Dashboard (under Developers, shown as Workbench in newer accounts) and look at its event deliveries. Each failed attempt shows the HTTP status your server returned and the response body. That status tells you which section of this guide you need:

What Stripe showsWhat it usually meansGo to
No delivery attempts at allThe endpoint isn't registered in this mode (test vs live), or the event type isn't selected on it.1 and 6
400 with "No signatures found matching the expected signature for payload"Wrong signing secret, or the body was changed before verification.2 and 3
401 or 403Something in front of your handler wants a logged-in user: Supabase JWT checks, Vercel Deployment Protection, or your own auth middleware.4
301, 302, 307, 308The URL redirects (www vs non-www, http vs https, a trailing slash, or a login redirect). Stripe treats redirects as failures.5
404Wrong path, or the function was never deployed to production.5
500The handler crashed after verification: a missing env var, a database error, or a blocked write.6
Timed outThe handler does slow work before answering.7
200, but the app still doesn't unlockThe webhook works; the logic after it doesn't.6

Also open your host's logs for the same minute (Vercel Logs, Supabase Edge Function logs, Replit Deployment logs). The status in Stripe plus the error line in your logs is usually enough to pinpoint the cause.

1. Test mode and live mode are two separate setups

Stripe keeps test and live data apart, and that includes webhooks. An endpoint you created while testing does not receive live events, and each endpoint has its own signing secret. When you switch to live payments you need, all at once:

Mixing them causes confusing results. A common one: you click "send test event" or replay a test event against an endpoint that verifies with the live secret, and the signature check fails even though the code is fine. The event's mode and the secret's mode must match.

2. The signing secret is wrong, stale, or not loaded

Stripe's own docs name the wrong endpoint secret as the most common cause of signature errors. Check these in order:

  1. It must be the webhook signing secret, which starts with whsec_. Not the secret key (sk_), not the publishable key (pk_).
  2. It must belong to this exact endpoint. The secret printed by stripe listen on your laptop is different from the secret of the endpoint in the Dashboard. Copying the CLI secret into production is a classic mistake.
  3. It must be loaded at runtime. Log whether the variable exists (never log the value itself). On Vercel, a changed variable only applies to new deployments, so redeploy. On Supabase, set it as a function secret, for example supabase secrets set STRIPE_WEBHOOK_SECRET=whsec_....
  4. Watch for copy-paste damage: a trailing space, a newline, or quotes pasted into the value field.
  5. An empty secret now fails loudly. Since stripe for Node 23.0.1 (October 22, 2026), a signing secret made only of spaces or line breaks is rejected instead of being used, so you get an error about the secret rather than a confusing signature mismatch. If that starts after you upgrade, the variable is blank in that environment: set the real whsec_ value and redeploy.

3. The request body was changed before verification

Stripe signs the exact bytes it sends. If your framework parses the body into JSON first and you pass the re-serialized object to the verifier, the signature no longer matches. AI tools get this wrong often, and sometimes rewrite a correct handler into a broken one while "fixing" something nearby. Read the raw body, verify, and only then parse.

Next.js App Router (Cursor, v0)

// app/api/webhooks/stripe/route.ts
import Stripe from "stripe";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

export async function POST(req: Request) {
  const body = await req.text();               // raw body, not req.json()
  const sig = req.headers.get("stripe-signature");
  let event: Stripe.Event;
  try {
    event = stripe.webhooks.constructEvent(body, sig!, process.env.STRIPE_WEBHOOK_SECRET!);
  } catch (err) {
    return new Response("Bad signature", { status: 400 });
  }
  // handle event.type here (see section 6), then:
  return new Response("ok", { status: 200 });
}

Keep this route on the Node.js runtime unless you know your Stripe setup works on the edge.

Next.js Pages Router

Turn off the built-in body parser for the webhook route with export const config = { api: { bodyParser: false } }, read the raw request stream into a buffer, and pass that buffer to constructEvent.

Express (Replit, Bolt exports with a Node server)

// The webhook route needs the raw body, so register it BEFORE express.json()
app.post("/api/webhooks/stripe", express.raw({ type: "application/json" }), (req, res) => {
  let event;
  try {
    event = stripe.webhooks.constructEvent(req.body, req.headers["stripe-signature"], process.env.STRIPE_WEBHOOK_SECRET);
  } catch (err) {
    return res.status(400).send("Bad signature");
  }
  res.sendStatus(200);
});

app.use(express.json()); // other routes

Supabase Edge Function (Lovable, Bolt)

Lovable and Bolt apps usually handle Stripe in a Supabase Edge Function. Edge Functions run on Deno, which needs the async verifier and a Web Crypto provider:

import Stripe from "npm:stripe";

const stripe = new Stripe(Deno.env.get("STRIPE_SECRET_KEY")!);
const cryptoProvider = Stripe.createSubtleCryptoProvider();

Deno.serve(async (req) => {
  const body = await req.text();
  const sig = req.headers.get("Stripe-Signature")!;
  try {
    const event = await stripe.webhooks.constructEventAsync(
      body, sig, Deno.env.get("STRIPE_WEBHOOK_SECRET")!, undefined, cryptoProvider
    );
    // handle event.type here
    return new Response("ok", { status: 200 });
  } catch (err) {
    return new Response("Bad signature", { status: 400 });
  }
});

If the code calls the synchronous constructEvent in an Edge Function, it fails even with the right secret. That's a different error from a bad signature, so read the function log carefully.

4. The endpoint demands a logged-in user

Stripe is the caller here, not your customer, so it has no session cookie and no user token. Anything that requires one returns 401 or 403 before your code runs:

5. The URL redirects or doesn't exist

Stripe doesn't follow redirects: it records any 3xx response as a failed delivery. Paste the exact endpoint URL into a terminal with curl -i -X POST https://yourdomain.com/api/webhooks/stripe and look at the status. You want a 400 from your own code (no signature was sent), not a redirect or a 404. Typical fixes:

6. The webhook returns 200, but the app never unlocks

Now Stripe is happy and the problem is your own logic. The usual suspects:

7. Timeouts, retries and duplicate events

Stripe expects a quick 2xx and recommends answering before any slow work. If your handler sends emails, calls an AI model or generates files before it answers, the delivery can time out and Stripe tries again. In live mode Stripe retries failed deliveries for up to three days with exponential backoff; test deliveries are retried three times over a few hours.

Two consequences matter for your code:

Test it properly before real customers do

  1. Locally, run stripe listen --forward-to localhost:3000/api/webhooks/stripe, use the whsec_ it prints in your local env only, and fire events with stripe trigger checkout.session.completed.
  2. On the deployed app, send a test event from the endpoint page in the Dashboard and confirm a 200 plus the expected row in your database.
  3. Do one real low-value live purchase yourself, check that the account unlocks, then refund it from the Dashboard.
  4. Once the fix is live, resend the failed events from the delivery log (or with stripe events resend) so customers who already paid get what they bought.

What not to do

How to prompt your AI tool for this fix

My Stripe webhook fails in production with [status from the Stripe delivery log] and
this log line: [paste error]. Do not change pricing, checkout or UI code.
Check only the webhook handler: it must read the raw body, verify the
Stripe-Signature with STRIPE_WEBHOOK_SECRET, not require a user session,
answer 200 quickly, skip event IDs it already processed, and update the
database with a server-side client. Show me the exact lines you change.

Scoping the prompt like this keeps the tool from rewriting checkout while it hunts for the bug. If it still loops, here's how to break the AI fix loop.

A go-live checklist for Stripe webhooks

FAQ

Why does my Stripe webhook work in test mode but not in production?

Test and live mode are separate. A webhook endpoint created in test mode doesn't receive live events, and every endpoint has its own whsec_ signing secret. Create a live-mode endpoint for your production URL, put its signing secret in your production environment variables, redeploy, and use live keys and live price IDs.

What does "No signatures found matching the expected signature for payload" mean?

The signature check failed. Either the signing secret is wrong (a CLI secret, a test secret, a secret from another endpoint, or a value with extra spaces), or the request body was parsed or changed before verification. Pass the raw body string or buffer, the Stripe-Signature header and the endpoint's whsec_ secret to the verifier.

Why does my Supabase Edge Function return 401 to Stripe?

Supabase Edge Functions require a valid user JWT by default, and Stripe doesn't send one. Deploy the webhook function with --no-verify-jwt or set verify_jwt = false for it in supabase/config.toml, and keep the Stripe signature check in the code as the protection.

Should the success page unlock the paid features?

No. Customers can close the tab before it loads, and anyone can open the URL. Let the verified webhook update the database, identify the user with client_reference_id or metadata, and have the success page only show the current status.

Why did a customer get charged once but credited twice?

Stripe can deliver the same event more than once, for example after a timeout. Store each processed event ID with a unique constraint and skip duplicates, and answer with a 2xx quickly before doing slow work.

Not sure which of these it is?

Run the free Rescue Scan: paste a public GitHub repo and VibeRescue, an automated AI repair tool, classifies the problem (code bug, missing files, or missing secrets) before you pay anything. If it is something you can fix with this guide, we will tell you. If you want a fix run, it opens a pull request, with a full refund if the run can't fix it.

Run the free Rescue Scan →