- 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
- Log in to the Developer Dashboard.
- Under REST API apps, select your app name.
- Under Sandbox App Settings > App Feature Options, check Accept payments.
- Expand Advanced options. Confirm that Vault is selected.
.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
- VAULT_WITHOUT_PAYMENT: Save payment method without making a purchase
- VAULT_WITH_PAYMENT: Save payment method while making a purchase
- 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:- Initialize PayPal SDK with vault-specific configuration
- Check eligibility for save payment functionality
- Create setup token on your server
- Start save payment session to collect payment method
- 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
- Successful Save: Complete save payment flow successfully
- User Cancellation: Test cancellation handling
- Network Errors: Simulate network failures
- Invalid Tokens: Test with expired or invalid setup tokens
- Multiple Saves: Test saving multiple payment methods
- 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
- PayPal Payment Method Tokens (vault) API reference
- PayPal Developer Dashboard
- PCI Compliance Guidelines
Support
For additional support and questions:- Visit PayPal Developer Community
- Check PayPal Developer Documentation
- Review the complete implementation in
./client/components/paypalPayments/savePayment/html/