Vibe Coding Rescue

Stripe in a Vibe-Coded App: Webhooks, Idempotency and the Test-Mode Trap

8 min read | Updated September 2026

Payments are where a vibe-coded app stops being an experiment. The AI can wire Stripe Checkout in one prompt and the first test payment goes through beautifully — which hides the fact that the parts that keep money and access in sync were never built. Here are the five things we check on every AI-built Stripe integration, and the one test that finds most of them.

The one test

Make a test purchase, then in the Stripe dashboard cancel the subscription (or refund the payment). Wait a minute. Log in to your app. If you still have access, your app is trusting the checkout redirect and ignoring what Stripe says afterwards — which means cancelled users keep everything and you’ll find out from the bank, not the app.

1. The redirect is not the receipt

The most common AI pattern: Checkout completes, Stripe redirects to /success, and the success page marks the user as paid. Anyone can type /success into the address bar. Even honest users hit it twice, or close the tab before it loads, and end up either double-provisioned or unpaid-but-charged.

The fix: access is granted only when your server receives and verifies a Stripe webhook (checkout.session.completed, then customer.subscription.updated/deleted, invoice.payment_failed). The success page just says “thanks, setting up your account” and polls or refreshes. Stripe is the source of truth; your database mirrors it.

2. Webhooks: verify, then make them idempotent

1
The signature is checked
Every webhook handler must verify Stripe-Signature with your endpoint’s signing secret. Without it, anyone can POST “payment succeeded” to your endpoint and grant themselves a plan. AI-generated handlers skip this surprisingly often — or verify it in development and lose it in the “make it work on Vercel” step because the raw body wasn’t available.
2
Duplicates are harmless
Stripe retries webhooks and can deliver the same event twice. Store the event.id and skip ones you’ve seen; make every update “set status to X” rather than “increment credits by 10.” The webhook architecture we use for RevenueCat applies word for word.
3
Out-of-order events don’t flip state backwards
A subscription.updated from a minute ago can arrive after the subscription.deleted from now. Compare timestamps or re-fetch the subscription from Stripe’s API before writing, instead of trusting the event payload alone.
4
Failures are visible
A handler that throws returns 500, Stripe retries for days, and nobody notices the customer who paid and got nothing. Log every event, alert on handler errors, and look at Stripe’s webhook delivery dashboard once a week until you trust it.

3. The test-mode trap

There are two independent Stripe environments with two sets of keys, two webhook secrets, two sets of products and prices. AI-built apps routinely ship with one of these mixed up: live publishable key with a test secret key (checkout fails cryptically), test price IDs in production (checkout works, no money arrives), or the test webhook secret on the live endpoint (every real event fails signature verification, silently). Check all four — publishable key, secret key, webhook secret, price IDs — per environment, and keep them in environment variables per deployment, never in code. If any key ever landed in the repo, rotate it.

4. Entitlements live in your database, not in the session

Storing “isPro: true” in a JWT or local storage at checkout time means it never changes when the subscription does. The plan should be a column on the user (or a subscriptions table keyed on Stripe’s customer and subscription IDs), written only by the webhook handler, read on every request that gates a feature. And that column must not be client-writable — see Supabase RLS or Firebase rules for the pattern; a user who can update their own plan field doesn’t need to pay.

5. The states nobody demoed

Failed renewal
Card expires, invoice.payment_failed fires, Stripe retries per your dunning settings. Decide: grace period or immediate downgrade? Then handle customer.subscription.updated with status past_due.
Cancel at period end
The user cancels but keeps access until the period ends. Your app needs to show “cancels on [date]” and only revoke on subscription.deleted — not on the cancel click.
Refunds and disputes
charge.refunded and charge.dispute.created. Access should follow the money. Refunds, chargebacks and entitlement revocation covers the logic in detail.
Plan changes
Upgrade mid-cycle with proration, downgrade at period end. Use Stripe’s Customer Portal for this rather than building it — the AI will try to build it, and it will get proration wrong.

Do this before taking real money

Run the one test at the top, then work down the list. Use Stripe’s CLI (stripe listen and stripe trigger) to fire every event type at your local handler and watch what your database does. Read the security checklist for the rest of the app — the payments flow is only as safe as the login and authorisation around it. And if any of this is unfamiliar, this is the one part of a vibe-coded app where an engineer’s review pays for itself the first month: a payments bug costs real money in both directions.

FAQ

Can I use Stripe Checkout and Customer Portal instead of building UI?
Yes — and you should. They handle cards, taxes, 3-D Secure, plan changes and cancellations. Your job reduces to the webhook handler and the entitlement column, which is exactly the part this article is about.
Do I need webhooks if I only sell one-time purchases?
Yes. The redirect problem is the same: fulfilment must happen on checkout.session.completed, not on the success page.
What about Lemon Squeezy, Paddle or RevenueCat?
Same principles: verify the webhook, make it idempotent, let the provider be the source of truth. For mobile subscriptions, our RevenueCat guides cover the store-specific versions of every state above.
My test payment worked. Isn’t that enough?
A test payment proves checkout works. It says nothing about cancellation, failed renewal, refunds, duplicates or forged events — which is where the money leaks. Run the one test at the top.

Taking real money soon?

Payments review for AI-built apps: we test every Stripe state against your handler, fix the entitlement sync, and confirm the live keys before your first real customer.

Book a Payments Review →

Engineering Insights

Latest from Syntaxa Studio.

Loading latest posts