Payment transactions
The payment transaction object and the allowed CRUD operations on the related resource endpoint
Payment transactions are the entry point for any payment action in Commerce Layer. Every operation — authorization, capture, void, or refund — is modeled as a transaction against a payment session, whether initiated explicitly via the API or created automatically when a gateway webhook event arrives. Each transaction tracks its full lifecycle from pending through to a terminal state.
Payment transactions are polymorphic. The concrete type can be one of:
payment_authorizations
Reserves funds on the customer's payment instrument.
payment_captures
Collects previously authorized funds.
payment_voids
Cancels an authorization before capture.
payment_refunds
Returns previously captured funds to the customer.
Lifecycle
All transaction types share the same state machine:
pending
The transaction has been created and is queued for processing.
requires_action
The transaction requires additional customer action (e.g., a 3DS challenge).
processing
The transaction is being processed by the payment provider.
succeeded
The transaction completed successfully.
declined
The transaction was declined by the payment provider.
failed
The transaction failed due to a processing error.
canceled
The transaction was canceled before completion.
expired
The transaction timed out.
A transaction is checked against its session twice: when it's created, and again when it's processed. If the session changes in the meantime so it can no longer accept the transaction (e.g. another authorization on the same session has already succeeded), the transaction moves to failed instead of staying open. Session expiration is the exception: it's checked at creation only, so a transaction already in progress when the session expires still reaches its final status.
Idempotency
Every payment transaction is created with an idempotency key, and Commerce Layer derives the value it sends to the payment provider from that key. Two transactions sharing a key present the gateway with the same operation, so a resubmitted capture or refund — whether from a retried API call or a double-clicked button — is recognized as the one already taken instead of moving the money twice.
A new transaction inherits the key of an earlier one when all of the following hold:
It belongs to the same payment session.
It is the same type — an authorization, capture, void, or refund.
It points at the same reference transaction: the payment authorization being captured or voided, the payment capture being refunded.
Its
amount_centsis identical.Its
referenceandreference_originare identical — two transactions that both omit them count as a match.The earlier transaction is still open (
pending,requires_action, orprocessing) and was created within the idempotency window.
Otherwise the new transaction gets a key of its own and reaches the gateway as a distinct operation.
That last condition is what keeps a legitimate repeat from being swallowed. An earlier attempt that already reached succeeded, declined, failed, canceled, or expired never lends its key — a retry after a decline, and a genuine follow-up after a success, both go through immediately, with no need to wait for the window to lapse. The window bounds the open case only: an attempt stuck in processing because a gateway event never arrived stops absorbing new attempts once it expires.
Where the key is sent to the provider depends on the payment setting type (more details on external endpoints here):
payment_setting_adyens
Idempotency-Key header.
payment_setting_braintrees
Not sent — Braintree's API takes no idempotency parameter.
payment_setting_checkout_coms
Cko-Idempotency-Key header.
payment_setting_paypals
PayPal-Request-Id header.
payment_setting_stripes
Idempotency-Key header.
payment_setting_gift_cards
Not applicable — no external provider is called.
payment_setting_manuals
Not applicable — no external provider is called.
payment_setting_externals
X-CommerceLayer-Idempotency-Key header.
Gateway options
Like payment sessions, some transaction types accept an options object passed straight through to the payment provider when the transaction is created — useful for gateway parameters not otherwise modeled by Commerce Layer (e.g. a Braintree descriptor or orderId on a capture or refund).
Internal version
Like payment sessions, wallets, and links, an individual transaction can force a specific supported internal payload version for its own creation request via the _internal_version trigger attribute — for example, pinning the exact payload variant used to build a capture or refund, independent of what the payment setting is configured with by default.
Last updated