Paytm Payment Gateway Integration in PHP
Today many eCommerce or other service websites start using Paytm payment gateway. So just send or receive payment via your Mobile Phone. Let’s start the process of Paytm Payment Gateway Integration.
It’s very easy to integrate in your application as compare to other payment gateway. Follow the below steps :
Step 1 : Register for Paytm Account
Sign Up for Paytm account : https://developer.paytm.com/docs/
See the screen short :
Now generete api key. left side menu DEVELOPERS/API Keys
Step 2 : Download Official Paytm PHP Kit
Paytm official announced library source code. Just download the Paytm Payment Gateway kit from GitHub. Extract the zip file and open the PaytmKit folder that has all the required files.
Step 3: Configure Paytm Credential
Open config_paytm.php file in PaytmKit/lib folder and update credential you got from Paytm.
define('PAYTM_ENVIRONMENT', 'TEST'); // change value PROD for production
define('PAYTM_MERCHANT_KEY', 'uG*****lH'); //Merchant key
define('PAYTM_MERCHANT_MID', 'Iy*****48'); //MID (Merchant ID)
define('PAYTM_MERCHANT_WEBSITE', 'WE*****NG'); Website name
After configure the credential, your code is ready to process.
Step 4: Create HTML Payment Form
I changed file name TxnTest.php to index.php. And css and js folder added.
index.php
<?php
header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");
?>
<!DOCTYPE html>
<html>
<head>
<title>Paytm payment gateway integration in PHP : Step by Step</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
#paytm_forms {
padding: 20px;
}
#footer {
margin-top: 20px;
}
</style>
</head>
<body>
<h1 class="text-center">Paytm payment gateway integration in PHP</h1>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<form method="post" action="pgRedirect.php" id="paytm_forms" class="form-horizontal text-center">
<div class="form-group">
<label class="control-label col-sm-4" for="ORDER_ID">Order Id :</label>
<div class="col-sm-8">
<input id="ORDER_ID" tabindex="1" maxlength="20" size="20" name="ORDER_ID" class="form-control" autocomplete="off" value="<?php echo "ORDS" . rand(10000,99999999)?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4" for="CUST_ID">Customer Id :</label>
<div class="col-sm-8">
<input id="CUST_ID" tabindex="2" maxlength="12" size="12" name="CUST_ID" class="form-control" autocomplete="off" value="<?php echo "CUST" . rand(10000,99999999)?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4" for="INDUSTRY_TYPE_ID">Industry Type Id : </label>
<div class="col-sm-8">
<input id="INDUSTRY_TYPE_ID" tabindex="4" maxlength="12" size="12" name="INDUSTRY_TYPE_ID" class="form-control" autocomplete="off" value="Retail">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4" for="CHANNEL_ID">Channel :</label>
<div class="col-sm-8">
<input id="CHANNEL_ID" tabindex="4" maxlength="12" size="12" name="CHANNEL_ID" autocomplete="off" class="form-control" value="WEB">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4" for="CHANNEL_ID">Txn Amount :</label>
<div class="col-sm-8">
<input title="TXN_AMOUNT" tabindex="10" class="form-control" type="text" name="TXN_AMOUNT" value="1">
</div>
</div>
<button type="submit" class="btn btn-success">Donate</button>
</form>
<div class="col-md-12">
<div class="alert alert-danger text-center"> All fields are mandatory. </div>
</div>
</div>
</div>
</div>
<section id="footer">
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<p>© <?php echo date('Y');?> by <b><a href="https://devnote.in">Devnote.in</a></b>. All Rights Reserved.</p>
</div>
</div>
</div>
</section>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
Form action should be pgRedirect.php inside the PaytmKit folder. This filehandle checksum and other require details and redirect to your Paytm payment page.
pgRedirect.php
Add callback url : $paramList["CALLBACK_URL"] = "http://localhost/paytmkit/pgResponse.php";
Download all source code from here : Paytm payment gateway integration in PHP