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

Payment setting braintrees

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

Braintree payment settings are the Braintree-specific subtype of payment settings. They hold the credentials and configuration required to process payments through the Braintree payment gateway via its GraphQL API.

Credentials

Setting up a Braintree payment setting requires the following credential attributes:

Attribute
Description
Required

merchant_id

Your Braintree merchant ID.

public_key

Braintree API public key.

private_key

Braintree API private key.

merchant_account_id

The specific merchant account to use for transactions.

google_pay_merchant_id

Your Google Pay merchant ID, issued by the Google Pay & Wallet Console — needed only to offer Google Pay in production.

Gateway versions

Braintree payment settings support the following gateway version, corresponding to Braintree's GraphQL API version:

  • 2019-01-01 (default)

Capabilities

Braintree payment settings support the following Commerce Layer features:

Feature
Supported

Payment sessions

Payment wallets

Payment links

3DS / SCA

Client-side integration

Braintree requires payment details to be collected client-side using its Drop-in UI or JS SDK. Once the customer completes the form, payment details must be submitted back (more details here).

Google Pay

To offer Google Pay in production, set the payment setting's google_pay_merchant_id and pass it as googleMerchantId when creating the Google Pay component with Braintree's JS SDK (more details here). The attribute is readable with sales channel API credentials — on the payment setting itself or through the order's available_payment_settings — so your checkout can read it without exposing any private credential. In sandbox, Google Pay works without it.

Apple Pay needs no attribute on the payment setting: it's set up on the Braintree side, as described in Braintree's Apple Pay guide.

Wallet vaulting

When a payment wallet is created against a Braintree payment setting, Commerce Layer reuses the Braintree customer profile from the customer's latest wallet on the same payment setting, or creates a new one on Braintree, and stores its ID as the wallet's customer token. The payment method is associated with that profile as part of the same request that vaults it.

Cards are verified on the payment setting's merchant_account_id before being stored, so a card the merchant account can't charge is rejected when the wallet is created rather than on its first payment.

You can find more information about how this compares to the other payment providers here.

Vaulting during a payment

When a payment session has vaulting enabled, Commerce Layer asks Braintree to store the payment method along with the authorization (or the charge, with auto_capture enabled), since Braintree consumes a single-use payment method as soon as it's used and can't store it afterwards. Braintree stores it only if the payment succeeds, and Commerce Layer creates the wallet from the returned payment method, already succeeded and linked to the session.

If the customer already holds a Braintree customer profile on the same payment setting, the new payment method is added to it. Otherwise, Braintree creates the profile from the customer's email at the moment the payment method is stored — a declined or abandoned payment leaves neither a wallet nor an empty customer profile behind.

Duplicate wallets

Braintree stores a new payment method every time an instrument is vaulted, even when it's one the customer already saved, so each vaulting creates a separate wallet with its own token.

Capture and refund outcomes

Captures and refunds resolve synchronously for Braintree. A transaction that Braintree accepts and submits for settlement is recorded as succeeded straight away, without waiting for settlement to complete. With auto_capture enabled, the payment is charged in a single step, and the resulting capture succeeds alongside the authorization.

Braintree refunds a transaction only once it's settling or settled. Creating a refund on a capture that's still submitted for settlement fails with Braintree's error, and can be retried once the capture has settled.

Order reference

Every authorization or charge sent to Braintree carries an orderId made of the order number followed by the ID of the payment authorization (e.g. 12345678-xYZkjABcDe). It's unique for each attempt, so a retried payment never reuses the reference of a previous one.

You can still set your own orderId via the session's gateway options — it takes precedence over the default.

Recurring payments

Commerce Layer sets Braintree's paymentInitiator on the payments of a subscription:

  • RECURRING_FIRST — on the payment that stores the instrument for an order with recurring line items, marking the start of the series.

  • RECURRING — on each renewal charged on a stored instrument, as a merchant-initiated payment.

Other payments carry no initiator, unless you set one yourself via the session's gateway options.

Refreshing a payment session

Sending the _refresh trigger attribute on a payment session asks Braintree for the current state of its transaction and aligns the session with it. This also picks up operations made directly in the Braintree Control Panel:

  • Voids — if the transaction was voided on Braintree, a payment void is created as succeeded.

  • Captures — if the session has no capture yet, one is created with the status matching Braintree's: succeeded once the transaction is submitted for settlement, or failed, declined, or expired if Braintree reports the transaction as failed, declined, or with an expired authorization. Existing captures follow their Braintree status — e.g. one whose settlement was declined is moved to failed.

  • Refunds — refunds issued on Braintree against a known capture are created, and existing ones follow their Braintree status.

The refresh only applies to sessions with a successful authorization recorded on Commerce Layer. Transactions that are already failed, declined, canceled, or expired are left unchanged.

Webhook events

Commerce Layer listens to the following Braintree webhook notification events, sent to the webhook_endpoint_url attribute exposed on this resource — configure it in the Braintree Control Panel so Braintree can deliver notifications to Commerce Layer:

Event
Action

transaction_settled

Creates a payment capture — succeeded — or, if the underlying Braintree transaction is a credit, a payment refund — succeeded. An existing capture or refund that's already succeeded is left unchanged.

transaction_settlement_declined

Creates a payment capture — failed — or, if the underlying Braintree transaction is a credit, a payment refund — failed. An existing capture or refund is moved from succeeded to failed.

local_payment_completed

Creates a payment authorization — unless a succeeded one already exists — and a payment capture, both succeeded.

local_payment_funded

Creates a payment authorization — succeeded — unless one already exists, and, if Braintree has already submitted the transaction for settlement, a payment capture — succeeded.

local_payment_expired

Moves an unpaid payment session to invalidated.

local_payment_reversed

Creates a payment refund — succeeded — for the whole captured amount if the payment was captured, moves the payment authorization to failed if it was only authorized, or moves an unpaid payment session to invalidated.

Whether a capture or a refund is created depends on the Braintree transaction type:

  • A sale transaction maps to a payment capture.

  • A credit transaction maps to a payment refund.

Events are matched to a payment session using the Braintree transaction ID — which Commerce Layer stores on the related payment transaction when it calls Braintree — or, for local payments, the payment_id. If the event refers to a session but the transaction doesn't already exist on Commerce Layer, it's created automatically.

Last updated