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

Payment sessions

The payment session object and the allowed CRUD operations on the related resource endpoint

A payment session represents a payment intent within Commerce Layer's Payments API — the central object of the payment flow, tracking the full lifecycle of a payment from creation through authorization, capture, void, and refund — and is always associated with a payment setting that determines the underlying payment provider.

A payment session can optionally be linked to an order or initiated independently via a payment link.

When linked to an order, amount_cents can be set explicitly at creation time and is capped at the order's remaining session_amount_cents — the portion of the order total not yet covered by sessions in authorized, paid, or partially_paid status. When initiated via a payment link instead, it takes the link's own amount and isn't capped, since that amount is what the customer was already charged at the gateway.

A payment session cannot be created for a free order (total amount zero).

A payment session can optionally be linked to a payment wallet, allowing customers to reuse vaulted payment instruments for faster checkout.

Lifecycle

A payment session transitions through the following statuses:

Status
Description

unpaid

Initial state — payment has not been processed yet.

authorized

An authorization has been successfully recorded.

voided

The authorization was cancelled before capture.

invalidated

An authorization attempt ended in failure — either a previously succeeded authorization was reversed by the payment provider (e.g. a delayed decline), or, for gift cards, the attempt failed outright before ever succeeding — or a Braintree local payment expired or was reversed before being paid — distinct from a deliberate void.

paid

The full session amount has been captured.

partially_paid

A partial capture has been recorded.

refunded

The full captured amount has been refunded.

partially_refunded

A partial refund has been issued.

Payment types

The session's payment subtype is derived automatically from the associated payment setting and determines which payment provider handles the transaction. Supported types are:

  • Adyen — processes payments through the Adyen gateway.

  • Braintree — processes payments through Braintree's GraphQL API.

  • Checkout.com — processes payments through the Checkout.com gateway.

  • External — integrates any custom gateway via a webhook-based contract.

  • Gift card — redeems a Commerce Layer gift card as payment.

  • Manual — handles off-band methods like wire transfers, with no gateway calls.

  • PayPal — processes payments through PayPal's REST API.

  • Stripe — processes payments through the Stripe gateway.

When using a gift card payment setting, the session requires a gift_card_code attribute. The code is validated against available active gift cards scoped to the order's market or currency.

Expiration

A payment session carries an expires_at timestamp. When you don't supply one, it's set automatically from the expiration window of the payment setting behind the session:

  • PayPal — 3 hours.

  • Adyen and Checkout.com — 1 day.

  • Braintree — 2 days.

  • Stripe — 7 days, only when auto_capture is disabled. With auto_capture enabled there's no default window, same as gift card and manual below.

  • External — whatever you supply, since there's no window Commerce Layer can assume for a custom gateway.

  • Gift card and manual — none. Along with Stripe under auto_capture, these are the settings with no default window — set expires_at explicitly if you want the session to expire anyway.

An expiration date you set explicitly always wins over the gateway default.

Exceeding the order balance

When a session is linked to an order, Commerce Layer checks whether authorizing it would push the combined amount from sessions in authorized, paid, or partially_paid status past the order's total.

This check happens at authorization time, not at session creation — so it also covers the case where multiple sessions for the same order (e.g. a split payment across a gift card and a card, or several sessions created in quick succession) are authorized close together and would otherwise combine to over-collect.

If authorizing a session would push the order over its total, the session still authorizes normally — its lifecycle and status are unaffected. Instead, its balance_exceeded_at attribute is stamped with the time this was detected. The underlying payment authorization is never rejected or falsified: it stays succeeded, since the authorization genuinely happened with the payment provider (and, depending on the provider and auto-capture setting, may already have placed a hold or even captured funds).

The balance_exceeded_at attribute is filterable, so you can query directly for flagged sessions (e.g. to build a reconciliation view) instead of comparing each session's amount against the order total yourself.

Capture and refund balances

