Idempotent Payment Retries: A Build Checklist to Avoid Double Charges

A customer taps Pay, the request times out, and your app retries. Did the first attempt succeed? If your server can't answer that, you risk charging twice or losing the sale. This guide walks technical founders and backend engineers through a retry-safe payment design: mapping intent states, binding idempotency keys to a cart or session, reusing an intent across an interrupted checkout, and treating webhooks as the record of truth. You will finish with a short pre-launch checklist covering what to log, alert on, and test before you ship.

Why retries cause double charges: the gap between client intent and server state

In the hypothetical Orbit Cart example, the customer clicks confirm once, but the browser sends three confirm attempts for cart_9f2 and sess_44a. The gap is simple: the client knows only that its request timed out after eight seconds. It does not know whether the server created a charge, is still processing, or rejected the attempt. Retrying without a shared reference can turn one customer intent into several payment attempts.

The Payment Intents API is designed to track a payment from creation through checkout and to trigger additional authentication steps when required (Stripe documentation). A typical integration creates and confirms a PaymentIntent, and each intent usually maps to a single shopping cart or customer session (Stripe documentation). That mapping is the practical bridge between client intent and server state.

Proposed decision exercise: before enabling retries, write down what identifier the client sends on attempt two and attempt three. If the answer is "nothing" or "a new value each time," the server cannot reliably connect the retries to the original attempt. If the answer is cart_9f2 or sess_44a, you have a candidate reference to reuse.

Attempt Client sees Server may know
First confirm Timeout after 8s Intent created or processing
Retry one No response Same reference or duplicate
Retry two No response Same reference or duplicate

Next, define how that reference is stored and reused before any retry logic ships.

The payment intent lifecycle as a retry-safe state machine

Treat the intent as a small state machine, not a fire-and-forget call. In the Orbit Cart example, the first confirm for cart_9f2 and sess_44a times out after eight seconds, so the client cannot tell whether the intent was created, is processing, or failed. The Payment Intents API is designed to track a payment from creation through checkout and to trigger extra authentication steps when required, which gives retries a stable object to point at rather than a fresh charge (Stripe).

A typical integration creates and confirms an intent, and each intent usually maps to one cart or customer session (Stripe). That mapping is the retry rule: attempts two and three should reuse the intent tied to sess_44a, not create another.

Proposed exercise — sketch the transitions and the client action for each:

Observed state Client action
No intent recorded Create once, store reference
Intent exists, not confirmed Confirm same intent
Processing / requires action Wait or complete authentication
Succeeded Stop; show confirmation

Because the annual plan recurs, note that subscriptions move through a predictable set of states and need stored customer and payment method details for later cycles (Stripe). Before shipping, confirm your retry path reads state before writing it, and that the late webhook updates the same intent rather than spawning a new one.

A name for a venture using this approach is another proposal to test with its intended audience. The following examples illustrate that separate naming decision.

In a hypothetical naming exercise, PayRouter.si could be considered for a hypothetical payment-orchestration tool, test whether engineers reading the name expect routing and failover logic; ask five backend engineers what they think it does before explaining it.

In a hypothetical naming exercise, LedgerLink.si could be considered for a hypothetical reconciliation tool, test whether finance-ops leads expect ledger syncing; ask three of them to describe the product from the name alone and note mismatches.

Choosing and storing idempotency keys tied to your cart or session ID

For Orbit Cart, derive the key from the cart and session, not from the click. The Payment Intents documentation notes that each PaymentIntent typically correlates with a single shopping cart or customer session, which makes cart_9f2 plus sess_44a a natural anchor (Stripe). A proposed rule: build the key as a stable hash of those two identifiers, store it server-side against the cart record, and have every confirm attempt for that cart read the stored value rather than generating a fresh one.

Proposed exercise: sketch the three confirm attempts for cart_9f2 and sess_44a and label where the key is read versus written.

Attempt Key source Expected outcome
First confirm Generated and persisted with cart_9f2 Intent created or processing
Retry one Read from cart record Same intent reused
Retry two Read from cart record Same intent reused

Two practical cautions. First, scope the key to the cart, not the browser tab, so a refresh or a second device does not mint a new key for the same purchase. Second, set a retention window longer than your slowest retry and the late webhook, which in this example arrives 40 seconds after the attempt. If your checkout uses hosted or embedded UIs, confirm how the session identifier is exposed before relying on it (Stripe). Next, verify that the stored key survives a server restart.

Reusing one intent across an interrupted checkout instead of creating a new one

In Orbit Cart's interrupted checkout, the client should retrieve the existing intent tied to cart_9f2 and sess_44a rather than create a new one. Stripe's guidance is direct: if checkout is interrupted and resumes later, attempt to reuse the same PaymentIntent, storing its ID on the cart or session so you can retrieve it (Stripe). Reuse also preserves failed-attempt state for that cart, which is exactly the context a fresh intent would discard.

Proposed exercise: map three confirm attempts to one stored intent.

Attempt Client action Server lookup
Confirm 1 (times out at 8s) Create intent, store ID on cart No prior ID
Confirm 2 Retrieve stored ID, confirm again Same intent
Confirm 3 Retrieve stored ID, confirm again Same intent
Webhook (40s late) Update that intent's state Same intent

The rule to test: no retry path may call create when a stored intent ID exists. If the customer changes the cart, update the amount on the existing intent rather than silently starting over (Stripe). Before shipping, add a check that the stored ID is read inside the same transaction that decides to create, so two near-simultaneous retries cannot both miss it. Then confirm the late webhook resolves to that same record and closes the exercise with a state you can reconcile.

Webhooks as the source of truth, plus a reconciliation checklist before you ship

In the Orbit Cart example, the client stops waiting after three confirm attempts, but the payment state is still unresolved. Stripe recommends that your server monitor webhooks to detect when a payment completes or fails, rather than trusting the client response (Stripe). The webhook arriving 40 seconds late is therefore the authoritative signal, not the timeout.

A proposed reconciliation exercise before shipping:

Check Orbit Cart question Pass condition
Intent count How many intents exist for cart_9f2 / sess_44a? Exactly one
Charge count Did retries create multiple charges on that intent? Each charge inspected and outcome recorded
Webhook mapping Does the late event resolve to the stored intent ID? Same record updated
Terminal state Is the intent in a final state? Succeeded or failed, not processing

Stripe notes that an intent can have more than one Charge object when retries occur, so inspect each charge's outcome (Stripe). Next steps: replay the three-attempt scenario in a test environment, confirm the webhook closes the same intent, and only then enable retries in production.

NameReserve offers the domain names featured in this article. Naming examples describe possible uses, rather than existing products.

Comments

Popular posts from this blog

Designing Connected Telemetry Pipelines on PulseLink.si Infrastructure

Handling Kickoff Traffic Spikes & Fan Sockets on Pregame.live Apps

Eliminating Check-In Friction Across Autonomous GuestRoom.si Hubs