How to integrate EBS payment gateway in PHP

Abhigyan Singh 12th Jul 2020

Here we will show to Integrate EBS payment gateway in PHP. As php is widely used for web development or in ecommerce site. EBS stands for E-Billing Solutions.  EBS provides secure payment gateway for online payment processing via credit card, debit cards and Net banking. It’s open source system that is used for e billing. Any merchant or developer can integrate this payment gateway on his/her website/application.

Below tutorial I will explain how to integrate EBS payment gateway in core PHP. I have successfully managed to integrate EBS payment gateway. EBS supports mostly all the programming language like HTML, PHP, ASP, ASP .Net, VB .Net, JAVA, Ruby on Rails, Perl, Python etc. There are also several plugins avaliable to integrate it in your application.

Integration steps of EBS payment gateway in PHP

There are three basic components of EBS integration. Firstly, we’ll brief about basic components of EBS Integration. Given bellow the three basic page of EBS Integration.

Pay Page: This is the page of last step of merchant website before connecting to EBS. It’s used for collect the customer Information. From this page it collect the customer details and product details.

Rc4 Page: This file decrypts the EBS response. So far, it's used to decrypt the EBS response.

Response Page: This page is for receives the response from EBS on completion. There are several reponse code after completion the payment. It mainly show the status of your payment.

Now, we’ll go to coding step. Given bellow the full example coding of EBS Integration. Follow bellows step to complete EBS Integration.

Step: 1

I have write bellows code for creating a form. It’s my idex.php file. Just copy and paste this code and replace demo value.

<form method="post" action="https://secure.ebs.in/pg/ma/sale/pay" name="frmPaymentConfirm" >
<?php
$ebsuser_name="User Name";

$ebsuser_address="Address";

$ebsuser_zipcode="City Pin code";

$ebsuser_city="City";

$ebsuser_state="State";

$ebsuser_country="Country";

$ebsuser_phone="Phone Number";

$ebsuser_email="Email";

$ebsuser_id="User ID";

$modelno="Model No of Product on Website";

$key="EBS Key";

$account_id="EBS ACCOUNT ID";

$finalamount=20000;

$order_no="123456";

// replace example.com by your website name
$return_url="https://www.example.com/response.php?DR={DR}"; $mode="TEST";

$hash = $key."|".$account_id."|".$finalamount."|".$order_no."|".$return_url."|".$mode;

$secure_hash = md5($hash);
? >

<input name="account_id" value="<?php echo $account_id;?>" type="hidden">

<input name="return_url" size="60" value="<?php echo $return_url; ?>" type="hidden">

<input name="mode" size="60" value="TEST" type="hidden">

<input name="reference_no" value="<?php echo $order_no; ?>" type="hidden">

<input name="description" value="<?php echo $modelno; ?>" type="hidden">

<input name="name" maxlength="255" value="<?php echo $ebsuser_name; ?>" type="hidden">

<input name="address" maxlength="255" value="<?php echo $ebsuser_address; ?>" type="hidden">

<input name="city" maxlength="255" value="<?php echo $ebsuser_city; ?>" type="hidden">

<input name="state" maxlength="255" value="<?php echo $ebsuser_state; ?>" type="hidden">

<input name="postal_code" maxlength="255" value="<?php echo $ebsuser_zipcode; ?>" type="hidden">

<input name="country" maxlength="255" value="<?php echo $ebsuser_country; ?>" type="hidden">

<input name="phone" maxlength="255" value="<?php echo $ebsuser_phone; ?>" type="hidden">

<input name="email" size="60" value="<?php echo $ebsuser_email; ?>" type="hidden">

<input name="secure_hash" size="60" value="<?php echo $secure_hash; ?>" type="hidden">

<input name="amount" id="amount" readonly="" value="<?php echo $finalamount; ?>" type="hidden">

<p>Your transaction will not be billed yet.</p>

<input value="Place an Order" id="submit" name="submit" type="submit">

</form>

Step: 2

In this step, decrypt the EBS response. Write this step for get a response from EBS. I have created php file named Rc43.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);
}
}

Step: 3

In third step, page is for receives the response from EBS on completion. I have created php file named Response.php. using bellows code.

<?php
$secret_key = "ebskey";
if(isset($_GET['DR'])) {
require('Rc43.php');
$DR = preg_replace("/\s/","+",$_GET['DR']);
$rc4 = new Crypt_RC4($secret_key);
$QueryString = base64_decode($DR);
$rc4->decrypt($QueryString);
$QueryString = explode('&',$QueryString);
$response = array();
foreach($QueryString as $param){
$param = explode('=',$param);
$response[$param[0]] = urldecode($param[1]);
}
}
?>

In the case of successfull payment, below code is applicable.

<?php
// payment success
if(($response['ResponseCode'] == 0))
{
foreach( $response as $key => $value)
{
echo $key;
echo $value;
}
}

?>

If payment is failed, for failed payment is below code execute.

<?php
// payment failed
if(($response['ResponseCode'] != 0))
{
foreach( $response as $key => $value)
{
echo $key;
echo $value;
}
}

?>

That’s all made a PHP based EBS Payment system. If you face problem to integrate EBS payment gateway in php, feel free to comment your suggestions regarding this tutorial without any hesitation.

Authored By Abhigyan Singh

He is a continuous blogger and has blogged on different topic. He loves to surf Internet and always trying to get new Idea about new Technology and Innovations and sharing these great information to all the technology lovers.

ALSO ON DISCUSS DESK