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
.env
file with your PayPal credentials:
Integration overview
The PayPal one-time payments integration supports multiple payment methods:- PayPal - Standard PayPal payments
- Pay Later - Buy now, pay later financing options
- PayPal Credit - Credit-based payment option
- Initialize the SDK with payment components
- Check eligibility for each payment method
- Create payment sessions with callback handlers
- Start payment flow with presentation mode configuration
Set up your front end
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
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:Auto mode (recommended)
- Automatically selects the best presentation mode
- Tries popup first, falls back to modal if popups are blocked
- Best for most use cases
Popup mode
- Opens PayPal in a popup window
- Provides seamless user experience
- May be blocked by popup blockers
Modal mode
- 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.1. Client Token endpoint
Get a client token to call the Orders API for checkout.2. Create Order endpoint
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.3. Capture Order endpoint
After a buyer authorizes payment, capture an order to transfer funds from the buyer to the merchant account.Handle errors
Best practices
Keep sensitive operations server-side, validate all payment data, and 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:- Visit the PayPal Developer Community
- Check PayPal Developer Documentation