Friday, 8 January 2016

EBS payment getway development using php

In this Post I will explain how to integrate EBS payment gateway in php and uses of ebs_payment_getway.php page, Rc43.php page and ebs_payment_response.php Pages.
First I will explain basic components of EBS Integration :
ebs_payment_getway.php page:
             Last page of Merchant website before connecting to EBS payment integration. Merchant should collect the Customer Information and post to EBS the specified parameters.

Rc43.php page:
            File used to decrypt the EBS response

ebs_payment_response.php Page:
            Page to which the Merchant receives the response from EBS on completion of sale process.
            The response parameters given back to the return URL are listed below. The response is provided using POST method to the URL defined under

ReturnURL
             parameter in the payment request.
Response is provided using POST method to the URL defined under ReturnURL parameter in the payment request. $response[‘ResponseCode’] == 0 means transaction successfully completed. Other than 0 value transactions failed.
For making LIVE, change the mode parameter value from TEST to LIVE in ebs_payment_getway.php file.

ebs_payment_getway.php Code

Needed varible for the page
             Please do not ommit any variable and maintain the secure hash veriable
<?php
$account_id='123456';//Sheller Ebs Account Id
$return_url="http://Localhost/ebs_payment_response.php?DR={DR}";//Returning url for detect success or unsuccess
$mode='TEST';// the mode of payment TEST/LIVE $order_no='Order_001234';//the purchase no of salling product $description='TESTING PRODUCT FOR PURCHASING ON EBS ';//description of salling product
$client_name='Client Name Here';//the name of byer
$client_address='City Center, Kolkata';//the address of byer $client_city='Kolkata';//the city of byer
$client_state='West Bengal';//the state of byer
$client_zipcode='700012';//the zipcode of byer
$client_country='India';//the country of byer
$client_phonenumber='+91 9999 999 999';//the contact no of byer $client_email='developerhiran@gmail.com';//the email address of byer $total_amount='100.00';//the bying total amount
$key='9876543210';//Sheller Ebs Key
$hash = $key."|".$account_id."|".$finalamount."|".$order_no."|".$return_url."|".$mode;//is for make a secure payment as user cannot able to change the description or any information
$secure_hash = md5($hash);//to encript the hash data
 ?>

Noe the html form
         Please do not change the name of the fields and acction paramiter of the form

<form method="post" action="https://secure.ebs.in/pg/ma/sale/pay" name="frmTransaction" id="frmTransaction">
         <input name="account_id" type="hidden" value="<?php echo $account_id; ?>" readonly/>
         <input name="return_url" type="hidden" size="60" value="<?php echo $return_url; ?>">
         <input name="mode" type="hidden" size="60" value="<?php echo $mode; ?>" readonly>
         <p>
                    <lable class="user-left">Order No:</lable>
                    <input name="reference_no" type="text" value="<?php echo $order_no; ?>" readonly>
         </p>
         <p>
                    <lable class="user-left"> Description:</lable>
                    <input name="description" type="text" value="<?php echo $description; ?>" readonly>
         </p>
         <p>
                     <lable class="user-left">Name:</lable>
                     <input name="name" type="text" maxlength="255" value="<?php echo $client_name; ?>" readonly>
         </p>
         <p>
                     <lable class="user-left">Address:</lable>
                     <input name="address" type="text" maxlength="255" value="<?php echo $client_address; ?>" readonly>
         </p>
         <p>
                     <lable class="user-left" > City:</lable>
                     <input name="city" type="hidden" maxlength="255" value="<?php echo $client_city; ?>" readonly>
         </p>
         <P>
                     <lable class="user-left" > State:</lable>
                     <input name="state" type="hidden" maxlength="255" value="<?php echo $client_state; ?>" readonly>
          </P>
          <p>
                     <lable class="user-left">Zipcode:</lable>
                     <input name="postal_code" type="text" maxlength="255" value="<?php echo $client_zipcode; ?>" readonly>
          </p>
          <p>
                     <lable class="user-left">Country:</lable>
                     <input name="country" type="text" maxlength="255" value="<?php echo $client_country; ?>" readonly>
          </p>
          <p>
                      <lable class="user-left">Phone No:</lable>
                      <input name="phone" type="text" maxlength="255" value="<?php echo $client_phonenumber; ?>" readonly>
          </p>
          <p>
                       <lable class="user-left">Email Id:</lable>
                       <input name="email" type="text" value="<?php echo $client_email; ?>" readonly>
          </p>
                        <input name="secure_hash" type="hidden" size="60" value="<?php echo $secure_hash; ?>" readonly>
          </p>
                        <lable class="user-left">Total Charges:</lable>
                        <input type="text" name="amount" id="amount" readonly value="<?php echo $total_amount; ?>" readonly>
          </p>
          <p style="text-align:center;">
                       <input type="submit" value="Place an Order" id="submit" name="submit">
         </p>
</form>

