MELLEPRISE MELLEPRISE AI MP Blog
← All articles

stripe webhook works in test mode but not live — the exact fix path

Pastel comic of two browser windows with a broken plug between a test checkout and a live webhook house

Your stripe webhook works in test mode but not live: the test checkout unlocked the account, then the first real customer paid and nothing happened.

No order row. No credit balance. No confirmation email. Stripe may show the payment while your app behaves as if the purchase never existed.

This is rarely a mysterious webhook bug. It is usually a mode mismatch: one object still belongs to the sandbox, one secret came from the wrong endpoint, or the live endpoint never received the event.

stripe webhook works in test mode but not live because test and live are separate worlds

Stripe test mode and live mode are not two labels on the same data. Keys, customers, products, prices, payment methods and webhook endpoints are separate objects in each mode.

The test proof is real but narrow. It proves that your handler can process a correctly signed test event. It does not prove that production has a live endpoint, the live endpoint secret, live object IDs or a deployment that uses them.

Stripe’s go-live checklist says to register production webhooks and confirm that the live endpoint behaves like the test endpoint. The detail that breaks launches is easy to miss: every endpoint has its own signing secret. Even the same URL can use a different secret in test and live mode.

Read the live delivery before touching code

Open the webhook endpoint in live mode and inspect Event deliveries. The delivery state separates the failure layers:

  • No live delivery: Stripe never sent the event there, the endpoint does not listen for that event type, or the payment is not live.
  • 3xx: the URL redirects. Stripe treats redirected webhooks as failures; use the final URL directly.
  • 400: often signature verification failed or the handler rejected the payload.
  • 401, 403, 404 or 405: the public URL, auth middleware, routing or POST method is wrong.
  • 500: Stripe reached the app, but the handler crashed.
  • TLS error or unable to connect: the host, certificate chain or public network path is broken; Stripe requires TLS 1.2 or higher.
  • Timeout: the handler does too much before responding. Acknowledge first, then process asynchronously.
  • 2xx but nothing unlocks: transport is fine; the app ignores the event type, writes the wrong object or is not idempotent.

A browser success screen only means checkout completed. Fulfillment depends on the webhook write.

Why AI-built apps hit this exact failure

AI builders assemble the sandbox happy path. They create checkout, paste test keys into the environment, add a webhook handler and verify it with the Stripe CLI. The demo works because every piece points to test mode.

Launch changes four things at once: live API keys, live product and price IDs, a separate live webhook endpoint and production secrets in the host or serverless platform.

The model often updates one visible variable and misses the rest. In Lovable, Replit, Vercel or Supabase Edge Functions, the code may be correct while production still uses the CLI secret from stripe listen, the test endpoint secret or a test price ID. That is why another broad “fix payments” prompt is dangerous. The repair is a small audit.

Step 1: prove whether the payment is live

  1. Open Stripe in live mode.
  2. Find the real payment or Checkout Session.
  3. Copy its object ID and creation time.
  4. Confirm that it has livemode: true.
  5. If it exists only in test mode, stop here: checkout keys or price IDs are still wrong.

If the payment is live, compare its time with live Event deliveries. If no event appears, check the endpoint URL and selected event types.

Step 2: create the live endpoint deliberately

In live mode, register the production webhook endpoint URL. Select only the events your application handles, commonly checkout.session.completed, invoice events or payment failure events.

Use the exact public URL. Do not use localhost, a temporary tunnel, a preview deployment or a URL that redirects. A small path difference is enough: /api/stripe-webhook and /api/webhooks/stripe are different endpoints.

If the app is serverless, confirm that the deployed route exists publicly and accepts POST without browser authentication middleware.

Step 3: replace the signing secret, not only the API key

Copy the signing secret from the live endpoint itself. It starts with whsec_. Put it into the production server environment, then redeploy or restart the service.

Three wrong secrets are common: the test endpoint secret, the local secret printed by stripe listen, or a secret from another endpoint. All three can look configured while failing every live signature. If logs mention signature verification only on live events, start here. The broader secret model is covered in stripe webhook secret.

Step 4: align keys, prices and products

A live webhook cannot repair a checkout that still creates test objects. Inspect production configuration:

  • publishable key starts with pk_live_,
  • backend key starts with sk_live_ or rk_live_,
  • price IDs come from live mode,
  • coupons, meters or subscription items used by checkout also exist in live mode,
  • no old test value remains in a second host, edge function secret store or database row.

Mode mixing is confusing because the key and object ID can each be valid alone. Stripe still rejects the combination because objects are not shared across modes. The wider launch chain is covered in stripe live mode.

Step 5: make the handler fast and idempotent

If live delivery reaches your server but returns 500 or times out, inspect application logs. Production-only causes include missing database env vars, a service-role key absent from the serverless function, a table that exists only in a test Supabase project or a slow fulfillment chain.

The handler should verify the signature, store the event ID, respond quickly and process heavy work asynchronously where possible. It must tolerate retries. Stripe can deliver the same event more than once, so fulfillment must not duplicate credits or orders.

If transport is already 2xx but the app never changes state, continue with stripe webhook. The failure is then inside routing, event-type handling or entitlement logic, not live-mode registration.

Do not test live with real card details

Stripe prohibits testing in live mode with real payment method details. A real customer payment is evidence, not a test harness.

Build the same flow in a sandbox: same events, equivalent products and prices, same handler version. Use test cards, stripe listen locally or trigger events with the Stripe CLI. Then compare the live endpoint configuration with the proven sandbox setup.

If this audit keeps uncovering missing production pieces, stabilize the whole release path with lovable deploy. Webhook mode is one launch layer; environment variables, database access, auth and rollback belong to the same production baseline.

The ten-minute production checklist

  • Real payment exists in live mode and has livemode: true.
  • Live webhook endpoint exists with the exact production URL.
  • Endpoint listens for the event type your app fulfills on.
  • No redirect, auth wall, missing route or method mismatch blocks it.
  • Live endpoint signing secret is in production env.
  • CLI or test-mode whsec_ is gone from production.
  • Live publishable and secret keys sit in the right frontend/backend places.
  • Live product, price and coupon IDs are used by checkout.
  • Database and serverless secrets point at production backends.
  • Live deliveries return 2xx and fulfillment is idempotent.

Test mode proves the handler. Live mode proves the launch configuration. If only live fails, compare the two environments before rewriting business logic.

FAQ

Why does a Stripe webhook work in test mode but not live?

Test and live mode use separate objects. The live endpoint, its signing secret, live API keys, live product or price IDs and the production deployment must all be recreated or updated; one leftover test value can stop fulfillment.

Can I test a live Stripe webhook with a real card?

Do not test in live mode with real payment method details. Stripe prohibits that. Test the same flow in a sandbox with test cards or the Stripe CLI, then compare the live endpoint URL, selected events and signing secret.

What should I check first when live webhook events do not arrive?

Open the live-mode webhook endpoint in Stripe and inspect Event deliveries. No delivery means the endpoint, event selection or live object chain is wrong; a 3xx, 4xx, 5xx, TLS or timeout status points to the public URL or your handler.