Gautam3164 Gautam3164 - 1 year ago 145
PHP Question

How to integrate Paytm with Codeigniter

I want to integrate paytm payment gateway in codeigniter in my website and i have searched a lot, but i found only in PHP.I have tried with php library but while validating checksum it is not working.Can anyone suggest any library to integrate paytm.

Answer Source

I was searching for this same option today and finally had to tweak the library they provided here.

  1. Cloned their kit to a different folder
  2. Moved the contents of the folder lib to application/third_party/paytmlib
  3. In the moved path, Configured config_paytmp.php values according to my site set
  4. From their kit path moved this file TxnTest.php to views folder and changed form post tag like below <form method="post" action="paytmpost">
  5. Have added controller methods like below

    function paytm()
    function paytmpost()
     header("Pragma: no-cache");
     header("Cache-Control: no-cache");
     header("Expires: 0");
     // following files need to be included
     require_once(APPPATH . "/third_party/paytmlib/config_paytm.php");
     require_once(APPPATH . "/third_party/paytmlib/encdec_paytm.php");
     $checkSum = "";
     $paramList = array();
     $ORDER_ID = $_POST["ORDER_ID"];
     $CUST_ID = $_POST["CUST_ID"];
    // Create an array having all required parameters for creating checksum.
     $paramList["MID"] = PAYTM_MERCHANT_MID;
     $paramList["ORDER_ID"] = $ORDER_ID;
     $paramList["CUST_ID"] = $CUST_ID;
     $paramList["CHANNEL_ID"] = $CHANNEL_ID;
     $paramList["TXN_AMOUNT"] = $TXN_AMOUNT;
     $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);
     echo "<html>
    <title>Merchant Check Out Page</title>
        <center><h1>Please do not refresh this page...</h1></center>
            <form method='post' action='".PAYTM_TXN_URL."' name='f1'>
    <table border='1'>
     foreach($paramList as $name => $value) {
     echo '<input type="hidden" name="' . $name .'" value="' . $value .         '">';
     echo "<input type='hidden' name='CHECKSUMHASH' value='". $checkSum . "'>
    <script type='text/javascript'>

Note : paytmpost() is modified from the pgRedirect.php in their kit. The pgResponse.php could also be tweaked to a controller function to process the output from the payment gateway.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download