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 rupixen.com on Unsplash

Introduction

Let’s build the app

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<title>Paytm-Nodejs</title>
</head>
<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>
<div class="form-group">
<label for="">Email: </label>
<input class="form-control" type="text" name="email" value="">
</div>
<div class="form-group">
<label for="">Phone: </label>
<input class="form-control" type="text" name="phone" value="">
</div>
<div class="form-group">
<label for="">Amount: </label>
<input class="form-control" type="text" name="amount" value="">
</div>
<div class="form-group">
<button class="btn form-control btn-primary">Pay Now</button>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>

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}` );
})
app.post('/paynow', (req, res) => {
// Route for making payment
})
app.post('/callback', (req, res) => {
// Route for verifiying payment
})
config.jsvar PaytmConfig = {
mid: "XXXXXXXXXXXXXXXXXXXX",
key: "XXXXXXXXXXXXXXXX",
website: "XXXXXXXXXX"
}
module.exports.PaytmConfig = PaytmConfig
const https = require('https')
const qs = require('querystring')
// Middleware for body parsing
const
parseUrl = express.urlencoded({ extended: false })
const parseJson = express.urlencoded({ extended: false })
const checksum_lib = require('../paytm/checksum')
const config = require('../paytm/config')
app.post('/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