PayPal Checkout Button based on REST API 2018

Azeem Shah
May 11 · 2 min read

Hello Developers,

Let’s go through PayPal’s Express checkout with new PayPal pay button that is based on REST API’s and popup payment checkout.

The new express checkout button allows to pay via PayPal (or given cards) without leaving the website. It is a smart payment button that dynamically present the most relevant payment methods for each customer in each geography.

More info:

There are many ways to integrate it, however I implemented the Server Side Integration. So we’ll go with that in this tutorial.

To meet the Prerequisites, you need to create a test sandbox account, make an app and get ClientID & Secret key.

You can find the documentation of this tutorial below:



The implementation can be broken down in 3 main steps:

1. Javascript code to render PayPal Pay button.

2. Create payment

3. Execute payment

1. To render the PayPal button in your webpage simply copy the Javascript code and PayPal payment button will appear.

2. The Create Payment (or Set up the payment) is called when buyer clicks the button. It calls the payment (callback function) with the requested server url.

At the backend (controller side) you need to initialise(create) the payment (using cURL or SDK) and in response it returns the Payment ID ( for that transaction.

I implemented this in PHP using curl. So basically you need to hit 2 curls

1. To generate access token

Sandbox link:

Live link:


2. To Create a sale

Sandbox link:

Live link:


Return the response of this curl from from controller to Javascript success(like ajax) as it contains the paymentID.

3. Now the amount to be paid will appear. It is time to execute this payment with the paymentID & payerID. On successful execution of the payment, PayPal will give success in response and you can notify your use that payment was successful.

In Execute payment also you need to hit 2 curls

1. To generate access token (details already mentioned above)

2. To Execute approved PayPal payment

Sandbox link:{paymentID}/execute

Live link:{paymentID}/execute


Azeem Shah

Written by

Software Engineer | Programming & Technology enthusiast | Reader | CS:GO Gamer | Movies-TV Series buff

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade