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

Payment setting paypals

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

PayPal payment settings are the PayPal-specific subtype of payment settings. They hold the credentials and configuration required to process payments through PayPal's REST API.

Credentials

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

Attribute
Description
Required

client_id

Your PayPal REST API client ID.

client_secret

Your PayPal REST API client secret.

webhook_id

The ID of the PayPal webhook pointing at webhook_endpoint_url, generated automatically — used to verify incoming webhook signatures. Read-only.

Capabilities

PayPal payment settings support the following Commerce Layer features:

Feature
Supported
Notes

Payment sessions

Payment wallets

Payment links

3DS / SCA

PayPal's own approval step provides equivalent strong customer authentication, but through a different mechanism — see below.

Approval flow

Unlike gateways that redirect the customer during authorization, PayPal requires the shopper's approval before an authorization can be attempted.

When a payment session is created with a PayPal payment setting, Commerce Layer creates a PayPal order and stores the raw response — including its HATEOAS links array — in the session's response_data attribute. Redirect the shopper to the link with the rel attribute set to approve to complete PayPal's approval step.

Once the shopper returns from the approval step, create a payment authorization as usual to complete the payment — or, if auto_capture is enabled, to authorize and capture it in one step.

Wallet vaulting

PayPal vaulting uses a two-step token exchange. Your client-side integration (the PayPal JS SDK) collects the shopper's consent and produces a setup token — Commerce Layer never creates this token itself. Submit its ID back when creating the payment wallet, via the _payment_details trigger attribute:

Commerce Layer exchanges the setup token for a permanent payment token via PayPal's Vault API and stores it as the wallet's payment_token. Unless you supply your own customer_token, Commerce Layer sends the customer's own identifier alongside the setup token in that same request and stores it as the wallet's customer token — it's a separate input, not part of the token exchange itself.

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 PayPal to store the shopper's account once the payment succeeds, and creates the wallet from the vault token PayPal returns — no setup token is needed. PayPal can store the account right away, in which case the wallet is created with the authorization, or complete the payment first and store the account shortly after: the wallet is then created when the VAULT.PAYMENT-TOKEN.CREATED webhook event arrives.

Duplicate wallets

PayPal keeps one vault token per PayPal account and customer, and returns the same one when that account is vaulted again for the same PayPal customer. Commerce Layer stores the PayPal customer ID on each wallet and reuses it for every later vaulting of that customer, directly or during a payment. The IDs sent to PayPal depend on how the wallet is created:

  • Created directly — your own customer ID is always sent as the merchant reference, together with the PayPal customer ID once the customer has one.

  • Created during a payment — your own customer ID is sent only until PayPal has assigned the customer an ID of its own. From then on, only the PayPal customer ID is sent.

When a payment session with vaulting enabled vaults an account the customer already holds in an active wallet, the session is linked to that wallet instead of creating a new one.

Webhook management

When a PayPal payment setting is created, Commerce Layer automatically registers a webhook with PayPal, subscribed to the events below and pointing to webhook_endpoint_url, and stores the resulting webhook_id. If a webhook with the same URL already exists on the PayPal app, it is reused instead of creating a new one, and its subscriptions are updated to the events below. If the request fails — e.g. because the client credentials lack the necessary permissions — the payment setting is still created, but stays in the pending status until the webhook is provisioned (more details here). The webhook is removed from PayPal when the payment setting is deleted.

Webhook events

Commerce Layer listens to the following PayPal webhook events, sent to the webhook_endpoint_url attribute exposed on this resource (more details above):

Event
Action

PAYMENT.AUTHORIZATION.CREATED

Creates or updates a payment authorization — succeeded or failed.

PAYMENT.AUTHORIZATION.VOIDED

Creates or updates a payment void — succeeded.

PAYMENT.CAPTURE.COMPLETED

Creates or updates a payment capture — succeeded.

PAYMENT.CAPTURE.PENDING

Creates or updates a payment capture — succeeded, recorded while PayPal is still holding the funds (e.g. for an eCheck or a payment under review).

PAYMENT.CAPTURE.DENIED

Creates or updates a payment capture — failed. A capture that's already succeeded is moved to failed.

PAYMENT.CAPTURE.DECLINED

Creates or updates a payment capture — failed. A capture that's already succeeded is moved to failed.

PAYMENT.CAPTURE.REFUNDED

Creates or updates a payment refund — succeeded — against the capture it refunds.

PAYMENT.REFUND.PENDING

Creates or updates a payment refund — succeeded, recorded while PayPal is still processing it — against the capture it refunds.

PAYMENT.REFUND.FAILED

Creates or updates a payment refund — failed. A refund that's already succeeded is moved to failed.

VAULT.PAYMENT-TOKEN.CREATED

Creates a succeeded payment wallet linked to the payment session that asked for vaulting, if it doesn't have one yet.

Events are matched to a payment session using the originating order ID — the same value Commerce Layer stores as the session's token — which PayPal sets in the event resource's supplementary_data.related_ids.order_id field for payment events, and in its metadata.order_id field for VAULT.PAYMENT-TOKEN.CREATED. When a payment event doesn't carry the order ID, Commerce Layer falls back to the event resource's custom_id — set to the payment session ID on every PayPal capture and refund it creates — and then to the capture referenced by the event's up link. If the referenced transaction does not already exist, it is created automatically.

With several partial captures on the same session, a refund event is attached to the capture it refunds, as referenced by its up link, or to the latest capture if that link is missing.

The custom ID is reserved for reconciliation: on captures and refunds, a value passed via the transaction's gateway options is always replaced by the payment session ID.

Unlike Adyen, Braintree, and Checkout.com, PayPal has no local signature check based on a shared secret. Commerce Layer verifies every incoming event with a server-to-server call to PayPal's own verification endpoint before processing it.

Last updated