Lovable Stripe integration broken? Webhook and checkout fixes
Lovable Stripe integration broken? Webhook and checkout fixes
Scope of this page:Lovable-specific Stripe issues — Supabase Edge Functions, Deno runtime, Lovable preview URLs. For the tool-agnostic error-signature fix see Stripe webhook not firing. For a pre-flight checklist see Stripe integration checklist for Lovable. Shopping for a paid engagement? Add payments to AI app.
Lovable’s Stripe connector stores your key as a backend secret and builds checkout as Supabase Edge Functions; by default the app asks Stripe for payment status directly and uses no webhooks. Once you add a webhook to sync plans into Supabase, four breaks show up again and again: webhook URL still pointing at preview, signature validation failing on the raw body, checkout.session.completed ignored, and subscription state never written to Supabase. Each fix is below, with a working Edge Function.
How do I fix Lovable Stripe integration broken?
Fix 1 — Add a production webhook endpoint
In Stripe Workbench open Webhooks → Create an event destination and enter the public URL of your deployed webhook Edge Function (Supabase lists it under Edge Functions), not a preview URL. Choose the Snapshot payload, since the handler below reads event.data.object. Subscribe to checkout.session.completed, invoice.paid, customer.subscription.updated, and customer.subscription.deleted. Copy the new signing secret into your production STRIPE_WEBHOOK_SECRET env var. Remove any leftover preview endpoint.
Not a developer? We fix this for you at a fixed price: $299 emergency triage, done in 48 hours or fully refunded. Not sure what else is broken? Send the repo for the $49 audit.
What if the quick fix doesn't work?
- 02
Fix 2 — Verify with the raw body
Stripe signs the raw bytes. If the function calls
req.json()first, verification fails. Lovable webhooks run as Supabase Edge Functions on Deno, so read the body withreq.text()and useconstructEventAsyncwith Stripe’s Web Crypto provider, as Supabase’s own example does. This version also records each event id (Fix 4) and writes the plan to Supabase (Fix 3):// supabase/functions/stripe-webhook/index.ts import Stripe from "npm:stripe@^22"; import { createClient } from "npm:@supabase/supabase-js@2"; const stripe = new Stripe(Deno.env.get("STRIPE_SECRET_KEY")!); const cryptoProvider = Stripe.createSubtleCryptoProvider(); const supabase = createClient( Deno.env.get("SUPABASE_URL")!, Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!, ); Deno.serve(async (req) => { const signature = req.headers.get("Stripe-Signature"); const body = await req.text(); // raw body, never req.json() first let event: Stripe.Event; try { event = await stripe.webhooks.constructEventAsync( body, signature!, Deno.env.get("STRIPE_WEBHOOK_SECRET")!, undefined, cryptoProvider, ); } catch (err) { return new Response((err as Error).message, { status: 400 }); } // Idempotency: event_id is the primary key, so a repeat fails with 23505. const seen = await supabase .from("stripe_events_seen").insert({ event_id: event.id }); if (seen.error?.code === "23505") return Response.json({ duplicate: true }); if (seen.error) return new Response("db error", { status: 500 }); let write; switch (event.type) { case "checkout.session.completed": { const s = event.data.object; write = await supabase.from("subscriptions").upsert( { user_id: s.client_reference_id, stripe_customer_id: s.customer, status: "active" }, { onConflict: "user_id" }, ); break; } case "customer.subscription.updated": case "customer.subscription.deleted": { const sub = event.data.object; write = await supabase.from("subscriptions") .update({ status: sub.status }) .eq("stripe_customer_id", sub.customer); break; } } if (write?.error) { // Let Stripe retry: forget the event id and return a non-2xx. await supabase.from("stripe_events_seen").delete().eq("event_id", event.id); return new Response("db error", { status: 500 }); } return Response.json({ received: true }); });Pass the signed-in user’s id as
client_reference_idwhen the checkout session is created, or the upsert has no user to attach the plan to. Supabase Edge Functions require a JWT by default and Stripe does not send one, so setverify_jwt = falsefor this one function insupabase/config.toml; the signature check is what authenticates the request. - 03
Fix 3 — Handle every subscription lifecycle event
On
checkout.session.completed: upsertsubscription_status = ‘active’. Oncustomer.subscription.updated: mirror the new status (past_due,canceled,active). Oncustomer.subscription.deleted: set‘canceled’. Read subscription_status from your app, not Stripe directly. - 04
Fix 4 — Add idempotency
In live mode Stripe retries an undelivered event for up to three days, and an endpoint can receive the same event more than once. Insert the
event.idinto astripe_events_seentable withprimary keyonevent_id. If the insert fails, it’s a duplicate — return 200 and skip. - 05
Fix 5 — Test end-to-end with Stripe CLI
With test-mode keys, run
stripe trigger checkout.session.completedand check the delivery in Workbench → Webhooks → Event deliveries. Confirm the database row flipped to active. Cancel the test subscription and confirm it flipped back. Then run a real checkout with the test cards below.
Before you start: test mode and keys
Lovable’s Connect Stripe form takes a restricted key (rk_...) with only the permissions your app needs; a secret key (sk_...) also works, a publishable key (pk_...) does not. Paste it into the form, never into the project chat. Lovable saves it as the backend secret STRIPE_SECRET_KEY, so it never lands in your code or repo. The preview has no separate test environment: connect an rk_test_ or sk_test_ key while you build, because with a live key every preview payment is real.
How Lovable connects Stripe, and where webhooks come in
Ask Lovable in chat for Stripe payments with your own account and it builds checkout and subscription logic as Edge Functions that call Stripe with the stored key. By default the app checks payment and subscription status with Stripe directly and matches subscriptions to users by email address. That works until you need your own database to know who paid: gating rows with RLS, fulfilling orders, or reacting to a failed renewal. That is when you ask Lovable to write the webhook function above and add its signing secret. If your project still runs on Lovable’s built-in backend, read how to connect your own Supabase project to Lovable first, since the webhook writes into those tables.
Stripe test-card checklist
Use test-mode keys, any future expiry (such as 12/34) and any three-digit CVC. Run each card through checkout and confirm what your app shows afterwards:
4242 4242 4242 4242: payment succeeds, the plan activates and the webhook delivery shows 200.4000 0000 0000 0002: generic decline, the plan stays locked and the user sees an error.4000 0000 0000 9995: insufficient funds, same expectation as the generic decline.4000 0027 6000 3184: 3D Secure on every payment, the plan activates only after the challenge is completed.- Cancel the test subscription in Stripe: the app drops back to the free plan.
- Resend one delivered event from Stripe: the row does not change a second time.
After payments work: the rest of the production pass
Payments are one seam in a Lovable app; auth redirects, RLS and environment variables tend to break in the same deploy. If you are planning the whole move, see taking a Lovable prototype to production. Before launch, run the webhook function and its service-role key through the security checklist for AI-generated code, since that function can write to any table.
Lovable, Stripe and Supabase behavior checked 4 November 2026 against the documentation listed under Sources.
Send your app URL. A senior engineer records a 10-minute teardown.
Free, and fully async — no call to book. A senior engineer walks your app on video: what’s broken, what’s risky, what to fix first. In your inbox within 24 hours. Want the code read line by line instead? Send the repo for the $49 audit.
Why do AI-built apps hit Lovable Stripe integration broken?
Lovable generates the easy half of Stripe: a checkout-session create call. It usually skips the hard half: webhook verification, idempotency, raw-body preservation, and writing subscription state into your database so your app can read it later.
The result is a checkout that takes money, followed by an app that still shows “Upgrade” because nobody told the database the user paid.
“I have tried 4 times and it is still broken.”
Diagnose Lovable Stripe integration broken by failure mode
Match your symptom to the fix below.
| Symptom | Root cause | Fix |
|---|---|---|
| Checkout opens, payment succeeds, plan never activates | Webhook not hitting prod URL | Fix #1 |
| Webhook logs show 400 signature verification failed | Body parsed before Stripe could verify it | Fix #2 |
| Subscription cancels but app still shows Pro | Not handling customer.subscription.deleted | Fix #3 |
| Same webhook processed twice, user got 2 months | No idempotency guard | Fix #4 |
| Stripe event deliveries show 401 from the Edge Function | Function still requires a Supabase JWT; Stripe has none | Set verify_jwt = false for the webhook function only |
| Real charges while testing in the Lovable preview | A live key is connected; the preview has no separate test environment | Connect an rk_test_ or sk_test_ key until launch |
| Payments still use test mode after launch | Test key or test price IDs left in place | Submit a live key and switch to live price IDs |
| Checkout button does nothing | Checkout opens in a new tab and a popup blocker stopped it | Allow popups, or open checkout from a direct click |
| Customer portal fails in the preview | The portal does not run in the preview panel and must be activated once in Stripe | Activate it in the Stripe dashboard and test on the deployed URL |
Related errors we fix
Still stuck with Lovable Stripe integration broken?
Stripe is where Lovable most often costs you real money. Get it right once.
Lovable Stripe integration broken questions
How do I add Stripe to Lovable?+
Why does my Lovable Stripe checkout succeed but the subscription never activates?+
Why are my Stripe webhooks failing on Lovable?+
How do I handle subscriptions in Lovable?+
Is it safe to put Stripe keys in Lovable?+
Do I need to handle every Stripe webhook event?+
How do I test Stripe webhooks on Lovable without making real payments?+
How much does it cost to have someone fix Stripe in a Lovable app?+
Ship the fix. Keep the fix.
Emergency Triage restores service in 48 hours. Break the Fix Loop rebuilds CI so this error cannot ship again.
Hyder Shah leads Afterbuild Labs, shipping production rescues for apps built in Lovable, Bolt.new, Cursor, Replit, v0, and Base44. our rescue methodology.
Lovable Stripe integration broken experts
If this problem keeps coming back, you probably need ongoing expertise in the underlying stack.