Menu

EBS Payment Gateway Integration in PHP

EBS Payment Gateway Integration in PHP

EBS (E-Billing Solutions) is popular secured payment gateway from India that enables online purchases from a merchant’s website and helps them to collect payment from the end customers through net banking, credit and debit cards etc. The EBS act as an intermediary that assembles the online payment options offered by various banks, cash card brands and many other payment processors onto a single platform with minimum technical integration with merchant website.

You will also like related tutorial to Integrate Payment Gateways



The EBS payment gateway developed to integrate it without any hassle. To integrate EBS payment gateway into your website, you should have EBS account and they will provide you EBS account id and EBS Key to perform transaction. In this tutorial, I have explained easy steps to integrate EBS payment gateway with PHP.


As explained earlier that it’s easy to integrate, you just need to pass required input field to EBS to process transaction. The EBS system expects certain input data with specific names to be sent to the EBS website. It is essential that the names of the input fields on the merchant website and the EBS website should match exactly.

Below is form with action URL to EBS and input field with values. In this form passed required input field with returned to response.php.

<form method="post" action="https://secure.ebs.in/pg/ma/sale/pay" name="frmPaymentConfirm">
<?php
$key="EBS Key";
$account_id="EBS ACCOUNT ID";
$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";
$finalamount=20000;
$order_no="123456";
// replace yoursite.com by your website name
$return_url="http://www.yoursite.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>Its just for testing. Your transaction will not be billed yet!</p>
<input value="Place an Order" id="submit" name="submit" type="submit">
</form>


When the above form submitted, it is retuned back to response.php after payment processing. The response returned in encrypted form and needs to be decrypted. To decrypt response, we need some from EBS. For this I have created Decrypt.php that have class and method to handle response decrypt.

<?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);
}
}
?>



Now finally we will handle returned EBS response decrypt by using above class and method in response.php. We will also check for transaction success and failure with response.

<?php
$secret_key = "EBS key";
if(isset($_GET['DR'])) {
require('Decrypt.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]);
}
// check for payment success
if(($response['ResponseCode'] == 0)) {
foreach( $response as $key => $value) {
echo $key;
echo $value;
}
}
// check for payment failed
if(($response['ResponseCode'] != 0)) {
foreach( $response as $key => $value) {
echo $key;
echo $value;
}
}
}
?>

Ads middle content1

Ads middle content2