Noe the Full code of payment page
<?php
$account_id='123456';//Sheller Ebs Account Id
$return_url="http://Localhost/ebs_payment_response.php?DR={DR}";//Returning url for detect success or unsuccess
$mode='TEST';// the mode of payment TEST/LIVE $order_no='Order_001234';//the purchase no of salling product $description='TESTING PRODUCT FOR PURCHASING ON EBS ';//description of salling product
$client_name='Client Name Here';//the name of byer
$client_address='City Center, Kolkata';//the address of byer $client_city='Kolkata';//the city of byer
$client_state='West Bengal';//the state of byer
$client_zipcode='700012';//the zipcode of byer
$client_country='India';//the country of byer
$client_phonenumber='+91 9999 999 999';//the contact no of byer $client_email='developerhiran@gmail.com';//the email address of byer $total_amount='100.00';//the bying total amount
$key='9876543210';//Sheller Ebs Key
$hash = $key."|".$account_id."|".$finalamount."|".$order_no."|".$return_url."|".$mode;//is for make a secure payment as user cannot able to change the description or any information
$secure_hash = md5($hash);//to encript the hash data
 ?>
<!DOCTYPE html>
<html>
    <head>
          <title>Ebs Payment Getway</title>
    </head>
    <body>
         <div class="my-account-content whitespace">
                 
<form method="post" action="https://secure.ebs.in/pg/ma/sale/pay" name="frmTransaction" id="frmTransaction">
         <input name="account_id" type="hidden" value="<?php echo $account_id; ?>" readonly/>
         <input name="return_url" type="hidden" size="60" value="<?php echo $return_url; ?>">
         <input name="mode" type="hidden" size="60" value="<?php echo $mode; ?>" readonly>
         <p>
                    <lable class="user-left">Order No:</lable>
                    <input name="reference_no" type="text" value="<?php echo $order_no; ?>" readonly>
         </p>
         <p>
                    <lable class="user-left"> Description:</lable>
                    <input name="description" type="text" value="<?php echo $description; ?>" readonly>
         </p>
         <p>
                     <lable class="user-left">Name:</lable>
                     <input name="name" type="text" maxlength="255" value="<?php echo $client_name; ?>" readonly>
         </p>
         <p>
                     <lable class="user-left">Address:</lable>
                     <input name="address" type="text" maxlength="255" value="<?php echo $client_address; ?>" readonly>
         </p>
         <p>
                     <lable class="user-left" > City:</lable>
                     <input name="city" type="hidden" maxlength="255" value="<?php echo $client_city; ?>" readonly>
         </p>
         <P>
                     <lable class="user-left" > State:</lable>
                     <input name="state" type="hidden" maxlength="255" value="<?php echo $client_state; ?>" readonly>
          </P>
          <p>
                     <lable class="user-left">Zipcode:</lable>
                     <input name="postal_code" type="text" maxlength="255" value="<?php echo $client_zipcode; ?>" readonly>
          </p>
          <p>
                     <lable class="user-left">Country:</lable>
                     <input name="country" type="text" maxlength="255" value="<?php echo $client_country; ?>" readonly>
          </p>
          <p>
                      <lable class="user-left">Phone No:</lable>
                      <input name="phone" type="text" maxlength="255" value="<?php echo $client_phonenumber; ?>" readonly>
          </p>
          <p>
                       <lable class="user-left">Email Id:</lable>
                       <input name="email" type="text" value="<?php echo $client_email; ?>" readonly>
          </p>
                        <input name="secure_hash" type="hidden" size="60" value="<?php echo $secure_hash; ?>" readonly>
          </p>
                        <lable class="user-left">Total Charges:</lable>
                        <input type="text" name="amount" id="amount" readonly value="<?php echo $total_amount; ?>" readonly>
          </p>
          <p style="text-align:center;">
                       <input type="submit" value="Place an Order" id="submit" name="submit">
         </p>
</form>
         </div>
    </body>
</html>

Rc43.php Code
<?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);
    }
}
?>
ebs_payment_response.php Code
<?php
$response = array();
$secret_key = 'abcd123456';     // Your Secret Key
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]);
     }
}

// payment sucess
if(($response['ResponseCode'] == 0))
{
    echo '<h2 style="text-align: center;">Thanks, Payment Success<h2><br/>';
    foreach( $response as $key => $value)
    {
        echo $key;
        echo ' => ';
        echo $value;
        echo '<br/>';
    }
}

// if payment failed
if(($response['ResponseCode'] != 0))
{
      echo '<h2 style="text-align: center;">Your Paument Fail <br/>Please Try again</h2>';
    foreach( $response as $key => $value)
    {
       echo $key;
       echo ' => ';
       echo $value;
       echo '<br/>';
    }
}
?>
EBS Testing Credentials
              EBS recommends you to make your Integration on Test Environment before going Live in the Production environment. EBS Test environment works in similar way to the Production Environment, except that you can test only Credit Card payments using the Test card details provided. To test the payments in Test mode, send the mode as TEST in payment request.

Name on card = ebs
Card Number= 4111 1111 1111 1111
Card Expiry Date= 07 (Jul) 2016
CVV = 123

Thanks A lot

No comments:

Post a Comment