Paytm Payment Gateway Integration in PHP

Webs Codex
4 min readDec 22, 2022

In this tutorial we explain how to integrate Paytm Payment Gateway into PHP. In today’s scenario, Paytm is the most popular and reliable mobile wallet system. According to a survey by Economic Time, Paytm has reached around 200 million registered users. Yes, that’s a very large number. Paytm payment accept only in India. Paytm payment does not accept International payment gateway.

Today many e-commerce websites or other services use Paytm payment gateways. It also reduces the risk of disclosing credit card or bank passwords. Send or receive payments easily from your mobile. So Paytm is undoubtedly a better online payment service for your website or mobile app. It’s best payment gateway for woocommerce.

How to use Paytm Payment gateway in PHP

Let’s start the process of Paytm Payment Gateway Integration. It’s very easy to integrate in your application as compared to other payment gateways. Follow the below :

Create HTML Payment Form

After configuring the credential, your code is ready to process. Now create an HTML form to make the online transactions. create checkout page to get customer and products details. When click on checkout button then redirect to Paytm payment page. insert payment details in payment transaction table.

index.php

<!DOCTYPE html>
<html lang=””>
<head>
<meta charset=”utf-8">
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1">
<title>Paytm Payment Gateway Integration in PHP Step by Step</title>
<! — Bootstrap CSS →
<link href=”https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel=”stylesheet”>
<link href=”https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css" rel=”stylesheet”>
</head>
<body>
<div class=”container”>
<div class=”py-5 text-center”>
<h2> Paytm Payment Gateway Integration Checkout Form</h2>
<p class=”lead”>This Checkout page using Paytm Payment Gateway for Testing purpose </p>
</div>
<form action=”http://localhost/Paytm-payment-gateway-in-php/PaytmKit/pgRedirect.php" method=”POST”>
<div class=”row”>
<div class=”col-md-8 order-md-1">
<h4 class=”mb-3">Billing address</h4>
<div class=”card p-3">
<div class=”row”>
<div class=”col-md-12 mb-3">
<label for=”firstName”>Full Name </label>
<input type=”text” class=”form-control” name=”full_name” placeholder=”Full Name” required=””>
</div>
</div>
<div class=”mb-3">
<label for=”mobile”>Mobile Number</label>
<div class=”input-group”>
<input type=”text” class=”form-control” name=”mobile_number” placeholder=”Mobile Number” required=””>
</div>
</div>
<div class=”mb-3">
<label for=”email”>Email <span class=”text-muted”>(Optional)</span></label>
<input type=”email” class=”form-control” name=”email” placeholder=”Email”>
</div>
<div class=”mb-3">
<label for=”address”>Flat, House no. Area, Street, Sector, Village</label>
<input type=”text” class=”form-control” name=”address” required=””>
</div>
<div class=”row”>
<div class=”col-md-6 mb-3">
<label for=”city”>Town/City</label>
<input type=”text” class=”form-control” placeholder=”Town/City”>
</div>
<div class=”col-md-6 mb-3">
<label for=”pincode”>Pincode</label>
<input type=”text” class=”form-control” name=”pincode” placeholder=”6 digits [0–9] Pin code” required=””>
</div>
</div>
</div>
</div>
<div class=”col-md-4 order-md-2 mb-4">
<h4 class=”d-flex justify-content-between align-items-center mb-3">
<span>Your cart</span>
<span class=”badge badge-secondary badge-pill”>3</span>
</h4>
<ul class=”list-group mb-3 sticky-top”>
<li class=”list-group-item d-flex justify-content-between lh-condensed”>
<div>
<h6 class=”my-0">First Product</h6>
<small class=”text-muted”>Brief description</small>
</div>
<span class=”text-muted”>₹12,000</span>
</li>
<li class=”list-group-item d-flex justify-content-between lh-condensed”>
<div>
<h6 class=”my-0">Second Product</h6>
<small class=”text-muted”>Brief description</small>
</div>
<span class=”text-muted”>₹8,000</span>
</li>
<li class=”list-group-item d-flex justify-content-between lh-condensed”>
<div>
<h6 class=”my-0">Third Product</h6>
<small class=”text-muted”>Brief description</small>
</div>
<span class=”text-muted”>₹5,000</span>
</li>
<li class=”list-group-item d-flex justify-content-between”>
<span><strong> Order Total: </strong></span>
<input type=”hidden” name=”order_amount” value=”25000" />
<strong>₹25,000</strong>
</li>
</ul>
<div class=”card p-2">
<button class=”btn btn-primary btn-block” type=”submit” name=”check_out”>Continue to checkout</button>
</div>
</div>
</div>
</form>
</div>
<! — jQuery →
<script src=”https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js”></script>
<! — Bootstrap JavaScript →
<script src=”https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js”></script>
</body>
</html>

