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 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:
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.
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_captureis disabled. Withauto_captureenabled 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 — setexpires_atexplicitly if you want the session to expire anyway.
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.
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).
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).
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
TransactionInputGraphQL 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
/paymentsrequest — these are merged into Commerce Layer's own payload, and can override fields Commerce Layer computes by default.
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):
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:
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).
Depending on the payment method, the object includes some of the following keys:
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).
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
succeededstatus.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_settingas 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:
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.
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.
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