Paytm Payment Gateway Integration in PHP - Example

On 1/22/2018

Hi! In this tutorial, we will see how to integrate paytm payment gateway in php. Mobile wallets have become immensely popular in recent years and paytm is highly trusted among online customers. Many people use it every day for doing online recharges, DTH & other bill payments. It reduces the risk of exposing customer's banking credentials and credit card details to hackers. Therefore, Paytm is a good solution for online payments on your Website and Mobile Apps.

Integrating the paytm gateway in your application is quite easy and below I'll show how to do it with php.

paytm payment gateway integration php

Paytm Payment Gateway PHP Integration:

If your application is based on php, then you don't have to go from scratch. You can quickly integrate paytm into the application using the paytm kit for php. It covers all the basics, you just have to download and use it in the following way.

Step-1) Download Paytm Kit

Download Paytm Payment Kit for PHP and extract its contents. Then move the 'PaytmKit' folder to your working directory.

Step-2) Register for Paytm Sandbox Account

Next, you must register for merchant sandbox account with paytm and collect the necessary details to use with the API. Visit this link and provide your mobile number, email id and password and register an account. You will be provided with merchant id, key etc. Store them in a text file to use it later.

Step-3) Configure the Settings

Now you must configure the payment gateway settings with the data you received in Step-2. Open 'PaytmKit' > 'lib' > 'config_paytm.php' file and update the following details.

define('PAYTM_ENVIRONMENT', 'TEST'); //change this to 'PROD' to use it in production environment
define('PAYTM_MERCHANT_KEY', 'YOUR_MERCHANT_KEY'); //Change this to the merchant key downloaded from the portal
define('PAYTM_MERCHANT_MID', 'YOUR_MERCHANT_ID'); //change this to merchant id received from paytm
define('PAYTM_MERCHANT_WEBSITE', 'WEBSITE_NAME'); //change this to website name received from paytm

Step-4) Create Payment Form

Finally create a payment form to make transactions. Here we need to pass the form action to file 'pgRedirect.php' located inside the 'PaytmKit' folder. This will take care of verifying the checksum and other details and process the payment via the paytm wallet.

<!doctype html>
<title>PHP Patym Gateway Integration Demo</title>
    <link href="" type="text/css" rel="stylesheet" />
<div class="container">
    <div class="col-xs-6 col-xs-offset-3">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="text-center">Paytm Payment Gateway Demo</h3>
            <div class="panel-body">
            <form action="pgRedirect.php" method="post">
                <div class="form-group">
                    <input type="text" class="form-control" id="ORDER_ID" name="ORDER_ID" size="20" maxlength="20" autocomplete="off" tabindex="1" value="<?php echo  "ORDS" . rand(10000,99999999)?>">
                <div class="form-group">
                    <input type="text" class="form-control" id="CUST_ID" name="CUST_ID" maxlength="12" size="12" autocomplete="off" tabindex="2" value="CUST001">
                <div class="form-group">
                    <input type="text" class="form-control" id="INDUSTRY_TYPE_ID" name="INDUSTRY_TYPE_ID" maxlength="12" size="12"  autocomplete="off" tabindex="3" value="Retail">
                <div class="form-group">
                    <input type="text" class="form-control" id="CHANNEL_ID" name="CHANNEL_ID" maxlength="12" size="12" autocomplete="off" tabindex="4" value="WEB">
                <div class="form-group">
                    <input type="text" class="form-control" id="TXN_AMOUNT" name="TXN_AMOUNT" autocomplete="off" tabindex="5" value="1">
                <div class="form-group">
                    <input type="submit" name="submit" value="CheckOut" class="btn btn-success btn-lg">

This is just a usual php form, but remember to pass all the required parameters as I did. And for designing UI, I have used bootstrap css here, but you can happily skip it if you don't want.

php paytm payment demo

You can refer the official documentation for more details about Paytm gateway API.

Read Also:

That explains about paytm payment gateway integration in php. Using the kit really simplifies the task and allows you quickly add the paytm payment option to your web/mobile applications. I hope you like this tutorial. Please share it on social media if you find it useful.

No comments:

Post a Comment

Contact Form


Email *

Message *