Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.
Beta

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.

This is an immutable API, meaning that create, update, and delete operations are not allowed on this endpoint. You can only fetch a list of payment transactions or a single payment transaction object. For the full set of available CRUD actions, refer to the specific payment transaction type endpoints.

Payment transactions are polymorphic. The concrete type can be one of:

Type
Description

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:

Status
Description

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.

The succeeded status isn't always final for a payment authorization: a gateway can send a corrective event reversing its own earlier success (e.g. a delayed bank decline), moving the authorization to declined, failed, canceled, or expired and invalidating its session. A reversed authorization is the only corrective event that invalidates the session this way — a corrective event on a capture, void, or refund moves that transaction's own status, but leaves the session's status untouched. A session can also end up invalidated without any transaction ever reaching succeeded — e.g. when a gift card authorization fails outright, or when a Braintree local payment expires or is reversed while the session is still unpaid.

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_cents is identical.

  • Its reference and reference_origin are identical — two transactions that both omit them count as a match.

  • The earlier transaction is still open (pending, requires_action, or processing) 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):

Type
Idempotency parameter

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.

Payment links and payment wallets are not transactions and don't take part in this inheritance — each derives its key from its own token and request payload, so an identical repeat on the same link or wallet is deduplicated by that key instead, where the provider accepts one.

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).

The options attribute can only be set using integration API credentials — sales channels cannot supply it. Options and response_data are also hidden from sales channel API credentials when reading a transaction — only integration API credentials can see them in the response. Instead, request_data is unaffected and remains visible to every credential type.

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.

Unlike options, it's available to sales channel API credentials too.

Last updated