Use the PayPal v6 JavaScript SDK to integrate PayPal, Venmo, Pay Later, and other payment methods into web applications. This reference covers payment eligibility checking, session management, callback handling, and web components.Documentation Index
Fetch the complete documentation index at: https://docs.paypal.ai/llms.txt
Use this file to discover all available pages before exploring further.
Check payment eligibility
Before displaying payment buttons to your buyers, check which payment methods are available for the current transaction. Eligibility depends on various factors including the buyer’s location, currency, merchant configuration, and transaction amount.sdkInstance.findEligibleMethods(options?)
Use findEligibleMethods to determine which payment methods are available for the current context. This method queries PayPal’s eligibility service and returns an object with methods to check specific payment options.
Parameters
| Parameter | Required | Description |
|---|---|---|
currencyCode | no | string. The three-letter ISO 4217 currency code for the transaction, for example, |
countryCode | no | string. The two-letter ISO 3166-1 alpha-2 country code representing the buyer’s country. This determines regional payment method availability. For example, Venmo is only available in the US. If not specified, the SDK attempts to detect the buyer’s country. |
amount | no | string. The transaction amount as a string, for example, |
Returns
Returns a promise that resolves to an EligiblePaymentMethods object with methods to check and retrieve payment method information. The returned object provides these methods:isEligible(method)- Check if a specific payment method is availablegetDetails(method)- Get additional information about a payment method
Example
paymentMethods.isEligible(method)
Check whether a specific payment method is available for the current transaction.
Parameters
| Parameter | Required | Description |
|---|---|---|
method | yes | string. The payment method identifier to check. Supported values:
|
Returns
Returnstrue if the payment method is available, false otherwise.
Example
paymentMethods.getDetails(method)
Retrieve additional configuration details for a specific payment method. This is particularly useful for Pay Later and PayPal Credit, which require additional attributes for proper button rendering.
Parameters
| Parameter | Required | Description |
|---|---|---|
method | yes | string. The payment method to get details for. Currently returns details for:
|
Returns
Returns an object with payment method-specific details. The structure varies by payment method. For Pay Later:Example
Creating payment sessions
Payment sessions manage the complete payment flow from initiation through completion. Each payment method has its own session creation method that returns a session object with methods to start and control the payment process.sdkInstance.createPayPalOneTimePaymentSession(options)
Create a payment session for one-time PayPal payments. This session handles the complete PayPal Checkout flow, including payment approval, shipping address changes, and order updates.
Parameters
The options object configures callbacks that handle different stages of the payment flow. These callbacks allow you to respond to buyer actions and update your order accordingly.| Parameter | Required | Description |
|---|---|---|
onApprove | yes | function(data). Called when the buyer approves the payment in the PayPal flow. This is where you should capture or authorize the payment on your server. The function receives a data object containing:
This function can return a promise if you need to perform async operations like capturing the payment. |
onCancel | no | function(data). Called when the buyer cancels the payment flow by closing the PayPal window or selecting cancel. The data object contains:
Use this callback to:
|
onError | no | function(error). Called when an error occurs during the payment flow. This includes network errors, validation errors, or payment failures. The error object contains:
Use this to display user-friendly error messages and log errors for debugging. |
onShippingAddressChange | no | function(data). Called when the buyer changes their shipping address within the PayPal flow. This allows you to update shipping costs or restrict certain addresses. The data object contains:
Return a promise to update the order with new shipping costs. If you reject the promise, the address change will be rejected. |
onShippingOptionsChange | no | function(data). Called when the buyer selects a different shipping option, for example, standard or express shipping. The data object contains:
Return a promise to update the order total with the new shipping cost. |
orderId | no | string. An existing PayPal order ID to use for this session. This allows you to create the order on your server before starting the payment flow (eager order creation). If not provided, you’ll pass an order creation function to the |
commit | no | boolean. Controls the final button text in the PayPal flow:
Default: |
savePayment | no | boolean. Saves the customer’s payment method during purchase. Set to |
Returns
Returns aPaymentSession object with methods to control the payment flow.
Example
sdkInstance.createPayPalSavePaymentSession(options)
Create a session for saving PayPal as a payment method for future use (vaulting). This allows buyers to save their PayPal account for faster checkout in future purchases.
The parameters and usage are identical to createPayPalOneTimePaymentSession, except the onApprove callback receives a billingToken instead of requiring immediate payment capture.
Example
sdkInstance.createVenmoOneTimePaymentSession(options)
Create a payment session for Venmo payments (US only). Venmo provides a mobile-optimized payment experience for US buyers using their Venmo balance or linked payment methods.
The parameters are identical to createPayPalOneTimePaymentSession. Venmo sessions support the same callbacks and flow options.
Example
sdkInstance.createPayLaterOneTimePaymentSession(options)
Create a session for Pay Later financing options. Pay Later allows buyers to pay in installments (like Pay in 4) or over time with longer-term financing.
The parameters are identical to createPayPalOneTimePaymentSession. Pay Later availability depends on transaction amount and buyer eligibility.
Example
sdkInstance.createPayPalCreditOneTimePaymentSession(options)
Create a session for PayPal Credit payments (US only). PayPal Credit offers buyers a reusable line of credit for purchases.
sdkInstance.createPayPalSubscriptionSession(options)
Create a payment session for PayPal subscription payments. Use subscriptions when buyers need recurring billing — for example, membership fees, software licenses, or regular service plans.
Parameters
| Parameter | Required | Description |
|---|---|---|
onApprove | yes | function(data) — Called when the buyer approves the subscription. The data object includes:
|
onCancel | no | function(data) — Called when the buyer cancels the subscription flow. The data object contains |
onError | no | function(error) — Called when an error occurs during the subscription flow. The error object contains |
Returns
Returns a subscription session object with astart(options?, subscriptionPromise) method. subscriptionPromise must resolve to { subscriptionId: string } containing your PayPal subscription ID.
Example
sdkInstance.createGooglePayOneTimePaymentSession()
Create a session for Google Pay payments. The Google Pay session integrates with the Google Pay API and handles PayPal order confirmation.
googlepay-payments component and the Google Pay JavaScript SDK. Load both before calling this method. Enable Google Pay in your PayPal sandbox and production account settings before going live.Returns
Returns aGooglePaySession object (synchronously) with these methods:
googlePaySession.formatConfigForPaymentRequest(config)
Format the Google Pay configuration for the Google Pay API. Before calling this method, use sdkInstance.findEligibleMethods() to check eligibility and retrieve the raw configuration, then pass the .config property from paymentMethods.getDetails("googlepay"):
Parameters
| Parameter | Required | Description |
|---|---|---|
config | yes | object. The config property from paymentMethods.getDetails("googlepay"). |
Returns
Returns a formatted configuration object:| Property | Type | Description |
|---|---|---|
allowedPaymentMethods | array | Payment method configuration for the Google Pay API |
merchantInfo | object | PayPal merchant information for Google Pay |
apiVersion | number | Google Pay API version |
apiVersionMinor | number | Google Pay API minor version |
countryCode | string | Two-letter ISO 3166-1 country code |
googlePaySession.confirmOrder(options)
Use the payment data from Google Pay to confirm the PayPal order. Call this inside the onPaymentAuthorized callback.
Parameters
| Parameter | Required | Description |
|---|---|---|
orderId | yes | string. The PayPal order ID created on your server. |
paymentMethodData | yes | object. The payment method data from the Google Pay authorization response (paymentData.paymentMethodData). |
Returns
Returns a promise that resolves to{ status }:
| Status | Description |
|---|---|
APPROVED | Order confirmed and ready to capture. |
PAYER_ACTION_REQUIRED | 3D Secure authentication required before capture. |
Example
sdkInstance.createApplePayOneTimePaymentSession()
Create a session for Apple Pay payments. The Apple Pay session integrates with the browser’s native ApplePaySession API and handles merchant validation and order confirmation.
- The
applepay-paymentscomponent - The Apple Pay JavaScript SDK
- An HTTPS connection
- A merchant domain registration with PayPal Apple Pay is available in Safari on Apple devices only.
Returns
Returns a promise that resolves to an Apple Pay session object with these methods:applePaySession.config()
Fetch the Apple Pay merchant configuration from PayPal.
Returns
Returns a promise that resolves to:| Property | Type | Description |
|---|---|---|
merchantCapabilities | string[] | Merchant capabilities for the Apple Pay payment request, for example, ["supports3DS"] |
supportedNetworks | string[] | Card networks the merchant accepts, for example, ["visa", "masterCard", "amex"] |
applePaySession.validateMerchant(options)
Complete Apple Pay merchant validation. Call this inside the onvalidatemerchant event handler of the browser’s ApplePaySession.
Parameters
| Parameter | Required | Description |
|---|---|---|
validationUrl | yes | string. The validation URL from the onvalidatemerchant event (event.validationURL). |
Returns
Returns a promise that resolves to{ merchantSession }. Pass merchantSession to applePaySession.completeMerchantValidation().
applePaySession.confirmOrder(options)
Confirm the PayPal order using the payment token from Apple Pay. Call this inside the onpaymentauthorized event handler.
Parameters
| Parameter | Required | Description |
|---|---|---|
orderId | yes | string. The PayPal order ID created on your server. |
token | yes | object. The Apple Pay payment token from event.payment.token. |
billingContact | no | object. The buyer’s billing contact from event.payment.billingContact. |
shippingContact | no | object. The buyer’s shipping contact from event.payment.shippingContact. |
Payment request structure
Build anApplePayPaymentRequest to pass to the browser’s new ApplePaySession():
| Property | Description |
|---|---|
countryCode | Merchant country code, for example, "US" |
currencyCode | Transaction currency code, for example, "USD" |
merchantCapabilities | From applePaySession.config() |
supportedNetworks | From applePaySession.config() |
requiredBillingContactFields | Array of required billing fields: "name", "phone", "email", "postalAddress" |
requiredShippingContactFields | Array of required shipping fields, or empty array if no shipping needed |
total | Object with label (string), amount (string), and type ("final" or "pending") |
Example
sdkInstance.createFastlane()
Create a Fastlane instance for accelerated guest checkout. Fastlane enables one-click checkout for recognized guests.
Returns
Returns a promise that resolves to a Fastlane instance.Example
sdkInstance.createPayPalMessages(options?)
Display PayPal Messages to show financing options and promotional messaging to buyers. These messages dynamically update based on the transaction amount and buyer eligibility.
Parameters
| Parameter | Required | Description |
|---|---|---|
amount | no | number. The product or cart amount to display messaging for. Messages update dynamically based on this amount. |
placement | no | string. The page placement context for the messages. This affects message format and content. Values: |
style | no | object. Visual styling options for the messages, including layout and logo configuration. |
Returns
Returns aPayPalMessagesInstance object with fetchContent(options?) and createLearnMore(options?) methods.
messagesInstance.fetchContent(options?)
Fetch message content from PayPal and render it in all <paypal-messages> components on the page.
| Option | Required | Description |
|---|---|---|
amount | no | string. Transaction amount with up to 2 decimal places, for example, "125.00". Affects which financing offers are displayed. |
currencyCode | no | string. Three-letter ISO 4217 currency code, for example, "USD". |
logoPosition | no | string. Where to place the PayPal logo. Values: LEFT (default), RIGHT, TOP, INLINE. Note: MONOGRAM logo type requires LEFT; TEXT logo type requires INLINE. |
logoType | no | string. PayPal branding style. Values: WORDMARK (default), MONOGRAM, TEXT. |
textColor | no | string. Message text color. Values: BLACK (default), WHITE, MONOCHROME. |
onContentReady | no | function. Called when content arrives from the server. Takes precedence over onReady. |
onTemplateReady | no | function. Called when content is served from local cache. Takes precedence over onReady. |
onReady | no | function. Called when content is ready from either cache or server. Used when neither onContentReady nor onTemplateReady is specified. |
messagesInstance.createLearnMore(options?)
Initialize a Learn more presentation that provides additional financing details when buyers select the Learn more link in a message.
| Option | Required | Description |
|---|---|---|
amount | no | string. The transaction amount to display in the Learn more presentation. |
presentationMode | no | string. How the Learn more content is shown. Values: AUTO (default), MODAL, POPUP, REDIRECT. |
onApply | no | function. Called when the buyer selects Apply in the Learn more presentation. |
onCalculate | no | function. Called when the buyer enters a value in the amount input field. |
onShow | no | function. Called when the Learn more presentation opens. |
onClose | no | function. Called when the Learn more presentation closes. |
CSS custom properties
Customize message appearance using these CSS properties on the<paypal-messages> element:
| Property | Description | Default |
|---|---|---|
--paypal-message-font-size | Font size in px, clamped to 10px–16px. | 14px |
--paypal-message-text-align | Text alignment. Values: left, right, center. | left |
Example
paymentSession.start(options?, orderPromise)
Start the payment user experience. This method opens the payment interface using the specified presentation mode and begins the checkout flow.
Parameters
| Parameter | Required | Description |
|---|---|---|
options | no | object. Configuration for how the payment UI is presented. |
options.presentationMode | no | string. Controls how the payment interface is displayed to the buyer. Available modes:
Default: The SDK will automatically fall back to alternative modes if the requested mode is unavailable. |
options.autoRedirect | no | object. Configuration for redirect mode behavior.
Only applies when using |
options.fullPageOverlay | no | object. Controls the background overlay when using popup mode.
Default: |
options.loadingScreen | no | object. Customize the loading screen text.
|
orderPromise | yes | promise. A promise that creates or retrieves the PayPal order. This promise should resolve to an object containing the The order creation can happen asynchronously while the payment UI is loading, improving perceived performance. |
Returns
For most presentation modes, returns a promise that resolves when the payment flow completes or is cancelled. For redirect mode withautoRedirect.enabled: false, returns the redirect URL:
Example
paymentSession.hasReturned()
Check if the current page load is a return from a redirect payment flow. Use this method on page load to detect and resume interrupted payment sessions.
Returns
Returnstrue if the buyer is returning from a PayPal redirect, false otherwise.
Example
paymentSession.resume()
Resume a payment session after returning from a redirect flow. This method continues the payment process and triggers the appropriate callbacks based on the payment outcome.
Returns
Returns a promise that resolves when the session is successfully resumed.Handling callbacks
Callbacks allow you to respond to events during the payment flow. Each callback receives specific data about the event and can optionally return a promise to perform asynchronous operations.onApprove(data)
Called when the buyer successfully approves the payment. This is where you should capture or authorize the payment on your server.
Parameters
The callback receives a data object with the following properties:| Property | Type | Description |
|---|---|---|
orderId | string | The PayPal order ID that was approved. Use this to capture the payment on your server. |
payerId | string | The buyer’s PayPal payer ID. This identifies the PayPal account used for payment. |
paymentId | string | undefined | Legacy payment ID for backwards compatibility. Only present in certain flows. |
billingToken | string | undefined | Token for saving payment method. Only present when using save payment sessions. |
Return value
The callback can optionally return a promise. If a promise is returned, the SDK waits for it to resolve before completing the flow.Example
onCancel(data)
Called when the buyer cancels the payment without completing it. This typically happens when they close the PayPal window or select a cancel button.
Parameters
| Property | Type | Description |
|---|---|---|
orderId | string | undefined | The order ID if one was created before cancellation. May be undefined if cancelled before order creation. |
Example
onError(error)
Called when an error occurs during the payment flow. This includes network errors, validation failures, and payment processing errors.
Parameters
The callback receives an error object with these properties:| Property | Type | Description |
|---|---|---|
code | string | A specific error code identifying the type of error. Use this for programmatic error handling. |
message | string | A human-readable error description. This may contain technical details not suitable for buyers. |
Common error codes
| Code | Description | Recommended action |
|---|---|---|
ERR_INVALID_CLIENT_TOKEN | Client token is invalid or expired | Generate a new token and reinitialize |
ERR_DOMAIN_MISMATCH | Current domain doesn’t match token | Verify domain configuration |
ERR_DEV_UNABLE_TO_OPEN_POPUP | Popup was blocked by browser | Fall back to modal or redirect mode |
ERR_FLOW_PAYMENT_HANDLER_BROWSER_INCOMPATIBLE | Payment handler not supported | Use traditional checkout flow |
INSTRUMENT_DECLINED | Payment method was declined | Suggest alternative payment method |
NETWORK_ERROR | Network request failed | Retry or check connection |
Example
onShippingAddressChange(data)
Called when the buyer selects or changes their shipping address within the PayPal flow. Use this callback to update shipping costs, validate addresses, or apply location-based restrictions.
Data properties
| Property | Type | Description |
|---|---|---|
errors | object | Error messages you can display to the user in the Checkout UI |
errors.ADDRESS_ERROR | string | ”Your order can’t be shipped to this address.” |
errors.COUNTRY_ERROR | string | ”Your order can’t be shipped to this country.” |
errors.STATE_ERROR | string | ”Your order can’t be shipped to this state.” |
errors.ZIP_ERROR | string | ”Your order can’t be shipped to this zip.” |
orderId | string | The current order ID |
shippingAddress | object | The newly selected shipping address |
shippingAddress.city | string | City name |
shippingAddress.state | string | State or province code |
shippingAddress.countryCode | string | ISO 3166-1 alpha-2 country code |
shippingAddress.postalCode | string | Postal or ZIP code |
Return value
Return a promise to update the order asynchronously. If the promise rejects, the address change will be rejected and the buyer must select a different address.Example
onShippingOptionsChange(data)
Called when the buyer selects a different shipping option, for example, standard or express delivery. Use this to update the order total with the selected shipping cost.
Data properties
| Property | Type | Description |
|---|---|---|
errors | object | Error messages you can display to the user in the Checkout UI |
errors.METHOD_UNAVAILABLE | string | ”The shipping method you chose is unavailable. To continue, choose another way to get your order.” |
errors.STORE_UNAVAILABLE | string | ”Part of your order isn’t available at this store.” |
orderId | string | The current order ID |
selectedShippingOption | object | Details of the selected shipping option |
Example
Web components
PayPal.js provides native web components for rendering payment buttons. These components automatically handle styling and accessibility while allowing customization through CSS variables.paypal-button
The PayPal button web component renders a PayPal-branded button that buyers select to start the payment flow.
Attributes
| Attribute | Type | Description |
|---|---|---|
type | string | Controls the button label text. Different types are optimized for different contexts in your checkout flow. Values:
|
class | string | Applies a predefined color scheme to the button. Values:
|
CSS variables
Customize the button appearance using CSS custom properties:| Variable | Description | Example values |
|---|---|---|
--paypal-button-border-radius | Border radius for the button | 4px, 20px, 50px |
--paypal-mark-border-radius | Border radius for the PayPal mark/logo | 4px, 8px |
Example
venmo-button
The Venmo button web component renders a Venmo-branded button for US buyers. The attributes and styling options are identical to <paypal-button>.
Example
paylater-button
The Pay Later button component displays financing options to buyers. This button requires additional configuration based on the available Pay Later products.
Attributes
| Attribute | Type | Description |
|---|---|---|
productCode | string | The specific Pay Later product to display, for example, "PAY_IN_4". Get this from paymentMethods.getDetails('paylater'). |
countryCode | string | The country code for the Pay Later offer. Required for proper messaging display. |
Example
paypal-credit-button
The PayPal Credit button component displays PayPal’s credit offering for eligible buyers (US only).
Attributes
| Attribute | Type | Description |
|---|---|---|
countryCode | string | The country code for PayPal Credit availability. Required for proper display. |
Example
Browser compatibility
The JavaScript SDK v6 supports modern browsers. Check browser compatibility before initializing the SDK to ensure optimal user experience.Minimum supported versions
| Browser (web/mobile web) | Minimum Supported Version |
|---|---|
| Chrome | 69 |
| Safari | 12 |
| Firefox | 63 |
| Samsung Internet | 10 |
| Edge | 79 |
Browser support check
Use thewindow.isBrowserSupportedByPayPal() function to verify browser compatibility before initializing the SDK:
Card fields
Card fields let you embed inline card input components on your page for credit and debit card payments. Card fields keep buyers on your page for the entire payment experience. Card data flows through PayPal-hosted iframes, so your site never handles raw card numbers.card-fields component. Check eligibility using paymentMethods.isEligible("advanced_cards") before rendering the fields. For PCI compliance requirements, see PCI DSS SAQ A-EP.sdkInstance.createCardFieldsOneTimePaymentSession()
Create a card fields session for a one-time payment. The session provides methods to create individual card input components and submit the payment.
Returns
Returns aCardFieldsOneTimePaymentSession object with createCardFieldsComponent(options) and submit(orderId, options?) methods.
sdkInstance.createCardFieldsSavePaymentSession()
Create a card fields session for saving a card payment method (vaulting) for future use. The session behaves the same as the one-time session.
cardSession.createCardFieldsComponent(options)
Create an individual card field input component. The method returns an HTMLElement that you append directly to a DOM container.
Parameters
| Parameter | Required | Description |
|---|---|---|
type | yes | string. The card field to render. Values:
|
placeholder | no | string. Placeholder text shown inside the field when empty, for example, |
style | no | object. CSS styles applied within the PayPal-hosted iframe. See Card field styling. |
Returns
Returns anHTMLElement. Mount it to a container using appendChild() or equivalent.
cardSession.submit(orderId, options?)
Submit the card payment. This validates the card data, runs 3D Secure (3DS) authentication if required, and returns the payment outcome.
Parameters
| Parameter | Required | Description |
|---|---|---|
orderId | yes | string. The PayPal order ID created on your server. Pass the string directly — do not pass an object such as . |
options.billingAddress | no | object. Billing address fields to include with the payment for risk and SCA purposes. Include at minimum the fields your risk strategy requires. Available fields: |
Returns
Returns a promise that resolves to{ data, state }:
| State | Description |
|---|---|
succeeded | Payment succeeded. data.orderId is the order ID to capture. data.liabilityShift indicates 3DS outcome. |
canceled | Buyer dismissed the 3D Secure modal. Display a non-blocking message and allow the buyer to retry. |
failed | Validation or processing failure. data.message may contain details. Show an error and allow retry. |
Card field styling
Pass astyle object to createCardFieldsComponent() to customize card field appearance. Styles are applied within the PayPal-hosted iframe.
Supported CSS selectors
| Selector | When it applies |
|---|---|
input | The card input element |
.invalid | Applied when the field value fails validation |
:focus | Applied when the field has keyboard focus |
Supported CSS properties
appearancebackgroundborderborderRadiusboxShadowcolordirectionfontfontFamilyfontSizefontSizeAdjustfontStretchfontStylefontVariantfontVariantAlternatesfontVariantCapsfontVariantEastAsianfontVariantLigaturesfontVariantNumericfontWeightheightletterSpacinglineHeightopacityoutlinepaddingpaddingBottompaddingLeftpaddingRightpaddingToptextShadowtransition
Example
Full card fields example
Guest payments
Guest payments render a PayPal-hosted card form without requiring the buyer to create or log in to a PayPal account. The card form appears as an overlay on your page, handling card input and validation inside a PayPal-hosted environment.paypal-guest-payments component. Use the <paypal-basic-card-button> web component to trigger the payment flow.sdkInstance.createPayPalGuestOneTimePaymentSession(options)
Create a guest payment session for one-time card payments. This session manages the full card collection and payment authorization flow.
Parameters
| Parameter | Required | Description |
|---|---|---|
onApprove | yes | function(data). Called when the payment is approved. Capture the order using |
onComplete | yes | function(data). Called after |
onCancel | no | function(data). Called when the buyer closes the card form without completing payment. |
onError | no | function(error). Called when an unrecoverable error occurs. The error object contains |
onWarn | no | function(data). Called when the buyer encounters a recoverable error after submitting the card form — for example, a card decline, name formatting error, or invalid address. The overlay stays open so the buyer can correct and retry. The data object contains:
|
onShippingAddressChange | no | function(data). Called when the buyer changes their shipping address. See |
onShippingOptionsChange | no | function(data). Called when the buyer selects a different shipping option. See |
Returns
Returns a guest payment session object with astart(options, orderPromise) method.
start(options, orderPromise) parameters
| Parameter | Required | Description |
|---|---|---|
options.presentationMode | no | string. How the card form overlay is displayed. Values: auto (default), modal, popup, redirect. |
options.targetElement | no | HTMLElement. The element that triggered the session, used for overlay positioning. |
orderPromise | yes | Promise. A promise that resolves to { orderId: string }. |