Why AI-built apps charge customers twice

Direct answer

Because the generated payment code assumes every request and every webhook arrives exactly once. In production, users double-click, clients retry, two people book the same slot in the same second, and Stripe redelivers events by design. Without a database constraint, a stored event ID or an idempotency key, each repeat becomes a second booking, charge, credit or refund. The fix is to make the database refuse duplicates, and to acknowledge a webhook only after its work is safely recorded.

Why payment code breaks after launch

A checkout flow built with an AI coding tool is tested by clicking through it once with a test card. That proves the happy path. It says nothing about the same request arriving twice, two requests arriving together, or a database write failing after the payment succeeded.

In the production issues we reviewed across about 25 projects in October, payments, webhooks and billing idempotency problems appeared in six. They are rarer than authorization gaps, but every one touches money.

What we found and fixed

  • A booking marketplace for creative freelancers could create two payment intents for one deposit when a user double-clicked or a request was retried. (Its double-booking race is covered in our article on race conditions.) Unique indexes now allow one active deposit and one active balance payment per booking. If the constraint fires, the orphaned payment intent is cancelled.
  • Its webhook handler acted on every delivery. It now records each event ID in a processed-events table before acting, and skips any event it has already handled.
  • A fitness coaching marketplace topped up session credits whenever a subscription renewal invoice was paid. A redelivered event would have added the credits twice. The handler now stores the last processed invoice per package and skips a repeat. Its payment endpoint also returns the existing pending payment intent instead of creating another, and refuses to create one for a session that is already paid.
  • An audit of an AI chat product that bills usage against a credit balance found that a credit reservation could be refunded in full after part of it had already been settled, if a later step in the same request failed. Settlement and refunds were made transactional and tied to the request, and a follow-up review supported the fix in testing.

What Stripe tells you to expect

None of this is unusual behavior from Stripe. Stripe’s webhook documentation says endpoints might occasionally receive the same event more than once, and recommends logging the event IDs you have processed and skipping ones already logged. It says Stripe doesn’t guarantee events arrive in the order they were generated. In live mode, Stripe retries undelivered events for up to three days with exponential backoff, and a non-2xx reply from your endpoint is one reason it retries.

The same page tells you to return a 2xx quickly, before complex logic that could time out. A common mistake in generated handlers is to catch a failed database write, log it and return 200 anyway, so Stripe treats the event as delivered and never retries it. A 200 should mean “recorded.” Store the event durably first, return 2xx, then process it from your own queue. If you cannot store it, return an error so Stripe tries again.

For calls you make to Stripe, Stripe’s idempotent requests reference explains that sending an Idempotency-Key header lets you retry after a connection error without creating a second object or performing the update twice. Stripe compares the parameters of a repeated key with the original and returns an error if they differ, and keys can be pruned once they are 24 hours old. Derive the key from your own record, such as the booking and payment type, so a retry from a second tab reuses it.

How to fix it: a short checklist

  1. Put uniqueness in the database. One active payment per booking, one booking per slot, one processed row per event ID. Application checks alone lose races.
  2. Send an idempotency key on every Stripe write. Base it on your own record, never on a timestamp.
  3. Store event IDs before acting. Skip any event you have already processed, and handle events arriving out of order.
  4. Return 200 only after the event is recorded. A swallowed error plus a 200 tells Stripe to stop retrying.
  5. Make refunds and credits idempotent too. Track what each request has settled, so recovery code cannot refund it twice.
  6. Test the repeats. Double-click, replay a webhook from the dashboard, and fail the database write on purpose.

If the payment succeeds but the account does not update, our guide to Stripe payments that never grant access covers that failure. For retries inside AI agents and multi-step workflows, see why AI agents need idempotency.

Related Zenveus services: Stripe webhook signature fix guide, AI Prototype Hardening and the 48-Hour Verdict

Scroll to Top

Optional tracking stays off until you enable it. You can change your choice at any time.

Essential — always active
Security, requested features, and remembering these choices.

Read our cookie policy