Payment Page Redirect

Form action should be to this file pgRedirect.php inside PaytmKit folder. This file handle checksum and other require details and redirect to you Paytm payment page. After click on checkout button user can process the payment via the paytm wallet.

pgRedirect.php

<?php
header(“Pragma: no-cache”);
header(“Cache-Control: no-cache”);
header(“Expires: 0”);
// following files need to be included
require_once(“./lib/config_paytm.php”);
require_once(“./lib/encdec_paytm.php”);

$checkSum = “”;
$paramList = array();

if (isset($_POST[‘check_out’])) {

$ORDER_ID = “WC”.rand(1111,9999); // Get customer order Id
$CUST_ID = rand(1,9999); // Make dynamic customer Id
$TXN_AMOUNT = $_POST[“order_amount”]; // Get total order amount
$MSISDN = $_POST[“mobile_number”]; // Get total order amount
$EMAIL = $_POST[‘email’];

// Create an array having all required parameters for creating checksum.
$paramList[“ORDER_ID”] = $ORDER_ID;
$paramList[“CUST_ID”] = $CUST_ID;
$paramList[“TXN_AMOUNT”] = $TXN_AMOUNT;
$paramList[“INDUSTRY_TYPE_ID”] = PAYTM_INDUSTRY_TYPE_ID;
$paramList[“CHANNEL_ID”] = PAYTM_CHANNEL_ID;
$paramList[“MID”] = PAYTM_MERCHANT_MID;
$paramList[“WEBSITE”] = PAYTM_MERCHANT_WEBSITE;

$paramList[“CALLBACK_URL”] = PAYTM_CALLBACK_URL;
$paramList[“MSISDN”] = $MSISDN; //Mobile number of customer
$paramList[“EMAIL”] = $EMAIL; //Email ID of customer
$paramList[“VERIFIED_BY”] = “EMAIL”; //
$paramList[“IS_USER_VERIFIED”] = “YES”; //

}

//Here checksum string will return by getChecksumFromArray() function.
$checkSum = getChecksumFromArray($paramList,PAYTM_MERCHANT_KEY);

?>
<html>
<head>
<title>Merchant Check Out Page</title>
</head>
<body>
<center><h1>Please do not refresh this page…</h1></center>
<form method=”post” action=”<?php echo PAYTM_TXN_URL ?>” name=”f1">
<table border=”1">
<tbody>
<?php
foreach($paramList as $name => $value) {
echo ‘<input type=”hidden” name=”’ . $name .’” value=”’ . $value . ‘“>’;
}
?>
<input type=”hidden” name=”CHECKSUMHASH” value=”<?php echo $checkSum ?>”>
</tbody>
</table>
<script type=”text/javascript”>
document.f1.submit();
</script>
</form>
</body>
</html>

Output

Please visit click on the below click for full blog post. I have explain easiest way to integrate paytm payment gateway in PHP. also given the full source code download button to implement in our project.

Paytm Payment Gateway Integration in PHP

--

--

Webs Codex

Webs Codex is programming and web development blog