Standard payments with single-page applications
Last updated: Apr 26th, 6:44pm
Use this guide if your integration uses a single-page application to accept payments, built on a library or framework such as React, Vue, or Angular.
Know before you code
Standard Checkout
This feature modifies an existing Standard Checkout integration and uses the following:
- JavaScript SDK: Adds PayPal-supported payment methods.
- Orders REST API: Create, update, retrieve, authorize, and capture orders.
You need a developer account to get sandbox credentials
PayPal uses the following REST API credentials, which you can get from the developer dashboard:
- Client ID: Authenticates your account with PayPal and identifies an app in your sandbox.
- Client secret: Authorizes an app in your sandbox. Keep this secret safe and don't share it.
Explore PayPal APIs with Postman
You can use Postman to explore and test PayPal APIs. Learn more in our Postman guide.
Add JavaScript SDK
The JavaScript SDK shows your payer's available payment methods on your checkout page.
Set up the PayPal checkout for your application by using the JavaScript SDK and handling the payer's interactions with the PayPal checkout button. Place the following script
tag in your index.html
page based on how you plan to render payment buttons, so the paypal
object is available when you need it in the checkout flow. You can render the payment buttons either immediately, or after user action, navigation, or other page change:
Sample request for Immediate
1<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID">2</script>
Sample request for On change
1<script defer src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID">2</script>
Modify the code
Copy the sample request and modify it as follows:
- Copy the sample JavaScript SDK code and paste it into your checkout page.
- In the SDK code, replace
YOUR_CLIENT_ID
with your client ID. - Pass parameters to replace default values, such as
USD
forcurrency
. To learn more about the default values, see the JavaScript SDK script configuration.