A session tracks two running balance attributes that reflect the current state of all associated transactions:

  • capture_balance_cents — the amount remaining to be captured (session amount minus the amounts of the succeeded captures). Refunds don't change it: refunded money gives funds back to the customer, it doesn't make them capturable again.

  • refund_balance_cents — the amount remaining to be refunded (session amount minus already refunded amounts).

There is no authorization_balance_cents — a session can hold exactly one succeeded payment authorization and one succeeded payment void (failed attempts can be retried — authorization, void — and don't count), so the authorized amount is always equal to the full session amount. Multiple captures and multiple refunds are supported instead, which is why the two attributes above exist as running balances.

Gateway options

At creation time, a payment session accepts an options object whose values are passed straight through to the underlying payment provider, alongside the attributes Commerce Layer manages automatically. This lets you use gateway-specific parameters without a dedicated Commerce Layer field for each one — including overriding some of the fields Commerce Layer would otherwise compute on your behalf, such as Adyen's recurringProcessingModel or shopperInteraction.

Supported keys depend on the payment setting type:

  • Braintree — any field accepted by Braintree's TransactionInput GraphQL type, e.g. descriptor (dynamic statement descriptor — name, phone, url), orderId, purchaseOrderNumber, discountAmount, shipping, tax, lineItems, riskData, customerDetails.

  • Stripe — any parameter accepted when creating a PaymentIntent, e.g. setup_future_usage, metadata, customer.

  • Adyen — any field accepted by the /payments request — these are merged into Commerce Layer's own payload, and can override fields Commerce Layer computes by default.

For Adyen, the 3DS fields allow3DS2, executeThreeD, and authenticationData only apply to the sessions and payments requests — they're left out of payment methods, capture, void, and refund requests. An authenticationData passed via options takes precedence over the native 3DS preference Commerce Layer sends by default on payments requests.

The options attribute can only be set using integration API credentials — sales channels cannot supply it. Options are also hidden from sales channel API credentials when reading a session — only integration API credentials can see it in the response.

Requesting a specific internal version

A payment session can force a specific supported internal payload version for its own creation request via the _internal_version trigger attribute, overriding whatever the payment setting is configured with by default — without needing to set any gateway options and without requiring integration API credentials.

The supported values depend on the payment setting type — check the internal versions listed on each payment setting's page (e.g. Adyen):

Unlike options, _internal_version is available to sales channel API credentials too — it only lets the caller pick among payload variants Commerce Layer has already built, never raw gateway parameters. An unsupported value is rejected with a 422 Unprocessable Entity error.

Payment instrument

A session's payment_instrument attribute describes the instrument the customer actually paid with (e.g. card brand and last digits, or the PayPal account), so you can show it on order confirmations, receipts, or in your back office without querying the payment provider.

It's filled once, as soon as the session's authorization succeeds — whether synchronously or through a webhook — from the data the provider returns:

Payment setting
Source

Adyen

The payment (or payment details) response, or the AUTHORISATION notification.

Braintree

The payment method snapshot of the authorized (or charged) transaction.

Checkout.com

The payment source, from the payment response or the payment_approved webhook.

PayPal

The payer of the authorized (or captured) order.

Stripe

The payment method of the payment intent.

External

The payment_instrument object returned by your authorization endpoint (more details here).

When the session is paid with a wallet, or stores the instrument while being paid, the instrument is also taken from the wallet, if it isn't already set.

Depending on the payment method, the object includes some of the following keys:

Key
Description

issuer_type

The kind of instrument (e.g. card, scheme, paypal, applepay).

card_type

The card brand (e.g. visa).

card_last_digits

The last digits of the card number.

card_expiry_month, card_expiry_year

The card expiration date.

card_holder_name

The cardholder name.

card_fingerprint

The provider fingerprint identifying the card.

account_email, account_id

The account email and identifier (e.g. PayPal payer).

account_last_digits, account_type, bank_name

The bank account details (e.g. US bank accounts on Braintree).

account_holder_type

The account holder type (e.g. individual or company on Stripe, personal or business on Braintree, or the raw account owner name on Adyen).

account_fingerprint

The provider fingerprint identifying the bank account.

username, venmo_user_id

The Venmo username and user identifier.

issuer

The instrument issuer (e.g. the issuing bank of an Adyen stored card, or as returned by an external integration).

account_status

The account status, as returned by an external integration.

payment_id

The provider identifier of the payment method (e.g. the Stripe payment method ID).

Once set, the payment instrument isn't overwritten by later events or wallets — with one exception: when an Adyen card is stored while being paid and its details only become available with Adyen's tokenization notification, they're used to complete the instrument of the sessions paid with that wallet. The instrument stays empty when the provider returns no instrument data — e.g. for local payment methods, or for Adyen when the card details aren't enabled among the additional data returned by your Adyen account and the card isn't being stored.

Paying with a wallet

A session's payment_wallet relationship links it to a previously vaulted payment wallet, letting a returning customer pay with a saved instrument instead of collecting payment details again through the provider's client-side SDK.

When a wallet is linked, the session uses the wallet's payment_token and customer_token directly to build the gateway request, in place of the payment details collected client-side. On providers that support it (e.g. Adyen), a wallet-backed session also skips the SCA/3DS challenge, since the instrument was already verified when the wallet was vaulted.

For Stripe, a wallet-backed session paying an order with recurring line items also sets the saved card up for off-session use, since the shopper is present and can authenticate the payment that precedes the renewals (more details here).

On a target order generated by an order subscription, a wallet-backed session is treated as merchant-initiated: the gateway is told the customer is not present, and the stored instrument is charged off session, with no authentication step.

To link a wallet, the following conditions must all be met:

  • The wallet must be in succeeded status.

  • If the wallet has an expires_at, it must not be expired.

  • The wallet must belong to the same customer as the session's order (a wallet belonging to a different customer is rejected).

  • The wallet must use the same payment_setting as the session.

  • The wallet and the session must belong to the same organization and environment (test or live).

Vaulting during a charge

A session's vaulting attribute asks the gateway to store the payment instrument as part of the charge itself: the request is sent along with the payment, and the instrument is stored only if that payment succeeds. Commerce Layer then creates the corresponding payment wallet from the token the gateway returns and links it to the session — you don't need to create the wallet yourself, and the same instrument can be charged again later without collecting payment details anew.

This is different from the standard payment wallet workflow, where you create the wallet directly and the gateway stores the instrument without charging the customer:

Vaulting during a charge
Creating a payment wallet

How

Set the vaulting attribute on the payment session.

Create a payment wallet for the customer.

Payment

Required — the instrument is stored only when the session is paid.

None — the instrument is stored on its own (e.g. to save a card before any purchase).

Wallet

Created automatically by Commerce Layer from the charge, already succeeded and linked to the session.

Needs to be created explicitly, then linked to the sessions it should pay.

Gateways

Adyen, Braintree, Checkout.com, PayPal, Stripe, external (with a token URL).

Any vaultable payment setting.

PayPal only vaults the account when reference transactions are enabled on your PayPal merchant account. When PayPal completes the payment before storing the account, the wallet is created as soon as the VAULT.PAYMENT-TOKEN.CREATED event arrives instead (more details here).

Session token

When a session is created, a token is generated and shared with your client-side integration. This token is used by the payment provider's front-end SDK to collect payment details in the browser without sensitive data passing through your server.

For payment settings that support session token specification, an integration can supply a custom token at creation time instead of having one generated.

The token must be unique within the organization environment and will serve as the reference identifier for all subsequent gateway events associated with this session.

Triggers

A payment session supports the following trigger attributes:

  • _refresh — syncs the session data with the payment provider (for Braintree, more details here).

  • _additional_data — fetches supplementary data from the payment provider required to initialize the client-side integration, such as the available ways to pay for the buyer's context (country, amount, currency).

  • _internal_version — forces a specific supported internal payload version for this session's creation request.

Last updated