payment-idempotency

Enforce idempotent payment connector endpoints using paymentId and requestId keys.

Updated Mar 27, 2026
One-click install
npx skills add https://github.com/exilonX/ap2 --skill payment-idempotency-exilonx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: payment-idempotency
Source: https://github.com/exilonX/ap2/tree/main/.agents/skills/payment-idempotency
Command: npx skills add https://github.com/exilonX/ap2 --skill payment-idempotency-exilonx

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents duplicate payment processing caused by gateway retries and replays, ensuring the same request identifiers always yield the same stored outcome instead of triggering multiple acquirer charges.

Core Features & Use Cases

  • Deterministic idempotency for Create Payment: Enforces paymentId as the idempotency key and returns the exact stored response for duplicates, avoiding repeated acquirer calls.
  • Safe operation idempotency for Cancel/Capture/Refund: Enforces requestId as the idempotency key for operational endpoints so retries don’t double-cancel or double-refund.
  • Correct payment state machine transitions: Validates allowed transitions (e.g., no capture after cancellation) to keep reconciliation consistent across retries, including the 7-day retry window for undefined status payments.

Quick Start

Use payment-idempotency when implementing your payment connector handlers so that duplicate Create Payment requests with the same paymentId return the previously stored response, and Cancel/Capture/Refund requests with the same requestId do not re-process the underlying acquirer operation.

Frequently Asked Questions about payment-idempotency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent duplicate charges when a VTEX IO gateway retries a payment connector request?

Prevent duplicate charges by enforcing idempotency: use paymentId as the key for Create Payment and requestId for Cancel, Capture, or Refund operations, returning the exact stored response for any repeated gateway retries without re-processing acquirer calls.

What is the correct idempotency key for handling payment refunds and cancellations?

The correct idempotency key for payment refunds and cancellations is requestId. Using requestId ensures that duplicate Cancel or Refund gateway requests return the previously stored outcome instead of double-processing the underlying acquirer operation.

How do I manage payment state machine transitions for asynchronous payment methods?

Manage asynchronous payment methods by returning a status of "undefined" until the transaction is confirmed, validating allowed state transitions to prevent inconsistent reconciliation, and supporting a 7-day retry window for undefined status payments.

Do I need persistent storage to implement idempotency for payment connector endpoints?

Yes, persistent storage is required to implement payment idempotency. It allows the system to store initial responses and perform verbatim response replay for duplicate requests, ensuring repeated gateway requests do not trigger multiple acquirer charges.

Why does my payment reconciliation show inconsistent artifacts after a gateway retry?

Inconsistent reconciliation artifacts occur because duplicate gateway retries are re-processing operations. Correct this by validating payment state machine transitions and enforcing idempotency keys to ensure retries return the exact stored response.

Can I capture a payment after it has been cancelled in the payment state machine?

No, capturing a payment after cancellation is an invalid state transition. Correct idempotency implementation validates allowed transitions to prevent illegal operations, keeping payment reconciliation consistent across gateway retries.