Node JS – Integrate Stripe Payment Gateway in Express JS

One of the obvious reason to love stripe is, it is pretty easy to integrate and nowadays it is the most popular one. You can create a Stripe account via stripe registration page, which you can use for both testing and production, both version will contain different app key and secret key, make sure to update those keys before deploying your application to production.

Stripe is responsible for processing and keeping client’s credit/debit card data so no information of essence would be stored on your server and you would not have to comply with all the rules that come with storing credit/debit cards.

Stripe integration steps

Step 1:
Create account on https://dashboard.stripe.com/register
stripe create account

Step 2:
Now login to your account and go to APIs page (left menu item). From here grab you api keys.
stripe account page

Step 3:
Create project directory and install required dependencies with below shown commands.

  • mkdir express-stripe-demo – it will crate a folder called “express-stripe-demo
  • cd express-stripe-demo – changing directory to “express-stripe-demo
  • npm init --yes – will create package.json file under the current directory
  • npm install --save express body-parser pug stripe – it will download all mentioned modules into node_modules directory

What do these packages do?

  • express is the Node framework.
  • body-parser will let us pull POST content from our HTTP request.
  • pug is the template engine
  • stripe is payment gateway library

Now lets setup application, create file called server.js with below code, go though the comments of the code for better understanding.

Now lets create view files to accept payment and to show the status of the translation

Start your sever with below command, you should able to access website at : http://localhost:3000/

After successful payment you should able to see below output –

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.