Stripe in a Vibe-Coded App: Webhooks, Idempotency and the Test-Mode Trap
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.
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
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.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.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.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
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.subscription.deleted — not on the cancel click.charge.refunded and charge.dispute.created. Access should follow the money. Refunds, chargebacks and entitlement revocation covers the logic in detail.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
checkout.session.completed, not on the success page.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.
