Tech Process payment gateway with Woocommerce : PART 1

Ecommerce engines like OScommerce, Prestashop or more like those have never been my expertise. But wordpress has accupied a good amount in my experience. So here is another post with a solution to a "not much" known problem of integrating TechProcess gateway with famous WooCommerce.

Tech Process is an Indian online payment gateway service, that provides transaction support for various Indian banks and credit / debit cards. You would need to register to them about your business and your domain. Before you start

  • you must have the necessary files provided by the TechProcess, including your Client ID.
  • Also, you must have prior knowledge about wordpress, CURL and OOPS.
  • Make sure that you have enabled "TEST Transactions" at your gateway, to do this, simply call Tech Process and ask them to do so.
  • Since payment gateway verifies the URL,you need to register the REAL business domain with them ans run the code on the live server (that is the only way, but dont worry).

Here we go, You would get 6 files from them(Tech Process) as in my screenshot.

Selection_006.png.scaled1000
  1. The "Request.php" has the request form to send request.
  2. "getcheck.php" is request handler.
  3. next is the "Response.php" that get you the response about the payment status.
  4. "MerchantDetails.properties", that is an important file that has your merchant details.
  5. "keystoretechp.pem", most important file, the secure certificate file.
  6. "TPSL_checksum_PHP.doc" the documentation, might need it, kinda old( as they say).

Dummy Transaction with default files So let us start, first we would setup those files with out woo commerce and make a test transaction.

Let us first look at the "MerchantDetails.properties" file.

BillerId=L**** // very important for test use 'T' as initial else use 'L' for live transactions ResponseUrl=http://yourdomain/Response.php CRN=INR CheckSumKey=****************  // 16 digit checksum key CheckSumGenUrl=use as provided TPSLUrl=Use as provided

here is my screenshot

Selection_007.png.scaled1000

You would only need to change BillerId and Response Url.

Next is our Request.php file, filled with dummy values

<form name="req_frm" action="getcheck.php" method="post">
  <input type="hidden" name="action" value="process">
   <table align="center" border="0">
      <tr>
          <td>Transaction ID</td>
          <td><input type="text" name="txtTranID" value="<? echo rand(10000,99999); /*****very important***/ ?>" /></td>
      </tr>
      <tr>
          <td>Market Code</td>
          <td><input type="text" name="txtMarketCode" value="As provided by Tech Process" /></td>
      </tr>
      <tr>
          <td>Account Number</td>
          <td><input type="text" name="txtAcctNo" value="As provided by Tech Process" /></td>
      </tr>
      <tr>
          <td>Txn Amount</td>
          <td><input type="text" name="txtTxnAmount" value="10.00" /></td>
      </tr>
      <tr>
          <td>Bank</td>
          <td><input type="text" name="txtBankCode" value="As provided by Tech Process" /></td>
      </tr>
        </table>
  <table align="center">
     <tr>
          <td><input type="submit" name="proceed" value="Proceed"/></td>
      </tr>
  </table>
  </form>

Next is the important handeler file "getcheck.php". Please pay attention, i am not pasting all the code just the important one.

at around like number 6

//---Set Property file Path, 
$property_path="/home/********/public_html/MerchantDetails.properties";
//Modify this url with the path of your property file. 
/* windows server would have something like    c:/something/something/..../MerchantDetails.properties*/ 

The path must be correct.

Next is when we read this property file and get its contents, code around line number 8 you will find

//---Read Property file
$property_data_array=readPropertyFileData($property_path); 

Then validating the file and saving value to array

if(count($property_data_array)<5)  {
                 ShowError("Invald Proerty File");
                 die();
         }
           $txtBillerId=$property_data_array[0];
         $txtResponseUrl=$property_data_array[1];
         $txtCRN=$property_data_array[2];
         $txtCheckSumKey=$property_data_array[3];
      $CheckSumGenUrl=trim($property_data_array[4]);
         $TPSLUrl=$property_data_array[5];

Around line number 35, we get the POST values from Request.php

$transaction = $_POST['txtTranID']; 
$market = $_POST['txtMarketCode'];
 $account = $_POST['txtAcctNo']; 
$transaction_amount = $_POST['txtTxnAmount']; 
$bankcode = $_POST['txtBankCode']; 

At line number 56, we create array with the post data

$pp=array(); 
foreach( $_POST as $key => $value) 
{
         if(trim($value)=="")
         {
                   ShowError("Invalid Input");
                   die();
         }
     $v="$key=".trim($value);
         array_push($pp,$v);
 }

at line number 90, we start the cURL request

