afterbuild/ops
ERR-512/stack trace
ERR-512
Lovable Stripe integration broken? Webhook and checkout fixes

Lovable Stripe integration broken? Webhook and checkout fixes

Last updated 4 November 2026 · 11 min read · By Hyder Shah
Direct answer

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?

Start here

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?

  1. 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 with req.text() and use constructEventAsyncwith 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_id when 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 set verify_jwt = false for this one function in supabase/config.toml; the signature check is what authenticates the request.

  2. 03

    Fix 3 — Handle every subscription lifecycle event

    On checkout.session.completed: upsert subscription_status = ‘active’. On customer.subscription.updated: mirror the new status (past_due, canceled, active). On customer.subscription.deleted: set ‘canceled’. Read subscription_status from your app, not Stripe directly.

  3. 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.id into a stripe_events_seen table with primary key on event_id. If the insert fails, it’s a duplicate — return 200 and skip.

  4. 05

    Fix 5 — Test end-to-end with Stripe CLI

    With test-mode keys, run stripe trigger checkout.session.completed and 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.

Tried the fix and still broken?

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.”
Reddit — r/boltnew

Diagnose Lovable Stripe integration broken by failure mode

Match your symptom to the fix below.

SymptomRoot causeFix
Checkout opens, payment succeeds, plan never activatesWebhook not hitting prod URLFix #1
Webhook logs show 400 signature verification failedBody parsed before Stripe could verify itFix #2
Subscription cancels but app still shows ProNot handling customer.subscription.deletedFix #3
Same webhook processed twice, user got 2 monthsNo idempotency guardFix #4
Stripe event deliveries show 401 from the Edge FunctionFunction still requires a Supabase JWT; Stripe has noneSet verify_jwt = false for the webhook function only
Real charges while testing in the Lovable previewA live key is connected; the preview has no separate test environmentConnect an rk_test_ or sk_test_ key until launch
Payments still use test mode after launchTest key or test price IDs left in placeSubmit a live key and switch to live price IDs
Checkout button does nothingCheckout opens in a new tab and a popup blocker stopped itAllow popups, or open checkout from a direct click
Customer portal fails in the previewThe portal does not run in the preview panel and must be activated once in StripeActivate it in the Stripe dashboard and test on the deployed URL

Still stuck with Lovable Stripe integration broken?

Emergency triage · $299 · 48h turnaround
We restore service and write the root-cause report.

Stripe is where Lovable most often costs you real money. Get it right once.

start the triage →

Lovable Stripe integration broken questions

How do I add Stripe to Lovable?+
Ask Lovable in the project chat for Stripe payments with your own account. It shows a Connect Stripe form: create a restricted key (rk_...) in Stripe with only the permissions you need and paste it there, never into the chat. Lovable stores it as the STRIPE_SECRET_KEY backend secret and builds checkout as Supabase Edge Functions. Start with a test key, then switch to a live key and live price IDs at launch.
Why does my Lovable Stripe checkout succeed but the subscription never activates?+
Your webhook isn't reaching production. Either Stripe is still pointed at your preview URL, the endpoint doesn't exist in production, or the webhook is failing signature verification (which shows as 400 in Stripe's event deliveries). Open Stripe Workbench → Webhooks → your endpoint → Event deliveries. Every failed delivery shows the exact response code and error.
Why are my Stripe webhooks failing on Lovable?+
Check the status code in Stripe's event deliveries. A 400 usually means signature verification failed because the function parsed the body before verifying it: read it with req.text() and pass it to stripe.webhooks.constructEventAsync with Stripe.createSubtleCryptoProvider(). A 401 means the Edge Function still requires a Supabase JWT, which Stripe never sends: set verify_jwt = false for the webhook function only. A 404 means the endpoint URL is wrong or the function is not deployed.
How do I handle subscriptions in Lovable?+
By default Lovable checks subscription status with Stripe directly and matches subscriptions to users by email. If your app needs the plan in its own database, add a webhook that handles checkout.session.completed, customer.subscription.updated and customer.subscription.deleted, writes the status to a subscriptions table, and have the app read that table.
Is it safe to put Stripe keys in Lovable?+
Yes, through the Connect Stripe form. Lovable stores the key as a backend secret that never appears in your app code or repository, and its docs warn never to paste a Stripe key into the project chat. Use a restricted key with only the permissions you need, never a publishable key, and keep the webhook signing secret and Supabase service-role key in Edge Function secrets too.
Do I need to handle every Stripe webhook event?+
No, but you need four: checkout.session.completed (activate subscription), customer.subscription.updated (handle status changes like past_due), customer.subscription.deleted (deactivate), and invoice.paid (confirm recurring billing). Missing customer.subscription.deleted is a common cause of 'they canceled but still have Pro' complaints.
How do I test Stripe webhooks on Lovable without making real payments?+
Use test-mode keys and the Stripe CLI. Run 'stripe trigger checkout.session.completed' and check the delivery under Workbench → Webhooks → Event deliveries, then pay with test card 4242 4242 4242 4242. No money moves. Watch your database flip, and confirm idempotency by resending the same event.
How much does it cost to have someone fix Stripe in a Lovable app?+
Our Integration Fix is $799 fixed price for one integration, delivered in 3–5 days. For Stripe that covers the webhook handler with signature verification and idempotency, the subscription lifecycle events, and webhook replay tests with the Stripe CLI.
Next step

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.

About the author

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.

Sources