Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/sample-repo/.almanac/pages/payment-idempotency-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Payment Idempotency Keys
summary: "Always pass an idempotency key when calling the payment provider to safely retry authorizations."
topics: [gotchas, payments]
files:
- src/payments.ts
---

# Payment Idempotency Keys

When retrying an authorization request with the payment provider, it is critical to use an idempotency key. This ensures that the payment provider will not charge the customer twice if the first request succeeded but we timed out while waiting for the response.

Agents editing [[src/payments.ts]] should ensure that any calls to the provider include an idempotency key generated at the beginning of the checkout session.
4 changes: 2 additions & 2 deletions examples/sample-repo/src/payments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export async function authorizePayment(amountCents: number): Promise<string> {
export async function authorizePayment(amountCents: number, idempotencyKey?: string): Promise<string> {
if (amountCents <= 0) {
throw new Error("amountCents must be positive");
}

return "receipt_sample";
return "receipt_sample_" + (idempotencyKey || "none");
}