SlideShare a Scribd company logo
1 of 34
Download to read offline
How to
Integrate
Paytm Payment
Gateway using
ReactJS in
Seven Easy
Steps
www.bacancytechnology.com
Introduction
01
Are you stuck with a requirement of
integrating a payment gateway into your
project? Are you aggressively looking for a
simple tutorial regarding the same? If yes,
this tutorial: Integrate Paytm payment
gateway using ReactJs is for you! In this
step-by-step guide, we will learn how to
implement a payment gateway in seven
easy steps. So, without further ado, let’s get
started with our tutorial.
02
Tutorial Goal:
Integrate
Paytm
Payment
Gateway
using ReactJS
03
You might be wondering what we are going
to do in this tutorial. We will build a small
demo application consisting of a button
‘Pay Now’. With the click of the button a
modal will be displayed as shown below.
The library allows you to customize the
modal and add various payment methods
the way you want.
04
Create a new
Paytm
developer
account
05
We would need to create new secret keys by
creating a new developer account.


Go to https://developer.paytm.com/, login if
you are already a Paytm user, or you can
create a new account.
06
Collect the
API keys
07
Once you are logged in successfully, you can
directly go to Dashboard and check the Test
API Details. Feel free to test the APIs using
the test API keys.
08
Create a
ReactJS
Application
09
Use the following command to create a new
reactJs application.










A new project would be created with the
default folder structure as shown below.
create-react-app < app - name >
10
Adding the
scripts to
index.html
11
Hire ReactJS developer from us to
add varied skillset to your existing
in-house development. We can help
you develop next-gen web solution
from ideation to development to
final delivery
< script type=”text/javascript”
crossorigin=”anonymous”
src=”https://securegw-
stage.paytm.in/merchantpgpui/checkoutjs/
merchants/.js” >< /script >
You need to link the Paytm library using the
script tag in public/index.html file. For that
use the below snippet.




12
Logic & UI:
Paytm
Payment
Integration
13
Create a new file paytmButton.js inside
/paytm-button folder. This file will contain
the main logic and functionality for the
Paytm payment integration using ReactJS.


The user interface would have a “Pay Now”
button that will trigger the Paytm checkout
modal.


