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: https://developer.paypal.com/docs/checkout/
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:
2. Create payment
3. Execute payment
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 (res.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: https://api.sandbox.paypal.com/v1/oauth2/token
Live link: https://api.paypal.com/v1/oauth2/token
2. To Create a sale
Sandbox link: https://api.sandbox.paypal.com/v1/payments/payment/
Live link: https://api.paypal.com/v1/payments/payment/
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