Skip to content
ketryon
Question 1.1 · Payments

Updated

Made by AIHow we do it

Why does my Stripe webhook work locally but fail on Vercel?

Check the secret first. The Stripe CLI’s secret only works on your machine — in production, the endpoint’s secret from your Stripe dashboard belongs in Vercel.

What happens

The webhook works when you test with the Stripe CLI, but after deploying to Vercel every event fails with a 400 or “signature verification failed”. The customer pays in Stripe — your app never finds out.

Why it happens

Stripe signs every request with a secret that starts with whsec_. Your code recalculates the signature and compares. Common causes: the secret comes from the Stripe CLI, test and live mode are mixed up, the variable is missing in Vercel’s Production — or the code parses the body as JSON before verifying.

“Test and live have different keys. Everything has to belong to the same mode.”

Good to know

What to check

  1. a.Stripe → Workbench → Webhooks: open the endpoint pointing at your Vercel URL.
  2. b.The right mode — test or live.
  3. c.Click Reveal secret and copy the endpoint’s secret. It differs from the Stripe CLI’s.
  4. d.Vercel → Settings → Environment Variables: compare STRIPE_WEBHOOK_SECRET for Production.

How to fix it

Add the right secret, redeploy and resend a failed event. If you read the body yourself, use req.text():

stripe/route.tsapp/api/webhooks/stripe/route.ts
export async function POST(req: Request) {
  const body = await req.text();
  const sig = req.headers.get("stripe-signature")!;
  let event;
  try {
    event = stripe.webhooks.constructEvent(
      body, sig, process.env.STRIPE_WEBHOOK_SECRET!
    );
  } catch {
    return new Response("Invalid signature", { status: 400 });
  }
  return new Response("ok");
}

Swipe sideways to see the full line

from $99per fix

Rather have us do it? A developer fixes it in the chat.

Start a chat visit

How to avoid it

One secret per environment — Preview and Production — in the right mode, and a test event after every change of domain or key. Stripe shows failed deliveries under Webhooks → your endpoint → Event deliveries.

Did this answer help?

Sources

  1. 1Manage webhook endpointsStripe
  2. 2Set up and deploy a webhookStripe
  3. 3Manage event destinationsStripe
  4. 4Managing environment variablesVercel
  5. 5route.jsNext.js

Ketryon

Written by AI

This answer was written by AI, which also compared it with the sources above. No person has reviewed it.

Report a mistake