Stripe checkout works in test mode but fails after going live
Test mode and live mode keep separate keys, prices, customers, and webhook endpoints. Checkout that worked on a test key fails on the published site when the deployment still has the test secret or publishable key, a test price id, a webhook that exists only in the sandbox, or a success URL pointed at localhost or a preview. A live charge can also succeed while the app never unlocks access, because the unlock runs from a webhook or a follow-up call to Stripe, not from the success page the browser happens to open. Put the live values in the environment that actually serves the site, redeploy, then make one small real purchase and refund it.
Last updated Nov 24, 2026.
A two-minute check
Do this on the published URL. The Lovable, Bolt, Replit, or v0 preview can stay green the whole time, and it is often still on test keys.
- Open the live site in a private window. Write down which host you are on. A preview, a localhost port, or a *.vercel.app preview is a different deployment from the domain customers use.
- Click the checkout or subscribe button. If nothing happens, open the browser console and the network tab. A blocked popup looks the same as a dead button. Lovable’s own Stripe checkout opens in a new tab.
- If a request leaves the browser, read its status. A 500 whose body says “No such price” is a test price id used with a live key. No request at all means the click handler failed before it called your server, which is usually the publishable key baked into that build.
- Leave the test card 4242 4242 4242 4242 for test keys. A live key declines it. That decline means you reached live mode. It does not mean the app will unlock after a real card succeeds.
Fix it, in this order
Put the live keys in the deployed environment, then redeploy
Stripe’s API keys are per mode. Publishable keys start with pk_test_ or pk_live_. Secret keys start with sk_test_ or sk_live_. Restricted keys start with rk_test_ or rk_live_. The key in the browser and the key on the server have to be the same mode. A live publishable key with a test secret, or the reverse, creates the session in the wrong mode or fails it outright.
The publishable key is supposed to be in the page. The secret key and the webhook signing secret are not. Search the published JavaScript for pk_test_ and pk_live_. Finding sk_ or whsec_ in that file means a secret was prefixed for the client bundle.
- In the Stripe Dashboard, turn the test-mode toggle off, then open Developers → API keys. Copy the live publishable key and a live secret or restricted key. A restricted key needs permission to create Checkout Sessions and to read the objects your webhook handler reads. Do not paste the secret into a chat.
- On Vercel, including a v0 app and most Next.js apps from Cursor, set the variables on the Production environment. A value scoped only to Preview changes the preview and leaves the production domain on the old key. Vercel applies an environment change to the next deployment. The deployment that is already live keeps the values it was built with. Redeploy.
- Next.js inlines any
NEXT_PUBLIC_variable into the browser bundle at build time. Vite does the same forVITE_. After the build, that copy does not follow later edits. The secret key must not use either prefix. PutSTRIPE_SECRET_KEYwhere only the server or the edge function can read it, and put the publishable key in the public variable. Then build again. - When Bolt publishes to Netlify, set the same names in the Netlify site settings and trigger a new deploy. The Bolt preview’s env is not the production build. The same rebuild rule is why a Bolt sign-up can work in preview and fail after deploy. Those checks are in Bolt app sign-up works in preview but breaks after deploy.
- On Replit, the published app reads Production app secrets under Publishing → Adjust settings, not the workspace Secrets list the preview uses. Set the live key there and select Publish. A workspace edit does not restart the app that is already live. The same split for other secrets is in Replit app works in preview but breaks after publish.
- On Lovable, with your own Stripe account, ask to update the Stripe key and submit the live key in the Update Stripe secret key form. Lovable stores it as
STRIPE_SECRET_KEY. Do not paste the key into the project chat. On the built-in backend it shows under More → Settings → Secrets. On your own Supabase project it is synced to that project’s edge function secrets. Lovable’s built-in payments product manages keys for you. This swap is for a project that uses your own Stripe account.VITE_values belong in.env, and they are embedded at build time. Secrets are the backend values.
After the new deployment is the one customers hit, search the page source again. It should contain pk_live_. Then try the button. A stale tab can still be running the old bundle.
Paste this into the editor that shipped the checkout. It asks for prefixes and a diff, and it tells the tool to leave the secret values out of the reply:
Stripe checkout works in test mode and fails on the published site. Compare key prefixes only: pk_test_ or pk_live_, sk_test_ or sk_live_, rk_test_ or rk_live_. Do not print secret values. Find hard-coded price_ ids and say whether each one was created in test mode. Find success_url and cancel_url. They must be the published https origin. Find the webhook handler. It must verify the Stripe-Signature header with the live whsec_ secret and return 400 when verification fails. Do not disable signature verification. Do not put a secret key or a webhook secret in a NEXT_PUBLIC_ or VITE_ variable. Show the diff.
Replace test price ids with live price ids
A product or price created in the sandbox is not usable in live mode. Stripe assigns a new price_ id when you create the price with test mode off. The live key then returns No such price, often with a line that a similar object exists in test mode and a live mode key made the request. The button’s request fails, and the app looks like checkout is down.
- Turn test mode off. Open Product catalog and find the price customers should buy. If it is missing, create it there. Copy the live
price_id. The test id will not start working if you only change the key. - Search the project for
price_. The id may be hard-coded in the checkout function, or stored in an env var such asSTRIPE_PRICE_. Replace each one the live checkout uses. On Lovable, ask it to switch the app to the live price ids. Lovable’s Stripe docs call out that the ids differ. - Redeploy. A price id inlined into a server bundle or a client bundle at build time stays on the old value until the next build, same as a
NEXT_PUBLIC_key.
Register the live webhook, and store that endpoint’s signing secret
Webhook endpoints are per mode. An endpoint you added while the test-mode toggle was on does not receive live events, and its signing secret will not verify a live delivery. Stripe’s go-live checklist says to define the live endpoint and confirm it behaves like the test one. The signing secret starts with whsec_. Each endpoint has its own. Stripe’s docs also say the secret differs between test and live even when the URL is the same.
This is the usual reason a payment succeeds and the app never unlocks access, or a subscription never updates. Checkout charges the card. Your database changes only when the handler runs checkout.session.completed, customer.subscription.updated, customer.subscription.deleted, invoice.paid, or invoice.payment_failed, whichever events that handler actually switches on. Selecting those events on the test endpoint does not select them on the live one.
- Turn test mode off. In Workbench, open the Webhooks tab and create an event destination whose URL is the live function. The URL has to be public HTTPS. Live mode requires HTTPS. A localhost URL, or a preview URL the host does not serve to Stripe, will not get the events.
- Select the events the code handles. Reveal the new
whsec_and save it as the server secret the handler reads, oftenSTRIPE_WEBHOOK_SECRET. Redeploy so the function sees it. The test secret will fail verification against a live signature. - Verify the signature with the raw request body, the
Stripe-Signatureheader, and that secret. Stripe’s libraries raise when verification fails. The sample handlers return HTTP 400. The error text is “No signatures found matching the expected signature for payload.” Parsing the body as JSON before you verify changes the bytes and fails a secret that is otherwise correct. - On Supabase, and on a Lovable app whose webhook is an Edge Function, the gateway checks for a Supabase JWT before your file runs. Stripe does not send one. With verification left on, Stripe records a 401, and the function log is empty because the function did not start. The response body is along the lines of “Missing authorization header.” Set
verify_jwt = falsefor that function insupabase/config.toml, turn JWT verification off on the function’s detail page, or deploy with--no-verify-jwt. Then verify the Stripe signature inside the function and return 400 when it fails. Leave the JWT check on for functions your own users call. Supabase’s function configuration docs use a Stripe webhook as the example for turning the check off.
Lovable’s integration for your own Stripe account does not use webhooks unless you asked for them. The app asks Stripe whether the subscription is active, and it matches the subscription to the user by email. A successful payment whose email differs from the login email leaves the account on the free plan. If you did add a webhook, Lovable’s docs say you still create the event destination yourself and store the signing secret when Lovable asks for it.
Point success and cancel URLs at the live site
Checkout Session success_url and cancel_url are where Stripe sends the browser after pay or cancel. Stripe’s quickstart says the success URL has to be a page on your site that customers can be redirected to. A session whose URLs are http://localhost:3000, a Bolt or Lovable preview host, or a Vercel preview deployment can still be created. The customer’s browser is then sent to that host. On their machine, localhost is not your server. The charge can already have succeeded.
- Search the checkout function for
success_url,cancel_url, andlocalhost. Build the origin from the live site’s public URL, or from the request host when that host is the published one. Do not leave the preview origin as the only value. - Redeploy, create a session, and read the URLs on the session in the Dashboard before you pay. They should be the published https origin.
- Treat the success page as a receipt the customer might see. Stripe’s fulfillment note says a customer can pay and never reach that page, so the unlock has to happen in the webhook or in a server read of the session. A page that only sets “paid” in the browser, and never writes it on the server, drops the purchase as soon as they close the tab.
A success URL on the wrong host is the same class of bug as an auth redirect left on the preview. On Lovable that shows up as login that works in preview and fails on the published URL. The checks are in My Lovable app stopped working.
Finish activation, and turn on the live payment methods
You can run the whole integration in a sandbox before Stripe has verified the business. Live mode is the point where that verification matters. Stripe’s account setup docs say a service works in live mode after you verify the business and complete the activation requirements. Until then, creating a live Checkout Session fails, and the same code still succeeds with test keys.
- Open the Dashboard with test mode off. Complete the banner Stripe shows: business details, the payout account, and any identity check. The request log from the failed session names the account problem. Fix that before you rotate keys again.
- Open Settings → Payment methods, still with test mode off. A method you tried in the sandbox can be off on the live account. If the session sets
payment_method_typesand one of those methods is not active, creating the session fails. Card still requires an activated account. - If a Manage subscription button errors only after go-live, activate the customer portal in the Dashboard with test mode off, then open it on the published URL. Lovable’s docs say the portal does not run inside the Lovable preview panel, so a preview test of that button answers a different question. Subscriptions also stay unchanged when the live webhook is missing the subscription events in the section above.
Read the Stripe logs, the event deliveries, and the function logs
Turn the test-mode toggle off before you read any of this. Sandbox logs and live logs are different lists. A healthy test delivery does not describe the live endpoint.
- From the Developers menu, open Workbench, then the Logs tab. Stripe documents this as the API request log, and older accounts still show it as Developers → Logs. Filter for the error status or for
/v1/checkout/sessions.resource_missingon the price parameter is the test price. An invalid API key is the wrong secret, or a secret from the other mode. If the failing click produced no row here, the request never reached Stripe. Go back to the browser network tab. - Open the Webhooks tab, select the live endpoint, and open Event deliveries. Stripe lists each attempt as Delivered, Pending, or Failed, with the HTTP status. No row, after a real live payment, means this endpoint is not subscribed to that event, or the endpoint itself exists only in test mode. A 400 is the handler rejecting the body. A 401 or 403 is the host refusing the call. A 404 means the path is wrong. A 500 means your code threw. Stripe retries a live delivery for up to three days. A sandbox delivery retries three times over a few hours.
- Read the function log for the same minute. On Lovable’s built-in backend that is More → Settings → Logs. On Supabase it is the Edge Function’s logs. On Vercel it is that deployment’s runtime log. On Replit it is the Publishing log. A 401 with an empty function log is the Supabase gateway, not a line you can find inside the function. A signature error in the log, next to a 400 in Event deliveries, is the
whsec_or the raw body.
Make one real low-value purchase and refund it
Test mode cannot prove the live path. The test card never charges a real network. After the keys, the price, the webhook, and the URLs are the live ones, and the new deployment is the one you are browsing, pay the smallest live price with your own card on the published URL.
- Use a private window on the customer domain. Complete checkout with a real card. You should land on the live success URL, and the app should show the paid state for that account.
- In Workbench, with test mode off, open the payment and the live endpoint’s Event deliveries. The event your handler uses to unlock access should show a 2xx. Then confirm the subscription or the one-time purchase is visible in the Dashboard, and that the app’s account matches it.
- Refund the payment from the Payments page in the Dashboard. If the purchase started a subscription, cancel that subscription as well so it does not renew. The refund confirms you can reverse the live charge. It does not, by itself, prove the app removes access. Removing access depends on the refund or cancellation event your handler actually processes.
How to catch it next time
The page customers load can return 200 for the entire time checkout is broken. A monitor that only fetches that URL stays green through a dead button, a test price id, a webhook that was never created in live mode, and a success URL that points at localhost.
- One low-value live purchase, after every key or price change. Private window, the published URL, your own card, then a refund. This is the check that sees the unlock. It is also the one that gets skipped when the last edit was a copy change on the pricing page.
- Stripe’s event deliveries, and the email it sends for a failing subscription webhook. The Event deliveries tab shows a 400, 401, or 500 for an endpoint that exists, and live mode retries for up to three days. On subscription invoices, Stripe’s billing docs say they email you when the endpoint keeps failing, and they hold the charge until they get a successful response or the finalization window passes. That email is about an endpoint Stripe is already calling. It does not arrive when the button never created a session, when the live endpoint was never registered, or when the customer paid and was sent to localhost. The payment can succeed with no email at all.
- An uptime monitor. It fetches a URL and tells you the status code. That is the right tool when the host is down or the homepage returns 500. A checkout button that does nothing, and a webhook that returns 400, both leave the marketing page on 200.
- An error tracker. It records exceptions your server or browser reports. A thrown error inside the checkout function can show up there. The Supabase gateway’s 401 never starts the function, so the tracker stays quiet. A missing live webhook sends no request to report. A click handler that returns early, or a popup the browser blocked, does not throw.
- A scheduled browser flow. Playwright, or any script you maintain, can open the live site, click checkout, and fail when the button is gone, the page shows a Stripe error, or the next URL is localhost or a preview host. You own the selectors. The next edit that renames the button fails the script until you update it. The walk does not enter a real card. Stopping on Stripe’s hosted payment page has not proved the webhook granted access.
- BreakAlarm. You describe signup, login, or checkout once. It re-walks those steps on a schedule and, on Starter and Pro, after a deploy hook, then emails a screenshot and a paste-ready fix prompt. Free checks one app every 24 hours. Starter is three apps, every hour, with a deploy hook. Pro is ten apps, every 15 minutes, with the hook and a Stripe lockout check. A green result only means the steps you wrote passed. A walk that stops when the payment page loads has not proved the app unlocked, and the check does not charge a card. The Pro Stripe check reads a restricted key and flags failed charges, events Stripe has not finished delivering, and an access URL you provide that returns hasAccess set to false. It does not read your webhook signing secret, and it does not replay the event. Use a flow check when the button or the page after checkout is what you are afraid of shipping broken. Use a plain uptime check when you only care that a URL answers.
The limits are the ones on the pricing section. What is BreakAlarm is the same description, including who it is for. The same preview-versus-published failure on Lovable is in My Lovable app stopped working, on Bolt in Bolt app sign-up works in preview but breaks after deploy, and on Replit in Replit app works in preview but breaks after publish. Other write-ups are on Guides. The homepage runs one check of a public URL you are allowed to test. It does not start the schedule, and it does not complete a card payment.
FAQ
Why does Stripe checkout work in test mode and fail after I go live?
Test mode and live mode do not share keys, prices, customers, or webhook endpoints. The preview can still hold pk_test_ and sk_test_, a price_ id created in the sandbox, and a webhook that exists only while the Dashboard test-mode toggle is on. Switching one of those and leaving the others in test mode is enough to break checkout, or to take the money and never unlock the app. Compare prefixes, then the price id, then the live endpoint, with the test-mode toggle off.
I saved the live keys. Why does the deployed app still use the test key?
The running deployment keeps the values it was built with. Vercel applies an environment-variable change only to a new deployment. Next.js inlines NEXT_PUBLIC_ values into the browser bundle at build time, and Vite does the same for VITE_ values. Saving the key in the dashboard does not rewrite the site that is already live. Redeploy, then search the published page for pk_live_. On Replit, the published app reads Production app secrets, so a workspace secret is not enough until you publish again.
The customer paid, but the app still says they are on the free plan. What failed?
The charge and the unlock are different steps. Stripe's checkout guide says you cannot fulfill an order only from the success page, because the customer may never reach it. The app unlocks from a webhook, or from a server call that reads the Checkout Session or the subscription. If the live endpoint was never created, Stripe has no delivery to show and no failure email for that event. If the signing secret is still the test whsec_, the delivery is a 400 and the handler returns before it grants access. On Lovable's own-Stripe integration, the default setup does not use webhooks: it asks Stripe whether the subscription is active and matches it by email. A live payment whose email does not match the login email stays locked.
The webhook delivery is 401 and the function logs are empty. Why?
Supabase Edge Functions verify a JWT before your code runs, unless you turn that check off for the function. Stripe does not send a Supabase JWT, so the gateway responds 401 with a missing or invalid authorization header and the function never starts. That 401 is not a bad whsec_. Set verify_jwt to false for the webhook function, or deploy it with --no-verify-jwt, then verify the Stripe-Signature header inside the function and return 400 when the signature does not match. Leave JWT verification on for functions your users call.
Checkout opens in test mode, and the button does nothing on the live site. Where do I look?
Open the browser console and the network tab on the published URL. No request means the click handler threw before fetch, often because the publishable key was empty at build time, or a popup blocker stopped a checkout that opens in a new tab. Lovable's own integration opens Checkout in a new tab. A request that returns 500 with No such price is a test price id sent with a live key. A card decline of 4242 4242 4242 4242 on a live key is expected: that card only works in test mode.
Will an uptime monitor catch a checkout that works in test and fails live?
An uptime check tells you the URL responded. The pricing page can return 200 while the button does nothing, the success URL is localhost, or a paid customer never gets access. Stripe's event deliveries show a webhook that was attempted and failed. They stay empty when the live endpoint was never created. A flow check that clicks checkout can catch the dead button and a redirect to the wrong host. It does not charge a card, so it does not prove the webhook unlocked the app. Prove that with one small live purchase, then refund it.
References
- Stripe: API keys. Test and live keys, and objects in one mode that the other mode cannot use.
- Stripe: Go-live checklist. Sandbox products are not usable in live mode, and live webhook endpoints have to be registered on their own.
- Stripe: Receive events. The
whsec_signing secret, signature verification, Event deliveries, and live retries for up to three days. - Stripe: Customize the success page. Fulfill from a webhook, because the customer is not guaranteed to reach
success_url. - Stripe: Using webhooks with subscriptions. The email Stripe sends when a subscription webhook keeps failing, and the hold on the charge until the endpoint responds.
- Stripe: Set up your account. A sandbox works before activation. Live mode needs the business verification.
- Stripe: Workbench. Developers menu, then Logs and Webhooks, including event deliveries.
- Vercel: Environment variables. A change applies to new deployments. The current deployment keeps the values it was built with.
- Next.js: Environment variables.
NEXT_PUBLIC_values are inlined into the browser bundle at build time. - Vite: Env variables and modes.
VITE_values are exposed in the client bundle and statically replaced at build time. - Supabase: Function configuration.
verify_jwt = falsefor a Stripe webhook, because Stripe does not send a user JWT. - Lovable: Connect your own Stripe account. Live key, live price ids, a real purchase, and webhooks you register yourself when you ask for them.
Stripe, Lovable, Bolt, Replit, v0, Vercel, Supabase, and Netlify are trademarks of their owners. BreakAlarm is not affiliated with them.