Node.js Express Paypal REST API SDK Payment Gateway Integration Full Example with Source Code 2020

You are currently viewing Node.js Express Paypal REST API SDK Payment Gateway Integration Full Example with Source Code 2020

 

Welcome folks today in this blog post we will be integrating the paypal payment gateway inside our node.js express application using the paypal rest api sdk. All the source code of the application is given below. A step by step youtube video is also shown below.

 

 

 

 

 

Live Demo

 

 

You can check out the Live Demo of the App here

 

 

Get Started

 

 

In order to get started you need to install these dependencies inside your node.js project which are listed below

 

npm i express

 

npm i nodemon

 

npm i paypal-rest-sdk

 

Install all these dependencies inside your node.js project and create your index.js file for your node.js project ad copy paste the below code to it

 

 

 

 

 

Here in this block of code we need to replace the client-id and the client-secret of the paypal like this

 

 

 

 

 

Just replace your client-id and client-secret from your paypal dashboard inside the application. But in order to get this you need to create a business account on paypal. We can create fake sandbox accounts on paypal

 

Go to Paypal Developer website and create a sandbox account like this

 

 

 

 

 

 

 

 

 

 

 

 

 

 

index.html

 

 

 

 

 

 

 

 

So we have the buy button here inside the app. When we click this button a post request will be made to the route /pay so we need to make this route like this

 

 

 

 

 

Basically here in this block of code we have made the json object containing all the properties which is required for the transaction so now we need to make the routes for the success callback and also the cancel callback events like this

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DOWNLOAD SOURCE CODE

 

 

Leave a Reply