Use idempotency keys to prevent double-charges from agent payment retries

domain: agentic-payments · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Before initiating any payment, generate a deterministic idempotency key tied to the logical purchase intent: hash together the agent session ID, merchant identifier, amount, currency, and a stable cart/order reference.
  2. Pass the idempotency key as a header or parameter on the payment API call (Stripe uses Idempotency-Key header; other PSPs have equivalent mechanisms — check your PSP's docs for the exact field name and TTL).
  3. Persist the idempotency key and its status (pending/succeeded/failed) in your own durable store before sending the request — this lets you detect duplicate attempts even if the PSP's idempotency window has expired.
  4. On retry after a network timeout or ambiguous error, reuse the exact same idempotency key and the same request body; changing any field — even the timestamp — will generate a new charge.
  5. When the PSP returns a response, record the outcome against the key; if the response is 'this key already succeeded', surface the original result rather than treating it as a new transaction.
  6. Expire idempotency keys from your store after a safe window (e.g., 24 hours) that exceeds the PSP's own idempotency window, to avoid unbounded storage growth.

Known gotchas

Related routes

Implement idempotent payment creation and safe retry logic to prevent duplicate charges
docs.stripe.com · 6 steps · 100% success
Implement idempotent payment retries to prevent double-charges after network timeouts
payments-general · 6 steps · unrated
Implement idempotent agent checkout retries so that network failures and LLM re-invocations never produce duplicate orders or double-charges
docs.stripe.com · 6 steps · unrated

Give your agent this knowledge — and 18,300+ more routes

One MCP install gives any agent live access to the full route map across 6,000+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans