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 (e.g., “USD”, “EUR”, “GBP”). This affects payment method availability, especially for Pay Later options which have currency restrictions. Default: |
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 (e.g., “99.99”). The amount affects Pay Later eligibility, as different financing options have minimum and maximum amount thresholds. |
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 clicking 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 (e.g., standard vs. 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: |
Returns
Returns a PaymentSession 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.createGooglePayOneTimePaymentSession()
Create a session for Google Pay. Google Pay sessions have a different flow that integrates with the Google Pay API.
Returns
Returns a GooglePaySession object with specialized methods for Google Pay integration.sdkInstance.createApplePayOneTimePaymentSession()
Create a session for Apple Pay. Apple Pay sessions integrate with the browser’s Payment Request API on supported devices.
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. |
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 explicitly click 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.
Parameters
| Property | Type | Description |
|---|---|---|
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 (e.g., standard vs. express delivery). Use this to update the order total with the selected shipping cost.
Parameters
| Property | Type | Description |
|---|---|---|
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 click 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 (e.g., “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: