How do I Integrate Paytm Payment Gateway in Php

#How do I Integrate Paytm Payment Gateway in Php?

Collect online payments with Paytm Payment Gateway

paytm

Paytm Checkout for your website provides a secure,

PCI-compliant way to accept Debit/Credit card,

Net-Banking, UPI and Paytm wallet payments from your customers.

Parameters Are –

REQUEST ATTRIBUTES
MID

String(20) Mandatory

This is a unique identifier provided to every merchant by Paytm. MID is part of your account credentials and is different on staging and production environment. Your staging MID is available here and production MID will be available once your activation is complete
ORDER_ID

String(50) Mandatory

Unique reference ID for a transaction which is generated by merchant Special characters allowed in Order ID are: @, -, _, .
CUST_ID

String(64) Mandatory

Unique reference ID for every customer which is generated by merchant Special characters allowed in Cust_ID are @, ! ,_ ,$, .
TXN_AMOUNT

String(10) Mandatory

Amount in INR payable by customer. Should contain digits up to two decimal points. Only special character allowed is (“.”)
CHANNEL_ID

String(3) Mandatory

This parameter is used to control the theme of the payment page. Based on the channel passed, Paytm will render the layout suitable for that specific platform
For websites, the value is WEB
For Mobile websites/App, the value is WAP
WEBSITE

String(30) Mandatory

For staging environment: For staging environment: WEBSTAGING
For production environment: Will be available here once your activation is complete
CHECKSUMHASH

String(108) Mandatory

Signature to avoid tampering. Generated using server side checksum utility available here
MOBILE_NO

String(15) Optional

Customer’s mobile number. Passing this enables faster login for customer into his/her Paytm account. When the customer clicks on login, the mobile number comes pre-filled on our payment page
EMAIL

String(50) Optional

Customer’s email ID
INDUSTRY_TYPE_ID

String(20) Mandatory

For staging environment: “Retail”
For production environment: Will be available here once your activation is complete
CALLBACK_URL

String(255) Mandatory

On completion of transaction, Paytm payment gateway will send the response on this URL.. Sample URL is – https://merchant.com/callback/
PAYMENT_MODE_ONLY

String(3) Optional

If merchant wants to allow payment mode selection on his website or restrict the payment to a particular paymode, then value to be passed is “YES”.
For example, with this parameter merchant can ensure that customer only sees credit card as a paymode when he lands on Paytm’s cashier page.
AUTH_MODE

String(10) Conditional

Required If PAYMENT_MODE_ONLY = YES, then
For Credit/Debit card – 3D
For Wallet, Net Banking – USRPWD
PAYMENT_TYPE_ID

String(15) Conditional

Required If PAYMENT_MODE_ONLY = Yes, then
Credit card payment mode – CC
Debit card payment mode – DC
Net banking payment mode – NB
Paytm wallet – PPI
EMI – EMI
UPI – UPI
BANK_CODE

String(5) Conditional

Required If PAYMENT_MODE_ONLY = Yes PAYMENT_TYPE_ID = NB
List of Bank Codes provided in this PDF

Generate checksumhash using Paytm library with parameters in key value pairs. Using the payload and checksumhash make an HTML form post and redirect customer to Paytm server.

    require_once("encdec_paytm.php");
    define("merchantMid", "rxazcv89315285244163");
    // Key in your staging and production MID available in your dashboard

    define("merchantKey", "gKpu7IKaLSbkchFS");
    // Key in your staging and production merchant key available in your dashboard

    define("orderId", "order1");
    define("channelId", "WEB");
    define("custId", "cust123");
    define("mobileNo", "7777777777");
    define("email", "[email protected]");
    define("txnAmount", "100.12");
    define("website", "WEBSTAGING");
    // This is the staging value. Production value is available in your dashboard

    define("industryTypeId", "Retail");
    // This is the staging value. Production value is available in your dashboard

    define("callbackUrl", "https://<Merchant_Response_URL>");


    $paytmParams = array();
    $paytmParams["MID"] = merchantMid;
    $paytmParams["ORDER_ID"] = orderId;
    $paytmParams["CUST_ID"] = custId;
    $paytmParams["MOBILE_NO"] = mobileNo;
    $paytmParams["EMAIL"] = email;
    $paytmParams["CHANNEL_ID"] = channelId;
    $paytmParams["TXN_AMOUNT"] = txnAmount;
    $paytmParams["WEBSITE"] = website;
    $paytmParams["INDUSTRY_TYPE_ID"] = industryTypeId;
    $paytmParams["CALLBACK_URL"] = callbackUrl;
    $paytmChecksum = getChecksumFromArray($paytmParams, merchantKey);
    $transactionURL = "https://securegw-stage.paytm.in/theia/processTransaction";
    // $transactionURL = "https://securegw.paytm.in/theia/processTransaction"; // for production

The Html data as below..

