ccavenue payment gateway integration in codeigniter

In this post we will show you CCAvenue Payment Gateway Integration using PHP, hear for CCAvenue Payment Gateway Integration using PHP we will give you demo and CCAvenue Payment Gateway Integration using PHP example for implement.

ccavenue payment gateway integration in codeigniter

CCAvenue is a popular payment gateway that offers e-merchants a one stop solution for processing e-merchants ranging from credit card transaction to direct debit from their online bank accounts. It is designed to integrate quickly without any hassle. To integrate CCAvenue payment gateway in your website, you should have CCAvenue account and they will give you a merchant id and a unique key for your website to perform transaction. So here in this tutorial, I have explained easy steps to integrate CCAvenue Payment Gateway with PHP.

In this post, we will learn about Ccavenue Payment Gateway Integration In Php Demo with an example.

As I have explained earlier that it is very easy to integrate, you just need to pass required input filed to CCAvenue to complete transaction. The CCAvenue system expects certain input data with specific names to be sent to the CCAvenue website. For this reason, it is essential that the names of the input fields on the merchant website and the CCAvenue website should match exactly. Also there are some input filed values are mandatory like Merchant_Id, Amount and Order_Id. The Merchant_Id and working key will be assigned to you by CCAvenue. Below is form with action URL to CCAvenue and input field with required values.

Code for CCAvenue Payment Gateway Integration using PHP

<?php
// Merchant id provided by CCAvenue
$Merchant_Id = "5956854";
// Item amount for which transaction perform
$Amount = "999";
// Unique OrderId that should be passed to payment gateway
$Order_Id = "0254863";
// Add your Unique Key provided by CCAvenue
$WorkingKey= "";
// URL of Success page 
$setRedirect_Url="success.php";
$get_Checksum = getCheckSum($Merchant_Id,$Amount,$Order_Id ,$Redirect_Url,$WorkingKey);
?>
 
<h2 title='how to set CCAvenue Payment Gateway Integration using PHP'>Demo for how to CCAvenue Payment Gateway Integration using PHP</h2>
<form id="ccavenue" method="post" action="https://world.ccavenue.com/servlet/ccw.CCAvenueController">
    <!-- Add Merchant Id -->
    <input type=hidden name="Merchant_Id" value="Merchant_Id">
    <!-- Add Amount -->
    <input type="hidden" name="Amount" value="Amount">
    <!-- Add Order Id -->
    <input type="hidden" name="Order_Id" value="Order_Id">
    <!-- Add Redirect Url -->
    <input type="hidden" name="Redirect_Url" value="<?php echo $setRedirect_Url; ?>">
    <!-- Add Txn Type -->
    <input type="hidden" name="TxnType" value="A">
    <!-- Add Action ID -->
    <input type="hidden" name="ActionID" value="TXN">
    <!-- Add Check sum -->
    <input type="hidden" name="Checksum" value="<?php echo $get_Checksum; ?>">
    <!-- Add billing cust name -->
    <input type="hidden" name="billing_cust_name" value="name of user">
    <!-- Add address of use -->
    <input type="hidden" name="billing_cust_address" value="address of user">
    <!-- Add user country -->
    <input type="hidden" name="billing_cust_country" value="user country">
    <!-- Add state of user -->
    <input type="hidden" name="billing_cust_state" value="state of user">
    <!-- Add city of user -->
    <input type="hidden" name="billing_cust_city" value="city">
    <!-- Add zip code of user -->
    <input type="hidden" name="billing_zip" value="zip/pin code">
    <!-- Add telphone of user -->
    <input type="hidden" name="billing_cust_tel" value="telphone no">
    <!-- Add email id of user -->
    <input type="hidden" name="billing_cust_email" value="emailid">
    <!-- Add name of user -->
    <input type="hidden" name="delivery_cust_name" value="user name">
    <!-- Add delivering address of user -->
    <input type="hidden" name="delivery_cust_address" value="delivering address">
    <!-- Add delivering country of user -->
    <input type="hidden" name="delivery_cust_country" value="delivering country">
    <!-- Add delivering state of user -->
    <input type="hidden" name="delivery_cust_state" value="delivering state">
    <!-- Add telphone no of user -->
    <input type="hidden" name="delivery_cust_tel" value="telphone no">
    <!-- Add notes of user -->
    <input type="hidden" name="delivery_cust_notes" value="this is a test">
    <!-- Add Merchant Param of user -->
    <input type="hidden" name="Merchant_Param" value="">
    <!-- Add billing zip code of user -->
    <input type="hidden" name="billing_zip_code" value="zip/pin">
    <!-- Add delivery cust city of user -->
    <input type="hidden" name="delivery_cust_city" value="city">
    <input type="submit" value="Buy Now" />
