Skip to main content
This guide demonstrates how to integrate one-time payments using the JavaScript SDK v6 in your web application, including PayPal, Pay Later, and PayPal Credit options.

Prerequisites

Set up your PayPal account:
  • Create a PayPal developer, personal, or business account
  • Visit the PayPal Developer Dashboard
  • Create a sandbox application to obtain your Client ID and Secret
  • Ensure your application has permissions enabled for JavaScript SDK v6
In your project root folder, create a .env file with your PayPal credentials:

Integration overview

The PayPal one-time payment integration supports multiple payment methods:
  1. PayPal - Standard PayPal payments
  2. Pay Later - Buy now, pay later financing options
  3. PayPal Credit - Credit-based payment option
The integration consists of four main steps:
  1. Initialize the SDK with payment components
  2. Check eligibility for each payment method
  3. Create payment sessions with callback handlers
  4. Start payment flow with presentation mode configuration

Set up your frontend

This is the recommended approach for most implementations. It includes all payment methods with eligibility logic and automatic fallback handling.

Key components

The following are key components of the integration.

PayPal SDK Instance

  • Purpose: Main entry point for PayPal functionality
  • Components: Includes paypal-payments component
  • Authentication: Requires client token from server

Eligibility Check

  • Purpose: Determines available payment methods
  • Factors: User location, currency, account status, device type
  • Implementation: Always check before showing payment buttons

Payment Sessions

  • PayPal: Standard PayPal payments
  • Pay Later: Financing options with specific product codes
  • PayPal Credit: Credit-based payments with country-specific configuration

Web Components

  • <paypal-button>: Standard PayPal payment button
  • <paypal-pay-later-button>: Pay Later financing button
  • <paypal-credit-button>: PayPal Credit button

Build an HTML page

Build the JavaScript

Advanced

For advanced use cases, you can choose specific presentation modes and implement your own fallback logic by leveraging the isRecoverable error property.

Key difference between v6 and previous versions

For more control over order details:

Choose a presentation mode

The JavaScript SDK v6 supports multiple presentation modes:
  • Automatically selects the best presentation mode
  • Tries popup first, falls back to modal if popups are blocked
  • Best for most use cases
  • Opens PayPal in a popup window
  • Provides seamless user experience
  • May be blocked by popup blockers
  • Opens PayPal in an overlay modal
  • This is only recommended for Webview scenarios
  • Do not use in desktop web scenarios as this integration has limitations on cookies, which can affect user authentication

Redirect mode

  • Full-page redirect to PayPal
  • Best for mobile devices
  • Requires return/cancel URL configuration

Payment handler mode (experimental)

  • Uses the browser’s Payment Handler API
  • Modern browsers only
  • Provides native payment experience

Set up your backend

Set up your backend to call the following endpoints for one-time checkout with PayPal.

1. Get client token

Use the access_token value returned as the client token to initialize the v6 SDK. Use expires_in for any caching management on the server-side.
The following server-side endpoint returns the client token to your client application. Call this endpoint from your frontend:

2. Create order

Creating an order initializes a payment request and reserves the funds, but doesn’t transfer money. After the buyer authorizes an order, you capture the funds.
  • Replace YOUR_ACCESS_TOKEN with the one generated using your application credentials.
  • You can send the id value in the response back to the client (JavaScript) side.
  • The following example creates an order with 2 items and details, and includes the total amounts with shipping costs. For more details on order creations, see the Create order endpoint.
Call your server endpoint from the client side.

3. Capture order

After a buyer authorizes payment, capture an order to transfer funds from the buyer to the merchant account.
Then, call your server endpoint from the client side to capture the order:

Best practices

Keep sensitive operations server-side and validate all payment data. Provide clear feedback to users throughout the payment flow.

Security

  • Obtain client tokens from your secure server
  • Never expose PayPal client secrets in frontend code
  • All payment processing happens through PayPal’s secure servers
  • Never pass up item total from browser - this can be manipulated
  • Validate order details on your server before capture

User experience

  • Always check eligibility before showing payment buttons
  • Provide clear loading states during payment processing
  • Handle popup blockers gracefully with { presentationMode:auto }
  • Show appropriate error messages for different failure scenarios

Performance

  • Initialize the SDK early, but avoid blocking page load
  • Cache client tokens appropriately
  • Use presentation mode fallback strategies

Testing

  • Test across different browsers and devices
  • Verify popup blocker handling
  • Test all callback scenarios (approve, cancel, error)
  • Validate eligibility logic works correctly

Production checklist

  • Replace sandbox URLs with production URLs
  • Update environment configuration for production
  • Test eligibility on production environment
  • Implement comprehensive error handling
  • Add analytics and conversion tracking
  • Test across different devices and browsers
  • Implement proper loading and success states
  • Set up monitoring and alerting
  • Verify webhook endpoints are configured
  • Test order capture and fulfillment process

Support

For additional support and questions: