Skip to main content
This guide demonstrates how to integrate PayPal save payment functionality using the JavaScript SDK v6, allowing customers to securely save their PayPal payment methods for future transactions without making an immediate purchase. The PayPal Save Payment integration enables you to:
  • Collect and securely store PayPal payment methods without charging the customer
  • Create payment tokens for future use in subsequent transactions
  • Provide a streamlined checkout experience for returning customers
  • Maintain PCI compliance by leveraging PayPal’s secure vault system

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 Client ID and Secret
  • Ensure your application has Vault permissions enabled
Enable vaulting:
  1. Log in to the Developer Dashboard.
  2. Under REST API apps, select your app name.
  3. Under Sandbox App Settings > App Feature Options, check Accept payments.
  4. Expand Advanced options. Confirm that Vault is selected.
Configure your environment: In your root folder, create an .env file with your PayPal credentials:

Key concepts

Setup token vs payment token:
  • Setup Token: Temporary token used during the save payment flow
  • Payment Token: Permanent token stored in PayPal’s vault for future use
  • Conversion: Setup tokens are converted to payment tokens after customer approval
Payment flows:
  • VAULT_WITHOUT_PAYMENT: Save payment method without making a purchase
  • VAULT_WITH_PAYMENT: Save payment method while making a purchase
Usage patterns:
  • IMMEDIATE: Token will be used right away
  • DEFERRED: Token will be used at a future date

Integration flow

The PayPal save payment integration follows a specific flow:
  1. Initialize PayPal SDK with vault-specific configuration
  2. Check eligibility for save payment functionality
  3. Create setup token on your server
  4. Start save payment session to collect payment method
  5. Create payment token from vault setup token for future use

Set up your front end

Build an HTML page and a JavaScript file to set up your front end.

Build an HTML page

Initialize the SDK to save payment methods

Configure the payment session

Set up button to save payments

Set up your backend

The save payment integration requires these server-side endpoints:

Client Token endpoint

Create Setup Token endpoint

Create Payment Token endpoint

Set up token creation on your server

On your server, create a setup token for vault operations:

Set up Payment Token creation on your server

Convert the vault setup token to a reusable payment token:

Use saved payment tokens

Once you have a payment token, you can use it for future transactions:

Create order with saved payment methods

Create a server-side order with a vault ID

Advanced Features

The following code samples demonstrate how to configure a custom setup token and manage payment tokens.

Configure custom setup token

Manage payment token

Error handling

Security best practices

Follow best practices for client and server-side security.

Client-side security

Server-side security

Integration patterns

Common integration patterns include checkout with a save payment option and customer payment method management.

Checkout with save payment option

Manage customer payment methods

Test

Use PayPal sandbox accounts for testing:
  • Create test business and personal accounts
  • Test with different countries and currencies
  • Verify vault permissions are enabled
Test the following scenarios:
  1. Successful Save: Complete save payment flow successfully
  2. User Cancellation: Test cancellation handling
  3. Network Errors: Simulate network failures
  4. Invalid Tokens: Test with expired or invalid setup tokens
  5. Multiple Saves: Test saving multiple payment methods
  6. Token Usage: Test using saved tokens for payments

Production checklist

  • Replace sandbox URLs with production URLs
  • Update environment configuration for production
  • Verify vault permissions are enabled in production
  • Implement secure payment token storage
  • Add comprehensive error handling
  • Set up monitoring and alerting
  • Test payment token usage workflows
  • Implement token lifecycle management
  • Add customer payment method management UI
  • Verify PCI compliance requirements
  • Test across different browsers and devices
  • Implement proper authentication and authorization

Technical limitations

  • Setup tokens have limited lifetime (typically 3 hours)
  • Payment tokens are specific to the merchant account
  • Vault functionality requires special permissions
  • Not all payment methods support vaulting

Business considerations

  • Consider customer consent and privacy regulations
  • Implement proper data retention policies
  • Provide clear opt-in/opt-out mechanisms
  • Handle payment method updates and expiration

Resources

Support

For additional support and questions: