EBS Payment gateway integration using php

1 comment
Today, I am going to explain how to integrate EBS payment gateway in core PHP. However, there are lots of plugins are available on EBS official website for popular CMS and E-commerce website. But in core PHP you have to integrate by yourself.

To integrate EBS payement gateway, you need three files.
1) Index.php: Here we have used index.php to fill the required value of parameters that EBS payment gateway need before processing payment.

2)RC43.php: This page contains functions to decrypt the EBS response.

3)Responce.php: This page will receive response from EBS payement gateway system after payment successfull or cancelled.
Index.php


<form method="post" action="https://secure.ebs.in/pg/ma/sale/pay/" name="goEbs" id="goEbs">
   <input type="hidden" name="account_id" value="1234" />
 <input type="hidden" name="mode" value="TEST" />
 <input type="hidden" name="description" value="Put your description here" />
 <input type="hidden" name="reference_no" value="123" />
 <input type="hidden" name="name" value="akhilesh shukla" />
 <input type="hidden" name="address" value="Allahabad" />
 <input type="hidden" name="city" value="Allahabad" />
 <input type="hidden" name="state" value="Utter Pradesh" />
 <input type="hidden" name="country" value="IN" />
 <input type="hidden" name="postal_code" value="123456" />
 <input type="hidden" name="ship_name" value="Akhilesh Shukla" />
 <input type="hidden" name="ship_address" value="Allahabad" />
 <input type="hidden" name="ship_city" value="Allahabad" />
 <input type="hidden" name="ship_state" value="Utter Pradesh" />
 <input type="hidden" name="ship_country" value="IN" />
 <input type="hidden" name="ship_postal_code" value="123456" />
 <input type="hidden" name="ship_phone" value="1234567890" />
 <input type="hidden" name="email" value="email@example.com" />
 <input type="hidden" name="phone" value="1234567890" />
 <input type="hidden" name="amount" value="5000" />
 <input name="currency" type="hidden" value="USD" />
 <input type="hidden" name="return_url" value="http://example.com/response.php?DR={DR}" />
 <input type="submit" value="Pay Now" />
</form>

RC43.php:


<?php class Crypt_RC4 {
    var $s= array();
    var $i= 0;
    var $j= 0;
    var $_key;
    function Crypt_RC4($key = null) {
        if ($key != null) {
            $this->setKey($key);
        }
    }
    function setKey($key) {
        if (strlen($key) > 0)
            $this->_key = $key;
    }
    function key(&$key) {
        $len= strlen($key);
        for ($this->i = 0; $this->i < 256; $this->i++) {
            $this->s[$this->i] = $this->i;
        }
        $this->j = 0;
        for ($this->i = 0; $this->i < 256; $this->i++) {
            $this->j = ($this->j + $this->s[$this->i] + ord($key[$this->i % $len])) % 256;
            $t = $this->s[$this->i];
            $this->s[$this->i] = $this->s[$this->j];
            $this->s[$this->j] = $t;
        }
        $this->i = $this->j = 0;
    }
    function crypt(&$paramstr) {
        $this->key($this->_key);

        $len= strlen($paramstr);
        for ($c= 0; $c < $len; $c++) {
            $this->i = ($this->i + 1) % 256;
            $this->j = ($this->j + $this->s[$this->i]) % 256;
            $t = $this->s[$this->i];
            $this->s[$this->i] = $this->s[$this->j];
            $this->s[$this->j] = $t;
            $t = ($this->s[$this->i] + $this->s[$this->j]) % 256;
            $paramstr[$c] = chr(ord($paramstr[$c]) ^ $this->s[$t]);
        }
    }
    function decrypt(&$paramstr) {
        $this->crypt($paramstr);
    }
} ?>

Response.php:


<?php
$secret_key = "123"; // put your secret key here

if(isset($_GET['DR']))
{
 require('Rc43.php'); //include RC43.php file decrypt response
 $DR = preg_replace("/\s/","+",$_GET['DR']);
 $rc4 = new Crypt_RC4($secret_key);
 $QueryString = base64_decode($DR);
 $rc4->decrypt($QueryString);
 $QueryString = split('&',$QueryString);
 
 $response = array();

 foreach($QueryString as $param)
 {
  $param = split('=',$param);
  $response[$param[0]] = urldecode($param[1]);
 }
}

?>
<table>
<tr>
<td><strong>Key</strong></td>
<td><strong>Value</strong></td>
</tr>

<?php foreach( $response as $key => $value) 
    {?>
 <tr>
 <td><?php echo $key;?></td>
 <td><?php echo $value;?></td>
 </tr>
      
   <?php }
?>
</table>

Change mode to 'LIVE' before going live in the production environment. Please share your opinion in the comment box below. Thanks.



1 comment :