<html>
    <head>
        <title>Merchant Checkout Page</title>
    </head>
    <body>
        <center><h1>Please do not refresh this page...</h1></center>
        <form method='post' action='<?php echo $transactionURL; ?>' name='f1'>
            <?php
                foreach($paytmParams as $name => $value) {
                    echo '<input type="hidden" name="' . $name .'" value="' . $value . '">';
                }
            ?>
            <input type="hidden" name="CHECKSUMHASH" value="<?php echo $paytmChecksum ?>">
        </form>
        <script type="text/javascript">
            document.f1.submit();
        </script>
    </body>
</html>

Endpoints: 
Staging: https://securegw-stage.paytm.in/theia/processTransaction
Production: https://securegw.paytm.in/theia/processTransaction

HTML Form POST Data::

<html>
    <head>
        <title>Merchant Check Out Page</title>
    </head>
    <body>
        <center><h1>Please do not refresh this page...</h1></center>

        <form method="post" action="https://securegw-stage.paytm.in/theia/processTransaction?ORDER_ID=order1" name="f1">
            <table border="1">
                <tbody>
                    <input type="hidden" name="MID" value="rxazcv89315285244163">

                    <input type="hidden" name="WEBSITE" value="WEBSTAGING">

                    <input type="hidden" name="ORDER_ID" value="order1">

                    <input type="hidden" name="CUST_ID" value="cust123">

                    <input type="hidden" name="MOBILE_NO" value="7777777777">

                    <input type="hidden" name="EMAIL" value="[email protected]">

                    <input type="hidden" name="INDUSTRY_TYPE_ID" value="Retail">

                    <input type="hidden" name="CHANNEL_ID" value="WEB">

                    <input type="hidden" name="TXN_AMOUNT" value="100.12">

                    <input type="hidden" name="CALLBACK_URL" value="https://Merchant_Response_URL>">

                    <input type="hidden" name="CHECKSUMHASH" value="ZWdMJOr1yGiFh1nns2U8sDC9VzgUDHVnQpG
                    pVnHyrrPb6bthwro1Z8AREUKdUR/K46x3XvFs6Xv7EnoSOLZT29qbZJKXXvyEuEWQIJGkw=">

                </tbody>
            </table>

        <script type="text/javascript">

            document.f1.submit();
        </script>

        </form>
    </body>
</html>

Response Parameters by PayTM:

RESPONSE ATTRIBUTESTypeDescription
MIDString(20)This is a unique identifier provided to every merchant by Paytm
TXNIDString(64)This is a unique Paytm transaction ID that is issued by Paytm for each transaction
ORDERIDString(50)Unique reference ID for a transaction which is generated by merchant and sent in the request
CUST_IDString(64)Unique reference ID for every customer which is generated by merchant and sent in request
BANKTXNIDStringThe transaction ID sent by the bank. In case of Paytm proprietary instruments too, there is unique reference number generated by Paytm’s system. In case the transaction does not reach the bank, this will be NULL or empty string. Primary reason for this is user dropping out of the payment flow before the transaction reaches to bank to servers
TXNAMOUNTString(10)Amount paid by customer in INR
CURRENCYString(3)Currency in which the transaction has taken place. Currently only “INR” is the supported currency of transaction
STATUSString(20)This contains the transaction status and has only three values: TXN_SUCCESS, TXN_FAILURE and PENDING
RESPCODEString(10)Codes refer to a particular reason of payment failure. List in this PDF
RESPMSGString(500)Description message is linked with each respcode. List in this PDF
TXNDATEDateTimeDate and Time of transaction in the format “yyyy-MM-dd HH:mm:ss.S”Example: “2015-11- 02 11:40:46.0”
GATEWAYNAMEString(15)Gateway used by Paytm to process the transactions. By paymodes, the details are provided below
Credit, debit cards UPI – Gateway used to process the transaction. For example, if HDFC gateway has been used to process SBI credit card transactions, the value will be HDFC
Net banking – Netbanking transactions are not routed via gateway. Hence issuing bank name is passed in this field
Paytm Wallet – Wallet
BANKNAMEString(500)Name of issuing bank of the payment instrument used by customer. By paymodes, the details are provided below
Credit, debit cards, net banking – Name of the issuing bank. Example in case customer uses SBI’s credit card, the value will be “SBI”
Paytm Wallet – Wallet
Note that in case of UPI – This parameter will be not be present in the response
PAYMENTMODEString(15)The payment mode used by customer for transaction
Credit card – CC
Debit card – DC
Net banking – NB
UPI – UPI
Paytm wallet – PPI
CHECKSUMHASHString(108)Security parameter to avoid tampering. Verified using server side checksum utility provided by Paytm. Utilities to generate checksumhash is available here
BIN_NUMBERString(6)Starting 6 digit of Credit Card/Debit Card which used in transaction.
For other modes, this field not provided in response
CARD_LAST_NUMSString(4)Last 4 digit of Credit Card/Debit Card which used in transaction.
For other modes, this field not provided in response

References:

https://developer.paytm.com/docs/v1/payment-gateway

Leave a Comment