EBS Payment Integration on our Web Applications

The primary thing is that, You should be registered in EBS secure payment for the transactions to happen. So after registration you need to login with your credentials on

https://secure.ebs.in/

to follow the customer payment flow, success transactions, failure transactions, cancel transactions, customer transaction details in real time.


How to test your transaction from localhost(127.0.0.1)?


Required files


1 . index.php

2 . response.php
3 . secure.php

Index.php

mandatory credentials -

  1. $secret_key="ebskey";

    'ebskey' is for testing purpose.
    For real time,
    a . logon to https://secure.ebs.in/
    b
    . Go to settings
    c . You can find Account Name, Account ID and Secret Key in Account              Information
  2. $accound_id = "5880"; 
    This is your test id. For real time - Go to settings, get Acccount ID
  3. $final_amount = "2"; (product amount)
  4. $order_no = "123"; (test order number)
  5. $return_url = "http://localhost/response.php?DR={DR}"

    return url is where the EBS server traverse after the transaction is complete.

    This includes Transaction success, Transaction Failure, product details, which can be viewed on the merchant side.

    {DR} is the encoded details of the payment response.
  6. $mode = "TEST"; ('TEST' for testing and 'LIVE' for live).
  7. $hash_key = $key."|".$account_id."|".$finalamount."|".$order_no."|".$return_url."|".$mode;
  8. $secure_hash = MD5($hash_key );

    Here the credentials has to be encrypted before sending it to the EBS server.

  9. key,account_id,finalamount,order_no,return_url,mode has to be concatenate with pipe('|') characters. And then it has to be encrypted using MD5 hashing.
HTML Form

Form method should be "POST" and the posting URL should be 

https://secure.ebs.in/pg/ma/sale/pay

<form method="post" action="https://secure.ebs.in/pg/ma/sale/pay" name="frmTransaction" id="frmTransaction">
<input name="account_id" type="text" value="5880"><br>
<input name="return_url" type="text" size="60" value="http://localhost/response.php?DR={DR}"><br>
<input name="mode" type="text" size="60" value="TEST"><br>
<input name="reference_no" type="text" value="123"><br>
<input name="description" type="text" value="sample model"><br>
<input name="name" type="text" maxlength="255" value="u1"><br>
<input name="address" type="text" maxlength="255" value="a1"><br>
<input name="city" type="text" maxlength="255" value="c1"><br>
<input name="state" type="text" maxlength="255" value="s1"><br>
<input name="postal_code" type="text" maxlength="255" value="z1"><br>
<input name="country" type="text" maxlength="255" value="c1"><br>
<input name="phone" type="text" maxlength="255" value="p1"><br>
<input name="email" type="text" size="60" value="e1"><br>
<input name="secure_hash" type="text" size="60" value="<?php echo $secure_hash; ?>"><br>
<input type="text" name="amount" id="amount" readonly="" value="2"><br>
<input name="page_id" id="page_id" type="text" value="2231" />
<input type="submit" value="Place an Order" id="submit" name="submit">
</form>

The name of the concatenated hashing values must be 'secure_hash' only.

Javascript secure hashing

Now keeping the value of 'secure_hash' empty and then appending the hashed value from javascript to the input.

$('document').ready(function(){
    var key = "ebskey";
   var account_id = "5880";
   var finalamount = 2;
   var order_no = "123";
   var return_url = "http://localhost/customebs/res.php?DR={DR}";
   var mode = "TEST";

   var hash = key + "|" +
  account_id + "|" + finalamount + "|" + order_no + "|" + return_url + "|" + mode;

   var secureHash = CryptoJS.MD5(
hash);
   
   $('#secure_hash').val(secureHash);

});


Capturing the transaction response - response.php

$secret_key = "ebskey";  
   // Your Secret Key
if(isset($_GET['DR'])) {
    require('secure.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]);
     }
}
if(($response['ResponseCode'] == 0))
{
?><table><?php
    foreach( $response as $key => $value) 
    {
        ?><tr><td><?php echo $key;?></td><td><?php echo $value; ?></td></tr><?php          
    }
?></table><?php
}
// payment failed
if(($response['ResponseCode'] != 0))
{
?><table><?php
    foreach( $response as $key => $value) 
    {
       ?><tr><td><?php echo $key;?></td><td><?php echo $value; ?></td></tr><?php
    }
?></table><?php
}


Decrypting the response - Secure.php

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

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

After Submitting the Form,


You must get the below payment page, for the users to enter the card details.



The success credentials for Testing purpose would be


Name on card - ebs
card number - 4111-1111-1111-1111
card expiry - 07/2016
cvv - 123


The transaction completion status will traverse to response.php. and the response will look like this






















Check Lists

  1. To work on live, you have to enable 'Secure Hash Validation' on admin panel.
    Log On to https://secure.ebs.in
    Go to Settings
    Scroll down to find 'Secure Hash Validation' on 'Request Preference'
    'Enabled' - update
  2. To have custom payment page for the users,
    Log On to https://secure.ebs.in
    Go to Payment Pages - Create New Page
    After creation, a 'Page ID' will generate.
    You can just pass page_id inside HTML form to call the specific page as the custom payment page.
    <input name="page_id" id="page_id" value="2180">
  3. Make sure you are Logged Out of https://secure.ebs.in, while submitting form to get Payment Page. If you are logged in, the URL will go to https://secure.ebs.in/pg/ma/reporting/graph/ 
  4. 'Secure Hash Validation Failed' - check 'secure_hash' parameter. It should be encrypted perfectly with these (key, account_id, finalamount, order_no, return_url, mode) values, with pipe(|) concatenation.
  5. 'Invalid accound ID' - For testing purpose, account ID must be '5880'. For live, check your admin panel.
  6. 'index.php' - Should be the last page just before 'https://secure.ebs.in/pg/ma/sale/pay' is submitted through form.

Comments

Popular posts from this blog

Exploring Coorg , Karnataka

Exploring Western Ghats, Karnataka

The Electronic Fuel Injection