Break a Cursor debug loop
Reproduce first, test one hypothesis, and stop after two failed attempts, so the agent cannot silently rewrite the file again.
A user who only visits your success URL should not get the paid thing. If they can, you do not have payments. You have a hidden button labelled “pay.”
24 November 2026 · About a 9 minute read
This is the failure I see most often in a first Stripe integration, especially one an agent has just generated. The app creates a Checkout Session, sends the customer to Stripe, then marks the order as paid when they land on /success, or when the page sees ?paid=1, or when the browser posts “payment succeeded.” None of those are proof that money moved.
I walked a throwaway demo through this. In the broken version, visiting /success?paid=1 marked the order paid, and a webhook with a junk signature still fulfilled. In the fixed version those cheats were refused, a verified checkout.session.completed event granted access once, and delivering the same event again did nothing the second time.
For a first version, hosted Stripe Checkout is simpler and safer than a custom card form. This is not tax advice, a marketplace guide, or a full subscriptions billing setup. If you already sell only through Payhip or a similar merchant, you may not need this at all.
Create the Checkout Session on the server, with the price defined on the server, not an amount the browser posts. After payment, fulfil in the webhook for checkout.session.completed, after signature verification, and make that fulfilment idempotent on the event id or session id. The success URL is a receipt page only. It must not grant access.
Before you let the agent “add Stripe,” make it tell you what the app already trusts.
Do not edit files and do not print secret key values. How does a payment currently work? I want: where a Checkout Session or charge is created, where we mark a user or order as paid, and whether that mark can be set by visiting a URL, posting from the client, or only by a verified webhook. If we trust ?paid= or a success page, say that plainly.
If the answer is “we trust the success page,” the app is not taking payments safely yet. Say that out loud. Then agree the v1 design before anyone types code.
v1: Stripe Checkout, one product, price defined on the server (not an amount from the browser). After payment, [what the user gets]. Fulfilment happens in the webhook for checkout.session.completed, after signature verification, and is idempotent on event id or session id. Success URL is a receipt page only, it must not grant access. Propose a short file list. Wait for my yes.
Implement what we agreed, using environment variable names (not real keys) for STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET, and the publishable key. Add .env.example placeholders. Give me the exact local steps to run the webhook listener (for example the Stripe CLI) and to complete a test payment. Do not switch on live keys.
The publishable pk_ key is the only key that may go to the client. sk_test_, sk_live_ and whsec_ are server-only. If you want the longer version of that, see how secret keys leak into the client app.
In Next.js, the webhook route must receive the raw request body for signature verification. Parsing JSON first will break signatures, and the usual “fix” is to disable verification. Do not do that.
This is the part most generated checkout tutorials skip. Run these checks in test mode, and fix only if they fail.
Run or spell out these checks, and fix only if they fail:
1. Visiting the success URL, or ?paid=1, or pasting a session id I did not pay for, does not grant the paid thing. 2. A webhook post with a junk signature is rejected. 3. Delivering the same valid event twice grants the paid thing only once. 4. The amount or product cannot be lowered by a client POST.
Report pass/fail for each.
The done-when test I care about most is number 1: you (or the agent) tried to cheat with the success URL and were refused. A genuine test-mode Checkout payment, with a verified webhook, should then grant access, once.
session_id on the success URL is useful to display a receipt after you retrieve the session on the server and confirm payment_status is paid. That is a display path. The webhook remains the system of record for granting the goods. Do not “fix” a missing local webhook by fulfilling on the success page. If the event never arrives, use the Stripe CLI or a tunnel until it does.
Write a short go-live list in the repo (for example docs/stripe-go-live.md): switch to live keys in the host’s env, set the live webhook endpoint and new whsec_, fulfil the same way, and a reminder to do one real £[small] purchase myself. Do not put real keys in the file. Do not enable live mode yourself.
Do not point a live webhook at a test key, or the reverse, and then “fix” it by disabling verification. Subscriptions need additional events (invoice.paid, cancellation). Do not pretend a one-shot Checkout playbook covers the whole subscription life cycle. This also does not set up Stripe Tax or UK VAT for you; check Stripe’s and GOV.UK’s own documentation.
The free Debug Loop Breaker sample on GitHub has the Cursor rule, the AGENTS.md section, and the full prompt sequence you can paste into a new chat. The Vibe Launch Pack (£12) adds 15 more playbooks, including the Stripe and secrets checks described in these guides.
Reproduce first, test one hypothesis, and stop after two failed attempts, so the agent cannot silently rewrite the file again.
Public-prefixed env vars are baked into the JavaScript users download. Here is how that happens, and how to search the bundle before you deploy.