if($_SERVER['REQUEST_METHOD']==='POST') {   // REQUIRE POST OR DIE
   $ch = curl_init(POST);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, False);
   curl_setopt($ch, CURLOPT_CAINFO, getcwd() . '/keystoretechp.pem'); //Setting certificate path
   curl_setopt ($ch, CURLOPT_SSLCERTPASSWD, 'changeit');
   curl_setopt($ch, CURLOPT_POST      ,1);
   //curl_setopt($ch, CURLOPT_TIMEOUT  ,10); // Not required. Don't use this.
   curl_setopt($ch, CURLOPT_REFERER  ,'http://www.yourdomain.com/getcheck.php'); //Setting header URL:
   curl_setopt($ch, CURLOPT_POSTFIELDS    ,POSTVARS);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
    curl_setopt($ch, CURLOPT_HEADER      ,0);  // DO NOT RETURN HTTP HEADERS
   curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1); // RETURN THE CONTENTS OF THE CALL
   $Received_CheckSum_Data = curl_exec($ch);
 curl_close($ch);

 

if yout want to check if the checksum recieved is a numeric value, uncomment the lines from 109 - 114

//if(!is_numeric($Received_CheckSum_Data)){ // Validating whether the Receieved value is numeric.
 //    echo "<br>" .  $Received_CheckSum_Data; //    
exit; //} 

thats is all for this file, everything else would be same.

Last is the "Response.php" file, the code pattern looks similar to getcheck.php

nothing much to change here as well.

Online number 14 you need to update

$property_path="MerchantDetails.properties"; //Modify this url with the path of your property file. 
// use file name if the all of these files are at root, else use the realtve path as stated in getcheck.php

The same with the cURL requests, starting at line 49

$ch = curl_init(POST);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, False);
   curl_setopt($ch, CURLOPT_CAINFO, getcwd() . '/keystoretechp.pem'); //Setting certificate path
   curl_setopt ($ch, CURLOPT_SSLCERTPASSWD, 'changeit');
   curl_setopt($ch, CURLOPT_POST      ,1);
   //curl_setopt($ch, CURLOPT_TIMEOUT  ,10); // Not required. Don't use this.
   curl_setopt($ch, CURLOPT_REFERER  ,'http://www.yourdomain.com/Response.php'); //Setting header URL
  curl_setopt($ch, CURLOPT_POSTFIELDS    ,POSTVARS);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
    curl_setopt($ch, CURLOPT_HEADER      ,0);  // DO NOT RETURN HTTP HEADERS
   curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1); // RETURN THE CONTENTS OF THE CALL
   $Received_CheckSum_Data = curl_exec($ch);
 curl_close($ch);
   $session_val = $_SESSION['msg'];
 $return_array = explode("|",$session_val); 

Finally the code to check if the transaction has failed or succeede, starts at line number79

             if(trim($return_array[14])=='0300')
             {
                       echo "<BR>";
                     echo "Success";
                           echo "<BR>Transaction Id : ".$return_array[1];
                     exit;
              }
             else
             {
                     echo "<BR>";
                     echo "Failed transaction.";
                   } 

as per gateway documentation the response contains array of values

[0] => T1234 [Biller Id] [1] => 1 [Transaction ID] [2] => 00 [3] => NA [4] => 1 [Amount] [5] => 470 [Bank code] [6] => NA [7] => NA [8] => INR [9] => NA [10] => NA [11] => NA [12] => NA [13] => 18-07-2011 10:12:18 [Timestamp] [14] => 0399 [Could be 0300/0399] 0300: Success transaction. 0399: Failed transaction. [15] => NA [16] => 1 [Market code] [17] => 1 [Account Number] [18] => NA [19] => NA [20] => NA [21] => NA [22] => NA [23] => NA [24] => NA [25] => 292697030925

so we are checking 14th index to get the status of the transaction

Once you understand and set up these files, we are ready for the dummy transaction. go to browser and open "Http://www.yourdomain.com/Request.php" you would get something like

Selection_010.png.scaled500

once you submit you will get the following screen from the payment gateway

_2012-08-23_00-35-40.png.scaled1000

Just for the try click cancel and you would be redirected to the "http://yourdomain/Response.php".

The response would show thow the array or response with Success or failed status. If you get error like

Selection.jpg.scaled500

Then you need to make sure that the Request file is kep at "http://yourdomain/Request.php". It important to understand that the gateway verifies the URL from where the form was submitted, by default it the root. In case you have url rewrites or any folder like "http://yourdomain/SOmething/Request.php", then you would need to register that path to the Tech Process Gateway(call them :] ).

That is all for setting up the files we got from the gateway service provider.

This is he first part, Next part will be available soon.

Hope you would find this useful.

thank you