Paytm Payment Gateway Integration in PHP

In this tutorial, you will learn how to integrate the paytm payment gateway in PHP.

Paytm Payment Gateway Integration in PHP

Here are steps:

  • Step 1 – Create Paytm Account
  • Step 2 – Download Paytm Payment Gateway PHP Kit
  • Step 3 – Update Paytm Gateways Config File
  • Step 4 – Create Payment Form

Step 1 – Create Paytm Account

First of all, we need to register or create a paytm merchant account. So go to this link https://paytm.com/business/payments/.

After that, paytm provides you some credentials like PAYTM_MERCHANT_KEY, PAYTM_MERCHANT_MID etc.

Step 2 – Download Paytm Payment Gateway PHP Kit

In the second step, we need to download the Paytm Payment Gateway PHP Kit from this link https://github.com/Paytm-Payments/Paytm_Web_Sample_Kit_PHP. You need to copy PaytmKit folder in document root of your local server.

Step 3 – Update Paytm Gateways Config File

Thired step, go to PaytmKit/lib folder and open the config_paytm.php. Then You need to update the paytm payment gateway credentials in config_paytm.php file.

//set payment mode TEST OR PROD
define('PAYTM_ENVIRONMENT', 'TEST');
// SET merchent key
define('PAYTM_MERCHANT_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxx');
// Set merchent mid
define('PAYTM_MERCHANT_MID', 'xxxxxxxxxxxxxxxxxxxxxxx');
//Set merchant website
define('PAYTM_MERCHANT_WEBSITE', 'xxxxxxx'); 

Step 4 – Create Payment Form

In this step, go to /Paytm_Web_Sample_Kit_PHP/PaytmKit/ and we need to create one file name index.php inside the PaytmKit folder. And you need to change or set form action like “pgRedirect.php” inside the PaytmKit folder.

pgRedirect.php 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.

Now we need to update the below code into your index.php file.

<!doctype html>
<html>
<head>
<title>Patym Payment Gateway Integration in PHP</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
</head>
<body>
<div class="container" style="padding-top:100px;">
    <div class="col-xs-6 col-xs-offset-3">
        <div class="panel panel-default">
            <div style="background-color: #000000; color:#fff" class="panel-heading">
                <h3 class="text-center">Paytm Payment Gateway Demo</h3>
            </div>
            <div class="panel-body">
            <form action="pgRedirect.php" method="post">
				<input type="hidden" id="CUST_ID" name="CUST_ID" value="CUST001">
					<input type="hidden" id="INDUSTRY_TYPE_ID" name="INDUSTRY_TYPE_ID" value="Retail">
					<input type="hidden"  id="CHANNEL_ID" name="CHANNEL_ID" value="WEB">
                <div class="form-group">

					<label>Order ID:</label>
                    <input type="text" class="form-control" id="ORDER_ID" name="ORDER_ID" size="20" maxlength="20" autocomplete="off"
tabindex="1" value="<?php echo  "ORDER" . rand(10000,99999999)?>">
                </div>

                <div class="form-group">
					<label>Amount to Pay:</label>
                    <input type="text" class="form-control" id="TXN_AMOUNT" name="TXN_AMOUNT" autocomplete="off" tabindex="5"
value="20">
                </div>
                <div class="form-group">
                    <input type="submit" name="submit" value="CheckOut" class="btn btn-success btn-lg" style="background-
color:#0000FF; margin-left: 37%;">
                </div>
            </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>

In this index.php file, we are sending some required parameters as hidden input fields like Channel ID, Industry Type and Customer ID. You have to pass these parameters along with form submit.

Now go to your browser and hit the below-given URL in your browser:

 http://localhost/Paytm_Web_Sample_Kit_PHP/PaytmKit/index.php

Recommended PHP Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *