Eligibility
This integration works everywhere PayPal is available.Prerequisites
- Create a PayPal developer account.
- Get a client ID and secret.
- (Optional) Enable negative testing in the developer dashboard:
- Go to Dashboard > Sandbox > Accounts.
- Select … on your sandbox business account and select View/Edit.
- Enable Negative Testing and save.
Create project structure
Choose your preferred language and set up the project structure.Set up back end
Choose your preferred language and copy the code into your server file:Set up front end
Open thepublic/index.html file in a code editor and copy and paste the following code. Replace YOUR_CLIENT_ID with the client ID created in the prerequisites.Set your client ID and secret
Open the.env file in a code editor and replace your_sandbox_client_id and your_sandbox_secret with the client ID and secret you created for your app in the prerequisites.Run the application locally
Start the server:Best practices
Use the following best practices to ensure secure, reliable, and maintainable integrations when building your checkout experience.- Start minimal and expand later: This code works in production. Add features as needed.
- Use environment variables: Never hardcode credentials. Keep the .env file out of Git.
- Create orders on the server: Never create orders in the browser due to security risks. Always use the server.
- Test in sandbox first: Use sandbox accounts to test payments before going live.
- Store transaction IDs: Save capture IDs for refunds, disputes, and record keeping.
Test your integration
Before testing, make sure you have sandbox account credentials for both buyer and seller roles. Get sandbox account credentials.Standard testing
Use the following standard test scenarios to verify your checkout handles key outcomes.Negative testing
Negative testing works only in sandbox mode. It is automatically disabled whenNODE_ENV=production.For negative testing:- Make sure to enable negative testing in your sandbox business account as described in the prerequisites.
- In the
.envfile, setENABLE_NEGATIVE_TESTING=trueand setNEGATIVE_TEST_TYPEto one of the error codes in the table. - Restart the server after changing the
.envfile:node server.js.
Go-live checklist
- Test all scenarios in the sandbox.
- In the
.envfile:- Comment out the development section.
- Uncomment the production section.
- Update HTML client ID to production.
- Add the HTTPS certificate.
- Test with real $1 transaction.
- Verify funds are received in your PayPal account.
Post-launch monitoring
These values are suggested monitoring thresholds for your integration, not performance guarantees from PayPal.References
Next steps
The following use cases are common next steps after completing this quick start.- Refund a payment: Process returns using capture IDs.
- Void an authorization: Cancel an order before capture.