LogicTrail
  • Trails
  • Check my app
  • Pricing
  • Sign in
  1. Trails
  2. /
  3. The life of a click
  4. · 5 minutes · Pro

The double order

A customer on slow hotel wifi taps Pay twice. They are charged twice and get two orders.

This answers: How do I stop duplicate orders from double clicks? No coding needed. 3 quick decisions.

  • How a request travels
  • Payments and webhooks
  • Where your data lives

Checking your access…

How do I stop duplicate orders from double clicks?

Give each purchase intent an and store it with a unique constraint in the database. When the same key arrives again, return the first result instead of creating a second order. Disabling the button helps, but retries, refreshes and second tabs still send duplicates.

Trail of the bug
  1. Browser
  2. Your server
  3. Stripe

Breaks at Your server: Two taps become two orders

How it works

One payment, two deliveriesRemember event ids
  1. 0sStripeSends evt_1Q8: 'checkout completed'
  2. 0–31sYour serverAdds one month of credits… but replies slowly
  3. 31sStripeNo reply in time, so it sends evt_1Q8 again
  4. 31sYour serverAdds a second month of credits
Without a record of event ids, the server treats the retry as a new payment and adds a second month.

Why AI tools write this bug

Generated checkout code usually creates an order on every request. Duplicate handling is invisible in testing, because you only click once.

How to fix it

  1. Generate one per purchase attempt on the client.

3 more steps, and a prompt that checks your own app for this bug. Part of Pro.

Unlock

Common questions

What does idempotent mean?
Doing the operation twice has the same effect as doing it once.

Related scenarios

  • One field, a million creditsPro · 4 min
  • The webhook that arrived twicePro · 5 min
  • Cancelled on day 3Pro · 4 min

More on this trail

The life of a click: Follow one button press from the browser to the database and back.

Want someone to look?

We check AI-built apps for this and three other common leaks, in plain English.

Check my app
Sign in

Sign in to walk this one

3 decisions, about 5 minutes, and a prompt to check your own app for the same problem.

Sign in No password. We email you a link.

How to fix it

  1. Generate one per purchase attempt on the client.

3 more steps, and a prompt that checks your own app for this bug. Part of Pro.

Unlock