Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
How to Integrate Paypal in Node ?
Next article icon

How to Integrate Stripe Payment Gateway in Node.js ?

Last Updated : 24 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Integrating Stripe in Node allows one to make and manage online payments. Stripe provides developer-friendly API to set up the payment gateway to handle secure transactions.

Payment gateways help the user to make their payments. There are many payment gateways available in the market like Razorpay, Google Pay, etc but the most popular among them is the Stripe payment gateway. Stripe is the premier option for online credit card processing and it is also the most popular premium payment gateway. 

  1. It’s easy to get started and easy to use.
  2. It is a widely used and popular module for processing payments.
  3. User-friendly services and highly secured.

Approach

To integrate Stripe Payment Gateway in Node we will install the Stripe package as a project dependency. Then, we set up environment variables for authentication, and API endpoints for processing payments, and handled the transactions.

Steps to Setup Stript Payment Gateway in Node

Step 1: Initialize a Node Project

Use this command to create a node project in the same folder

npm init

Step 2: Install Stripe Module

You can visit the link Install stripe module. You can install this package by using this command.

npm install stripe

Step 3: Verify the Installation

After installing stripe module, you can check your stripe version in command prompt using the command.

npm version stripe

Step 4: Install other required modules

npm install ejs express body-parser

Project Structure:

Project-structure---payment-gateway-in-node

project structure

Step 5: Import Stripe

You need to include stripe module in your file by using these lines.

const stripe = require('stripe')('Your_Secret_Key');

To get your secret key, simply go to Stripe Official Website and create an account, then you can get your secret key as well as the publishable key. 

HTML
<!-- Filename - Home.ejs -->  <!DOCTYPE html> <html> <title>Stripe Payment Demo</title> <body>     <h3>Welcome to Payment Gateway</h3>     <form action="payment" method="POST">        <script            src="//checkout.stripe.com/v2/checkout.js"           class="stripe-button"           data-key="<%= key %>"           data-amount="2500"           data-currency="inr"           data-name="Crafty Gourav"           data-description="Handmade Art and Craft Products"           data-locale="auto" >         </script>     </form> </body> </html> 
JavaScript
// Filename - index.js  const express = require("express"); const bodyparser = require("body-parser"); const path = require("path"); const app = express();  const Publishable_Key = "Your_Publishable_Key"; const Secret_Key = "Your_Secret_Key";  const stripe = require("stripe")(Secret_Key);  const port = process.env.PORT || 3000;  app.use(bodyparser.urlencoded({ extended: false })); app.use(bodyparser.json());  // View Engine Setup app.set("views", path.join(__dirname, "views")); app.set("view engine", "ejs");  app.get("/", function (req, res) { 	res.render("Home", { 		key: Publishable_Key 	}); });  app.post("/payment", function (req, res) { 	// Moreover you can take more details from user 	// like Address, Name, etc from form 	stripe.customers 		.create({ 			email: req.body.stripeEmail, 			source: req.body.stripeToken, 			name: "Gourav Hammad", 			address: { 				line1: "TC 9/4 Old MES colony", 				postal_code: "452331", 				city: "Indore", 				state: "Madhya Pradesh", 				country: "India" 			} 		}) 		.then((customer) => { 			return stripe.charges.create({ 				amount: 2500, // Charging Rs 25 				description: "Web Development Product", 				currency: "INR", 				customer: customer.id 			}); 		}) 		.then((charge) => { 			res.send("Success"); // If no error occurs 		}) 		.catch((err) => { 			res.send(err); // If some error occurs 		}); });  app.listen(port, function (error) { 	if (error) throw error; 	console.log("Server created Successfully"); }); 

Steps to run the program

Run index.js file using below command

node index.js

Output of above command

Open browser and type this URL

http://localhost:3000/

Then you will see the Payment Gateway form as shown below  

Payment Demo Form

Then click on ‘Pay with Card’ button and then you will see the stripe payment form as shown belowStripe payment form Fill this form with correct credit card details and click on ‘Pay’ button and then if no errors occur, then the following message will be displayedSuccess Message

Now go to your stripe dashboard and you can see the current payment details as shown belowStripe Dashboard

So this is how you can integrate Stripe payment gateway in node.js. There are other payment gateways available in the market like Razorpay, Google Pay, etc.



Next Article
How to Integrate Paypal in Node ?
author
gouravhammad
Improve
Article Tags :
  • JavaScript
  • Node.js
  • Web Technologies
  • Write From Home
  • Node.js-Misc

Similar Reads

  • How to Integrate Paytm Test API in Node.js ?
    Paytm stands for Pay through mobile is used for online transactions. We can integrate it with our node.js application using Paytm developer API. This API can be used for testing as well as for development purposes.  There are two methods for doing so: Test API and Production API. Production API will
    2 min read
  • How to Integrate Paypal in Node ?
    In today's digital age, online payments have become an integral part of e-commerce and web applications. Among the myriad of payment gateways available, PayPal stands out as one of the most widely used and trusted platforms. Integrating PayPal into your Node.js application can streamline the payment
    5 min read
  • How to Integrate Stripe Payments in React App using Express ?
    Many of the projects you develop might have a requirement to integrate the payment module in your application. Stripe serves as a payment processing platform designed to help applications securely accept and handle online payments. In this article, we will see how we can easily integrate payment sys
    6 min read
  • Razorpay Payment Integration using Node.js
    Payment gateway is a technology that provides online solutions for money-related transactions, it can be thought of as a middle channel for e-commerce or any online business, which can be used to make payments and receive payments for any purpose. Sample Problem Statement: This is a simple HTML page
    15 min read
  • How to Integrate Browserify for Node.js ?
    Browserify is a powerful tool for front-end JavaScript development that allows you to use Node.js-style require statements in your browser code. By bundling up modules and resolving dependencies, Browserify enables a more modular and maintainable approach to JavaScript development. This guide will w
    4 min read
  • How to Pass Node.js Output to Web Interface ?
    Node.js is a versatile runtime that excels at building server-side applications. One of the common use cases is to pass the output from a Node.js server to a web interface, allowing users to interact with server-generated data in a browser. This article will walk you through the process of passing N
    2 min read
  • How to Install Express in a Node Project?
    ExpressJS is a popular, lightweight web framework for NodeJS that simplifies the process of building web applications and APIs. It provides a robust set of features for creating server-side applications, including routing, middleware support, and easy integration with databases and other services. B
    3 min read
  • How to Install Node.js and npm on Ubuntu?
    If you're developing JavaScript applications on Ubuntu, knowing how to install Node.js on Ubuntu is essential. Node.js is a powerful runtime environment that enables server-side scripting, while npm, the Node Package Manager, allows you to manage your project's dependencies easily. This guide will w
    7 min read
  • How To Create a Simple HTTP Server in Node?
    NodeJS is a powerful runtime environment that allows developers to build scalable and high-performance applications, especially for I/O-bound operations. One of the most common uses of NodeJS is to create HTTP servers. What is HTTP?HTTP (Hypertext Transfer Protocol) is a protocol used for transferri
    3 min read
  • How to install modules without npm in node.js ?
    We can install modules required for a particular project in node.js without npm, the recommended node package manager using yarn. Yarn is a wonderful package manager. Like npm, if you have a project folder with package.json containing all the required dependencies mentioned for the project, you can
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences