Prerequisites
Before beginning your integration, meet these requirements:- Create a PayPal Developer account.
- Create a PayPal app in the Apps & Credentials section of your account.
- Use the Sandbox environment for testing.
- Note your Client ID and Secret for server configuration.
Development setup
Before you run the integration locally, complete both server and client setup.Server set up
- Navigate to your demo directory and instal dependencies:
- Create environment configuration:
- Start the server:
http://localhost:8080
.
Client set up
- Navigate to the demo directory:
- Install dependencies:
- Start development server:
http://localhost:3000
.
Integration patterns
The v6 SDK supports a variety of standalone payment button integration flows. The following patterns help you tailor the user experience for different requirements.Standard button
Use the standard button implementation for payers to select a button to start the standalone payment button flow (Recommended).- File:
html/src/recommended/app.js
HTML setup
Auto-start on load
Use the auto-start on load integration to automatically initiate the standalone payment button.- File:
html/src/onload/app.js
Shipping callbacks
Use the shipping callback integration to handle address validation and shipping option changes.- File:
html/src/shipping/app.js
Sample order creation with shipping options
Implementation support functions
These helper functions allow the client to interact with your backend for token generation, order creation, and payment capture.Get client token
Create order
Capture order
Callback functions
Define the callback functions to handle key events during the standalone payment button flow, such as approvals, cancellations, and errors.Required callbacks
Start options
When starting a payment session, you can configure presentation mode.API endpoints
Your backend server must provide these endpoints:GET /paypal-api/auth/browser-safe-client-token
- Returns client token for SDK initializationPOST /paypal-api/checkout/orders/create-with-sample-data
- Creates PayPal order with sample dataPOST /paypal-api/checkout/orders/create
- Creates PayPal order with custom dataPOST /paypal-api/checkout/orders/{order-id}/capture
- Captures the authorized payment
Testing
See the steps for running and validating your integration.- Ensure both server and client are running.
- Navigate to the demo page.
- Use PayPal Sandbox test accounts.
- Test all three integration patterns:
- Standard button
- Auto-start on load
- Shipping callbacks
Best practices
- Error handling: Always wrap PayPal API calls in try-catch blocks.
- Eligibility check: Call
findEligibleMethods()
to determine available payment options. - Security: Never expose client secrets in frontend code, and use client tokens.
- User experience: Choose the most suitable presentation mode for your use case.
- Validation: Validate shipping callbacks if needed.
- Testing: Test thoroughly in PayPal Sandbox before going live.
Troubleshooting
Quick solutions for common issues:-
SDK load errors: Ensure the JavaScript SDK v6 script loads before
onPayPalWebSdkLoaded()
. - Client token issues: Verify server endpoints are running and accessible.
- Eligibility issues: Check that your standalone payments are enabled in PayPal app settings.
- CORS errors: Confirm proper CORS configuration between client and server.