Checking access…

Skip to main content
Audience: CCG Platform Engineers

Idempotency & Retries

Platform engineers implementing or reviewing merchantTransactionId dedup logic, retry-count handling, or Stripe idempotency-key forwarding in a v2 payment flow. For the exact rules and database fields, see Idempotency & Retries β€” Reference. For request and response examples, see How to Retry a Payment Request.

Overview​

The v2 payment API uses merchantTransactionId as an idempotency key to prevent duplicate payment processing. This mechanism is critical for reliability in a distributed system where network failures, timeouts, and retries are expected.



How Idempotency Works​



Best Practices for Engineers​

PracticeWhy
Always use the composite key (merchantTransactionId + merchantId) for dedup lookupsPrevents cross-merchant collisions
Increment retryCount atomicallyUse UPDATE ... SET retryCount = retryCount + 1 WHERE retryCount < 5 to prevent race conditions
Return the full current state on retryDon't return stale data β€” query the latest payment state
Forward merchantTransactionId to Stripe as the Stripe idempotency keyEnsures Stripe-level dedup matches our dedup
Never re-process a terminal paymentIf status is COMPLETED, FAILED, or CANCELLED, return as-is
Log retries distinctlyInclude retryCount in log entries to distinguish first attempts from retries


Stripe-Level Idempotency​

The Stripe adapter passes merchantTransactionId as Stripe's Idempotency-Key header. This provides a second layer of protection:

LayerKeyProtection
Service layermerchantTransactionId + merchantIdDatabase unique constraint
Stripe layermerchantTransactionId as Idempotency-KeyStripe returns cached response for duplicate calls

Both layers must agree. If our database shows no record but Stripe has one (e.g., after a partial failure), the Stripe response takes precedence and the service reconciles the state.