</form>

After the fruitful installment, the CCavenue will divert to your furnished achievement URL with the some exchange points of interest with $_GET variable having auth_status. In the event that it is “Y” at that point it is effectively approved by entryway. In the event that it is “N” at that point it is unsuccessful exchange. In the event that it is “B” at that point it is not confirmed now of time.

Read Also:  Get PHP Session Value using AJAX/Jquery

We additionally need to confirm the installment passage points of interest send by CCavenue is altered or not for that we need to utilize the check checksum work verifychecksum($MerchantId,$OrderId,$Amount,$AuthDesc,$CheckSum,$WorkingKey). We have to pass the exchange points of interest to this capacity. In the event that it returns valid than the points of interest are alright and installment page was effectively divert to progress page. On the off chance that it returns false then the subtle elements are altered while sending to our application and something incorrectly has happened and need to divert to unsuccessful page.

Read Also:  PHP Add JSON object Data Example

Use below PHP functions to get check sum using function getchecksum() and verify returned checksum using function verifychecksum().

Get the checksum of product

<?php
// Get the checksum
function getchecksum($MerchantId,$Amount,$OrderId ,$URL,$WorkingKey)
{
    $str ="$MerchantId|$OrderId|$Amount|$URL|$WorkingKey";
    $adler = 1;
    $adler = adler32($adler,$str);
    return $adler;
}
?>

Verify the the checksum of product

<?php
// Verify the the checksum
function verifychecksum($MerchantId,$OrderId,$Amount,$AuthDesc,$CheckSum,$WorkingKey)
{
    $str = "$MerchantId|$OrderId|$Amount|$AuthDesc|$WorkingKey";
    $adler = 1;
    $adler = adler32($adler,$str);
    if($adler == $CheckSum)
    return "true";
    else
    return "false" ;
}
?>

Verify the the checksum of product

<?php
function leftshift($str , $num) {
    $str = DecBin($str);
    for( $i = 0 ; $i < (64 – strlen($str)) ; $i++)
    $str = "0".$str ;
    for($i = 0 ; $i < $num ; $i++) {
        $str = $str."0";
        $str = substr($str , 1 ) ;
    }
    return cdec($str) ;
}
?>

Get cdec for Verify the the checksum of product

<?php
function cdec($num) {
    for ($n = 0 ; $n < strlen($num) ; $n++) {
        $temp = $num[$n] ;
        $dec = $dec + $temp*pow(2 , strlen($num) – $n – 1);
    }
    return $dec;
}
?>

Get adler32 Verify the the checksum of product

<?php
function adler32($adler , $str) {
    $BASE = 65521 ;
    $s1 = $adler & 0xffff ;
    $s2 = ($adler >> 16) & 0xffff;
    for($i = 0 ; $i < strlen($str) ; $i++) {
        $s1 = ($s1 + Ord($str[$i])) % $BASE ;
        $s2 = ($s2 + $s1) % $BASE ;
    }
    return leftshift($s2 , 16) + $s1;
}
?>

Hope this code and post will helped you for implement CCAvenue Payment Gateway Integration using PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve pakainfo. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs pakainfo.com