Create a new function initializePaytm() that
will contain all the initialization
configurations and token generation steps
that will be triggered on page load using
useEffect.
useEffect(() => {
initialize();
}, []);
14
The initializePaytm() function will make use
of the Paytm checksum file and it will
generate a token.
const initialize = () => {
let orderId = "Order_" + new
Date().getTime();
// Sandbox Credentials
let mid = ""; // Merchant ID
let mkey = ""; // Merchant Key
var paytmParams = {};
paytmParams.body = {
requestType: "Payment",
mid: mid,
websiteName: "WEBSTAGING",
orderId: orderId,
callbackUrl:
"https://merchant.com/callback",
txnAmount: {
value: 100,
currency: "INR",
},
15
userInfo: {
custId: "1001",
},
};
PaytmChecksum.generateSignature(
JSON.stringify(paytmParams.body),
mkey
).then(function (checksum) {
console.log(checksum);
paytmParams.head = {
signature: checksum,
};
var post_data =
JSON.stringify(paytmParams);
var options = {
/* for Staging */
// hostname: "securegw-stage.paytm.in"
/* for Production */,
hostname: "securegw.paytm.in",


16
port: 443,
path: `/theia/api/v1/initiateTransaction?
mid=${mid}&orderId=${orderId}`,
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": post_data.length,
},
};
var response = "";
var post_req = https.request(options,
function (post_res) {
post_res.on("data", function (chunk) {
response += chunk;
});
post_res.on("end", function () {
console.log("Response: ", response);
// res.json({data: JSON.parse(response),
orderId: orderId, mid: mid, amount:
amount});
setPaymentData({
17
...paymentData,
token:
JSON.parse(response).body.txnToken,
order: orderId,
mid: mid,
amount: 100,
});
});
});
post_req.write(post_data);
post_req.end();
});
};
18
Explanation
19
This method is called on page load
which will return a transaction token
from Paytm which will be later used for
initiating the Paytm checkout modal.
To retrieve the token, we will make an
API call to
/theia/api/v1/initiateTransaction which
will expect a basic transaction object in
the request body along with a hashed
value created using the transaction
object. The paytmParam.body is a
transaction object with basic fields like
orderId, value, and currency.
paytmParams.body = { ... };
20
A hash value should be using this
transaction object. For that Paytm
provides a library – PaytmChecksum
using which we can generate a hashed
value by passing the transaction object
as arguments.
This hash value will be sent along with
the transaction object in the
initiateTransaction API and will provide
the transaction token in response. Later
this token will be used when the user
clicks on the ‘Pay Now’ button and will
be helpful for triggering the payment
checkout modal.
PaytmChecksum.generateSignature(
JSON.stringify(paytmParams.body),mkey
).then(function(checksum){ ... // logic }
21
Create a new function makePayment() that
will be triggered on click of the button,
which will use the already generated token
and display the checkout modal to the user.
In this function, you can modify the style of
the Paytm checkout modal and change the
color code and add your logo.


const makePayment = () => {
var config = {
"root":"",
"style": {
"bodyBackgroundColor": "#fafafb",
"bodyColor": "",
"themeBackgroundColor":
"#0FB8C9",
"themeColor": "#ffffff",
"headerBackgroundColor": "#284055",
"headerColor": "#ffffff",
"errorColor": "",
"successColor": "",
22
"card": {
"padding": "",
"backgroundColor": ""
}
},
"data": {
"orderId": paymentData.order,
"token": paymentData.token,
"tokenType": "TXN_TOKEN",
"amount": paymentData.amount /*
update amount */
},
"payMode": {
"labels": {},
"filter": {
"exclude": []
},
23
"order": [
"CC",
"DC",
"NB",
"UPI",
"PPBL",
"PPI",
"BALANCE"
]
},
"website": "WEBSTAGING",
"flow": "DEFAULT",
"merchant": {
"mid": paymentData.mid,
"redirect": false
},
"handler": {
"transactionStatus":
function transactionStatus(paymentStatus){
console.log(paymentStatus);
},
24
"notifyMerchant":
function notifyMerchant(eventName,data){
console.log("Closed");
}
}
};
if (window.Paytm &&
window.Paytm.CheckoutJS) {
window.Paytm.CheckoutJS.init(config).
then(function onSuccess() {
window.Paytm.CheckoutJS.invoke();
}).catch(function onError(error) {
console.log("Error => ", error);
});
}}
25
Call the makePayment() method on click
event of the button.




return (
< div >
{loading ? (
< img src="https://c.tenor.com/I6kN-
6X7nhAAAAAj/loading-buffering.gif" / >
) : (
< button onClick={makePayment}>Pay
Now< /button >
)}
< /div >
);
26
Import
PaytmButton
in App.js
27
Once we are done with the main logic
implementation it’s time to import the file
into App.js.


import "./App.css";
import { PaytmButton } from "./paytm-
button/paytmButton";
function App() {
return (
< div >
< PaytmButton / >
< /div >
);
}
export default App;
28
Run the
Server
29
So, finally, we are done with the tutorial:
How to Integrate Paytm Payment Gateway
using ReactJS. Now using the below
command, run your server.


npm start




Visit http://localhost:3000/ and test the
demo app.
The entire source code is available on the
github repo: paytm-payment-gateway-
integration. Feel free to clone the repository
and play around with the code.
30
Conclusion
31
I hope the tutorial has helped you learn how
to integrate Paytm payment gateway using
ReactJS. We value your feedback and
suggestions, so feel free to write back. Our
team is trying to explore and add more such
topics to ReactJS tutorials. If you are a
ReactJS enthusiast, visit the ReactJS
tutorials page without wasting your time,
clone the github repository, and polish your
technical side.
32
Thank You
www.bacancytechnology.com

More Related Content

What's hot

Online Library Management
Online Library ManagementOnline Library Management
Online Library ManagementVarsha Sarkar
 
Computer shop billing system
Computer shop billing systemComputer shop billing system
Computer shop billing systemMayur Solanki
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design PatternsGodfrey Nolan
 
Introduction to Android Fragments
Introduction to Android FragmentsIntroduction to Android Fragments
Introduction to Android FragmentsSergi Martínez
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practicesIwan van der Kleijn
 
MySQL USER MANAGEMENT,ROUTINES & TRIGGERS.
MySQL USER MANAGEMENT,ROUTINES & TRIGGERS.MySQL USER MANAGEMENT,ROUTINES & TRIGGERS.
MySQL USER MANAGEMENT,ROUTINES & TRIGGERS.Prabhu Raja Singh
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass SlidesNir Kaufman
 
Session12 J2ME Generic Connection Framework
Session12 J2ME Generic Connection FrameworkSession12 J2ME Generic Connection Framework
Session12 J2ME Generic Connection Frameworkmuthusvm
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
Difference between authentication and authorization in asp.net
Difference between authentication and authorization in asp.netDifference between authentication and authorization in asp.net
Difference between authentication and authorization in asp.netUmar Ali
 
What is Material UI?
What is Material UI?What is Material UI?
What is Material UI?Flatlogic
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react formYao Nien Chung
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLJohn David Duncan
 

What's hot (20)

C++ super market
C++ super marketC++ super market
C++ super market
 
Online Library Management
Online Library ManagementOnline Library Management
Online Library Management
 
13 mongoose
13 mongoose13 mongoose
13 mongoose
 
Computer shop billing system
Computer shop billing systemComputer shop billing system
Computer shop billing system
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design Patterns
 
Introduction to Android Fragments
Introduction to Android FragmentsIntroduction to Android Fragments
Introduction to Android Fragments
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practices
 
Express js
Express jsExpress js
Express js
 
MySQL USER MANAGEMENT,ROUTINES & TRIGGERS.
MySQL USER MANAGEMENT,ROUTINES & TRIGGERS.MySQL USER MANAGEMENT,ROUTINES & TRIGGERS.
MySQL USER MANAGEMENT,ROUTINES & TRIGGERS.
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
Session12 J2ME Generic Connection Framework
Session12 J2ME Generic Connection FrameworkSession12 J2ME Generic Connection Framework
Session12 J2ME Generic Connection Framework
 
Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 
Master page in Asp.net
Master page in Asp.netMaster page in Asp.net
Master page in Asp.net
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Difference between authentication and authorization in asp.net
Difference between authentication and authorization in asp.netDifference between authentication and authorization in asp.net
Difference between authentication and authorization in asp.net
 
What is Material UI?
What is Material UI?What is Material UI?
What is Material UI?
 
Atm
AtmAtm
Atm
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQL
 
React JS - Introduction
React JS - IntroductionReact JS - Introduction
React JS - Introduction
 

Similar to Integrate Paytm Payment Gateway in React Apps in 7 Steps

java and javascript api dev guide
java and javascript api dev guidejava and javascript api dev guide
java and javascript api dev guideZenita Smythe
 
Razorpay payment gateway integration in laravel and vue js 2
Razorpay payment gateway integration in laravel and vue js 2Razorpay payment gateway integration in laravel and vue js 2
Razorpay payment gateway integration in laravel and vue js 2Katy Slemon
 
Paytm integration in swift
Paytm integration in swiftPaytm integration in swift
Paytm integration in swiftInnovationM
 
Razorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftRazorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftInnovationM
 
June2013 Meetup : In-App Billing by Soham & Senthil
June2013 Meetup : In-App Billing by Soham & SenthilJune2013 Meetup : In-App Billing by Soham & Senthil
June2013 Meetup : In-App Billing by Soham & SenthilBlrDroid
 
Abandoned carts
Abandoned cartsAbandoned carts
Abandoned cartsNetmera
 
How to build twitter bot using golang from scratch
How to build twitter bot using golang from scratchHow to build twitter bot using golang from scratch
How to build twitter bot using golang from scratchKaty Slemon
 
Barcelona Developers Conference 2011
Barcelona Developers Conference 2011Barcelona Developers Conference 2011
Barcelona Developers Conference 2011PayPal
 
Idram merchant api- Idram Payment System merchant interface description
Idram merchant api- Idram Payment System merchant interface descriptionIdram merchant api- Idram Payment System merchant interface description
Idram merchant api- Idram Payment System merchant interface descriptioniDramAPI
 
eZ Publish Workflows and Payment Gateways
eZ Publish Workflows and Payment GatewayseZ Publish Workflows and Payment Gateways
eZ Publish Workflows and Payment GatewaysGraham Brookins
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsEvangelia Mitsopoulou
 
https://uii.io/ref/hmaadi
https://uii.io/ref/hmaadihttps://uii.io/ref/hmaadi
https://uii.io/ref/hmaadihmaadi96
 
Payment Request API with a React high order component
Payment Request API with a React high order componentPayment Request API with a React high order component
Payment Request API with a React high order componentMarco Lanaro
 
InReceipts Plug N Play Client & REST APIs for billing softwares v1.0
InReceipts Plug N Play Client & REST APIs for billing softwares v1.0InReceipts Plug N Play Client & REST APIs for billing softwares v1.0
InReceipts Plug N Play Client & REST APIs for billing softwares v1.0InReceipts
 
Creating an Uber Clone - Part XXXI - Transcript.pdf
Creating an Uber Clone - Part XXXI - Transcript.pdfCreating an Uber Clone - Part XXXI - Transcript.pdf
Creating an Uber Clone - Part XXXI - Transcript.pdfShaiAlmog1
 
2012 SVCodeCamp: In App Payments with HTML5
2012 SVCodeCamp: In App Payments with HTML52012 SVCodeCamp: In App Payments with HTML5
2012 SVCodeCamp: In App Payments with HTML5Jonathan LeBlanc
 
Integration of payment gateways using Paypal account
Integration of payment gateways using Paypal account Integration of payment gateways using Paypal account
Integration of payment gateways using Paypal account Phenom People
 
Developing Business Blockchain Applications on Hyperledger
Developing Business  Blockchain Applications on Hyperledger Developing Business  Blockchain Applications on Hyperledger
Developing Business Blockchain Applications on Hyperledger IMC Institute
 

Similar to Integrate Paytm Payment Gateway in React Apps in 7 Steps (20)

java and javascript api dev guide
java and javascript api dev guidejava and javascript api dev guide
java and javascript api dev guide
 
Razorpay payment gateway integration in laravel and vue js 2
Razorpay payment gateway integration in laravel and vue js 2Razorpay payment gateway integration in laravel and vue js 2
Razorpay payment gateway integration in laravel and vue js 2
 
Paytm integration in swift
Paytm integration in swiftPaytm integration in swift
Paytm integration in swift
 
Razorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftRazorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS Swift
 
June2013 Meetup : In-App Billing by Soham & Senthil
June2013 Meetup : In-App Billing by Soham & SenthilJune2013 Meetup : In-App Billing by Soham & Senthil
June2013 Meetup : In-App Billing by Soham & Senthil
 
Abandoned carts
Abandoned cartsAbandoned carts
Abandoned carts
 
How to build twitter bot using golang from scratch
How to build twitter bot using golang from scratchHow to build twitter bot using golang from scratch
How to build twitter bot using golang from scratch
 
Barcelona Developers Conference 2011
Barcelona Developers Conference 2011Barcelona Developers Conference 2011
Barcelona Developers Conference 2011
 
Idram merchant api- Idram Payment System merchant interface description
Idram merchant api- Idram Payment System merchant interface descriptionIdram merchant api- Idram Payment System merchant interface description
Idram merchant api- Idram Payment System merchant interface description
 
eZ Publish Workflows and Payment Gateways
eZ Publish Workflows and Payment GatewayseZ Publish Workflows and Payment Gateways
eZ Publish Workflows and Payment Gateways
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applications
 
https://uii.io/ref/hmaadi
https://uii.io/ref/hmaadihttps://uii.io/ref/hmaadi
https://uii.io/ref/hmaadi
 
Payment Request API with a React high order component
Payment Request API with a React high order componentPayment Request API with a React high order component
Payment Request API with a React high order component
 
InReceipts Plug N Play Client & REST APIs for billing softwares v1.0
InReceipts Plug N Play Client & REST APIs for billing softwares v1.0InReceipts Plug N Play Client & REST APIs for billing softwares v1.0
InReceipts Plug N Play Client & REST APIs for billing softwares v1.0
 
Chat php
Chat phpChat php
Chat php
 
Creating an Uber Clone - Part XXXI - Transcript.pdf
Creating an Uber Clone - Part XXXI - Transcript.pdfCreating an Uber Clone - Part XXXI - Transcript.pdf
Creating an Uber Clone - Part XXXI - Transcript.pdf
 
2012 SVCodeCamp: In App Payments with HTML5
2012 SVCodeCamp: In App Payments with HTML52012 SVCodeCamp: In App Payments with HTML5
2012 SVCodeCamp: In App Payments with HTML5
 
Salesforce and sap integration
Salesforce and sap integrationSalesforce and sap integration
Salesforce and sap integration
 
Integration of payment gateways using Paypal account
Integration of payment gateways using Paypal account Integration of payment gateways using Paypal account
Integration of payment gateways using Paypal account
 
Developing Business Blockchain Applications on Hyperledger
Developing Business  Blockchain Applications on Hyperledger Developing Business  Blockchain Applications on Hyperledger
Developing Business Blockchain Applications on Hyperledger
 

More from Katy Slemon

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfKaty Slemon
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfKaty Slemon
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfKaty Slemon
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfKaty Slemon
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfKaty Slemon
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfKaty Slemon
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfKaty Slemon
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfKaty Slemon
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfKaty Slemon
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfKaty Slemon
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfKaty Slemon
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfKaty Slemon
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfKaty Slemon
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfKaty Slemon
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfKaty Slemon
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfKaty Slemon
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfKaty Slemon
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfKaty Slemon
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfHow to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfKaty Slemon
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfKaty Slemon
 

More from Katy Slemon (20)

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdf
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdf
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdf
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdf
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdf
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdf
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfHow to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdf
 

Recently uploaded

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Integrate Paytm Payment Gateway in React Apps in 7 Steps

  • 1. How to Integrate Paytm Payment Gateway using ReactJS in Seven Easy Steps www.bacancytechnology.com
  • 3. Are you stuck with a requirement of integrating a payment gateway into your project? Are you aggressively looking for a simple tutorial regarding the same? If yes, this tutorial: Integrate Paytm payment gateway using ReactJs is for you! In this step-by-step guide, we will learn how to implement a payment gateway in seven easy steps. So, without further ado, let’s get started with our tutorial. 02
  • 5. You might be wondering what we are going to do in this tutorial. We will build a small demo application consisting of a button ‘Pay Now’. With the click of the button a modal will be displayed as shown below. The library allows you to customize the modal and add various payment methods the way you want. 04
  • 7. We would need to create new secret keys by creating a new developer account. Go to https://developer.paytm.com/, login if you are already a Paytm user, or you can create a new account. 06
  • 9. Once you are logged in successfully, you can directly go to Dashboard and check the Test API Details. Feel free to test the APIs using the test API keys. 08
  • 11. Use the following command to create a new reactJs application. A new project would be created with the default folder structure as shown below. create-react-app < app - name > 10
  • 13. Hire ReactJS developer from us to add varied skillset to your existing in-house development. We can help you develop next-gen web solution from ideation to development to final delivery < script type=”text/javascript” crossorigin=”anonymous” src=”https://securegw- stage.paytm.in/merchantpgpui/checkoutjs/ merchants/.js” >< /script > You need to link the Paytm library using the script tag in public/index.html file. For that use the below snippet. 12
  • 15. Create a new file paytmButton.js inside /paytm-button folder. This file will contain the main logic and functionality for the Paytm payment integration using ReactJS. The user interface would have a “Pay Now” button that will trigger the Paytm checkout modal. Create a new function initializePaytm() that will contain all the initialization configurations and token generation steps that will be triggered on page load using useEffect. useEffect(() => { initialize(); }, []); 14
  • 16. The initializePaytm() function will make use of the Paytm checksum file and it will generate a token. const initialize = () => { let orderId = "Order_" + new Date().getTime(); // Sandbox Credentials let mid = ""; // Merchant ID let mkey = ""; // Merchant Key var paytmParams = {}; paytmParams.body = { requestType: "Payment", mid: mid, websiteName: "WEBSTAGING", orderId: orderId, callbackUrl: "https://merchant.com/callback", txnAmount: { value: 100, currency: "INR", }, 15
  • 17. userInfo: { custId: "1001", }, }; PaytmChecksum.generateSignature( JSON.stringify(paytmParams.body), mkey ).then(function (checksum) { console.log(checksum); paytmParams.head = { signature: checksum, }; var post_data = JSON.stringify(paytmParams); var options = { /* for Staging */ // hostname: "securegw-stage.paytm.in" /* for Production */, hostname: "securegw.paytm.in", 16
  • 18. port: 443, path: `/theia/api/v1/initiateTransaction? mid=${mid}&orderId=${orderId}`, method: "POST", headers: { "Content-Type": "application/json", "Content-Length": post_data.length, }, }; var response = ""; var post_req = https.request(options, function (post_res) { post_res.on("data", function (chunk) { response += chunk; }); post_res.on("end", function () { console.log("Response: ", response); // res.json({data: JSON.parse(response), orderId: orderId, mid: mid, amount: amount}); setPaymentData({ 17
  • 19. ...paymentData, token: JSON.parse(response).body.txnToken, order: orderId, mid: mid, amount: 100, }); }); }); post_req.write(post_data); post_req.end(); }); }; 18
  • 21. This method is called on page load which will return a transaction token from Paytm which will be later used for initiating the Paytm checkout modal. To retrieve the token, we will make an API call to /theia/api/v1/initiateTransaction which will expect a basic transaction object in the request body along with a hashed value created using the transaction object. The paytmParam.body is a transaction object with basic fields like orderId, value, and currency. paytmParams.body = { ... }; 20
  • 22. A hash value should be using this transaction object. For that Paytm provides a library – PaytmChecksum using which we can generate a hashed value by passing the transaction object as arguments. This hash value will be sent along with the transaction object in the initiateTransaction API and will provide the transaction token in response. Later this token will be used when the user clicks on the ‘Pay Now’ button and will be helpful for triggering the payment checkout modal. PaytmChecksum.generateSignature( JSON.stringify(paytmParams.body),mkey ).then(function(checksum){ ... // logic } 21
  • 23. Create a new function makePayment() that will be triggered on click of the button, which will use the already generated token and display the checkout modal to the user. In this function, you can modify the style of the Paytm checkout modal and change the color code and add your logo. const makePayment = () => { var config = { "root":"", "style": { "bodyBackgroundColor": "#fafafb", "bodyColor": "", "themeBackgroundColor": "#0FB8C9", "themeColor": "#ffffff", "headerBackgroundColor": "#284055", "headerColor": "#ffffff", "errorColor": "", "successColor": "", 22
  • 24. "card": { "padding": "", "backgroundColor": "" } }, "data": { "orderId": paymentData.order, "token": paymentData.token, "tokenType": "TXN_TOKEN", "amount": paymentData.amount /* update amount */ }, "payMode": { "labels": {}, "filter": { "exclude": [] }, 23
  • 25. "order": [ "CC", "DC", "NB", "UPI", "PPBL", "PPI", "BALANCE" ] }, "website": "WEBSTAGING", "flow": "DEFAULT", "merchant": { "mid": paymentData.mid, "redirect": false }, "handler": { "transactionStatus": function transactionStatus(paymentStatus){ console.log(paymentStatus); }, 24
  • 26. "notifyMerchant": function notifyMerchant(eventName,data){ console.log("Closed"); } } }; if (window.Paytm && window.Paytm.CheckoutJS) { window.Paytm.CheckoutJS.init(config). then(function onSuccess() { window.Paytm.CheckoutJS.invoke(); }).catch(function onError(error) { console.log("Error => ", error); }); }} 25
  • 27. Call the makePayment() method on click event of the button. return ( < div > {loading ? ( < img src="https://c.tenor.com/I6kN- 6X7nhAAAAAj/loading-buffering.gif" / > ) : ( < button onClick={makePayment}>Pay Now< /button > )} < /div > ); 26
  • 29. Once we are done with the main logic implementation it’s time to import the file into App.js. import "./App.css"; import { PaytmButton } from "./paytm- button/paytmButton"; function App() { return ( < div > < PaytmButton / > < /div > ); } export default App; 28
  • 31. So, finally, we are done with the tutorial: How to Integrate Paytm Payment Gateway using ReactJS. Now using the below command, run your server. npm start Visit http://localhost:3000/ and test the demo app. The entire source code is available on the github repo: paytm-payment-gateway- integration. Feel free to clone the repository and play around with the code. 30
  • 33. I hope the tutorial has helped you learn how to integrate Paytm payment gateway using ReactJS. We value your feedback and suggestions, so feel free to write back. Our team is trying to explore and add more such topics to ReactJS tutorials. If you are a ReactJS enthusiast, visit the ReactJS tutorials page without wasting your time, clone the github repository, and polish your technical side. 32