Integrate Paytm payment gateway using Node.js

Note: This is an HTML form post integration method and it has been deprecated by Paytm. The flow is available for only existing integrations. Please follow this post for the updated payment gateway integration method.

Photo by on Unsplash


Let’s build the app

<!DOCTYPE html>
<html lang="en" dir="ltr">
<meta charset="utf-8">
<link rel="stylesheet" href="" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<body style="background-color:#f5f3ef">
<div class="row my-5">
<div class="col-md-4 offset-md-4">
<div class="card">
<div class="card-body">
<form class="" action="/paynow" method="post">
<div class="form-group">
<label for="">Name: </label>
<input class="form-control" type="text" name="name" value="">
<div class="form-group">
<label for="">Email: </label>
<input class="form-control" type="text" name="email" value="">
<div class="form-group">
<label for="">Phone: </label>
<input class="form-control" type="text" name="phone" value="">
<div class="form-group">
<label for="">Amount: </label>
<input class="form-control" type="text" name="amount" value="">
<div class="form-group">
<button class="btn form-control btn-primary">Pay Now</button>

Let’s build the backend

  • One for making transaction
  • Other for receiving the transaction response/callback response from Paytm.
index.jsconst express = require('express')
const path = require('path')
const app = express()
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname + '/index.html'))
const port = 3000
app.listen(port, () => {
console.log(`Server listening on port ${port}` );
})'/paynow', (req, res) => {
// Route for making payment
})'/callback', (req, res) => {
// Route for verifiying payment
config.jsvar PaytmConfig = {
website: "XXXXXXXXXX"
module.exports.PaytmConfig = PaytmConfig
const https = require('https')
const qs = require('querystring')
// Middleware for body parsing
parseUrl = express.urlencoded({ extended: false })
const parseJson = express.urlencoded({ extended: false })
const checksum_lib = require('../paytm/checksum')
const config = require('../paytm/config')'/paynow', [parseUrl, parseJson], (req, res) => {
// Route for making payment

Wrapping Up

 by the author.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store