Skip to main content

Your First Integration

Integrate PayPal Checkout to accept payments swiftly and securely. Whether you're building an HTML page or a dynamic React application, this guide helps you get up and running.

Overview

PayPal Checkout leverages the Orders v2 API to create and manage transactions. By integrating PayPal Checkout, you provide users with a seamless payment experience using their PayPal accounts.

Prerequisites

Ensure you have the following:

HTML is ideal for static websites or quick prototypes.

1. Add the PayPal script

<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID"></script>

Replace YOUR_CLIENT_ID with your sandbox client ID.

2. Add PayPal buttons

<div id="paypal-button-container"></div>

<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '10.00' // Replace with your amount
}
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('#paypal-button-container');
</script>

Next steps

After setting up the basic integration:

  • Test your integration with PayPal sandbox accounts.
  • Implement environment detection logic to determine if the environment is sandbox or production.
  • Move order creation and capture to your backend for enhanced security. Creating orders on the client side is only recommended for prototyping.
  • Integrate webhooks to monitor payment status and handle asynchronous events.

See also