CCAvenue is the largest Payment Gateway in India today and currently powers more than 85% of the e-commerce merchants in the country.
To integrate with this in your website, you need ccavenue merchant account, to create merchant visit this link.
Follow the steps to integrate ccavenue in your website:-
1. There are three important files you have to write into your website
First file is libfuncs.php3 – see the code below
This file has some functions which is for checkout and redirect pages, we must include this page in checkout and redirect pages
———————library functions starts here——————–
function getchecksum($MerchantId,$Amount,$OrderId ,$URL,$WorkingKey)
$adler = 1;
$adler = adler32($adler,$str);
$str = “$MerchantId|$OrderId|$Amount|$AuthDesc|$WorkingKey”;
$adler = 1;
$adler = adler32($adler,$str);
if($adler == $CheckSum)
return “true” ;
return “false” ;
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 ;
//echo “s1 : $s1 <BR> s2 : $s2 <BR>”;
return leftshift($s2 , 16) + $s1;
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 ) ;
//echo “str : $str <BR>”;
return cdec($str) ;
for ($n = 0 ; $n < strlen($num) ; $n++)
$temp = $num[$n] ;
$dec = $dec + $temp*pow(2 , strlen($num) – $n – 1);
———————library functions ends here——————–
Second file is checkout.php3 – see the code below
Checkout page contains values for checkout form in ccavenue site, here we are sending details of customer, merchant, redirect url, billing details in hidden field
———————checkout page starts here——————–
$Merchant_Id = “YourMerchantId”; //This id from CC Avenue for registered customer
$Amount = “YourAmount”; //Amount defined for your product
$Order_Id = “YourOrderId”; //This is for your reference id for your product
$Redirect_Url = “http://www.yourdomain.com/redirecturl.php3”; //This url is to redirect from ccavenue website to your website (redirecturl.php3) page
$WorkingKey = “YourWorkingKey”; //You can get this key from your CC Avenue account page
$Checksum = getCheckSum($Merchant_Id,$Amount,$Order_Id,$Redirect_Url,$WorkingKey); //This function is to verify data’s which sent to CC Avenue website from our website
//Customer address and contact details which is to fill automatically to CC Avenue Checkout form
$billing_cust_name = $billing_cust_name;
$billing_cust_address = $billing_cust_address;
$billing_cust_state = $billing_cust_state;
$billing_cust_country = $billing_cust_country;
$billing_cust_tel = $billing_cust_tel;
$billing_cust_email = $billing_cust_email;
$delivery_cust_name = $delivery_cust_name;
$delivery_cust_address = $delivery_cust_address;
$delivery_cust_state = $delivery_cust_state;
$delivery_cust_country = $delivery_cust_country;
$delivery_cust_tel = $delivery_cust_tel;
$delivery_cust_notes = $delivery_cust_notes;
$Merchant_Param = $Merchant_Param;
$billing_city = $billing_city;
$billing_zip = $billing_zip;
$delivery_city = $delivery_city;
$delivery_zip = $delivery_zip;
//Payment chechout form, values are send into hidden field
<form method=”post” name=”checkout” id=”checkout” action=”https://www.ccavenue.com/shopzone/cc_details.jsp”>
<input type=hidden name=Merchant_Id value=”<?php echo $Merchant_Id; ?>”>
<input type=hidden name=Amount value=”<?php echo $Amount; ?>”>
<input type=hidden name=Order_Id value=”<?php echo $Order_Id; ?>”>
<input type=hidden name=Redirect_Url value=”<?php echo $Redirect_Url; ?>”>
<input type=hidden name=Checksum value=”<?php echo $Checksum; ?>”>
<input type=”hidden” name=”billing_cust_name” value=”<?php echo $billing_cust_name; ?>”>
<input type=”hidden” name=”billing_cust_address” value=”<?php echo $billing_cust_address; ?>”>
<input type=”hidden” name=”billing_cust_country” value=”<?php echo $billing_cust_country; ?>”>
<input type=”hidden” name=”billing_cust_state” value=”<?php echo $billing_cust_state; ?>”>
<input type=”hidden” name=”billing_zip” value=”<?php echo $billing_zip; ?>”>
<input type=”hidden” name=”billing_cust_tel” value=”<?php echo $billing_cust_tel; ?>”>
<input type=”hidden” name=”billing_cust_email” value=”<?php echo $billing_cust_email; ?>”>
<input type=”hidden” name=”delivery_cust_name” value=”<?php echo $delivery_cust_name; ?>”>
<input type=”hidden” name=”delivery_cust_address” value=”<?php echo $delivery_cust_address; ?>”>
<input type=”hidden” name=”delivery_cust_country” value=”<?php echo $delivery_cust_country; ?>”>
<input type=”hidden” name=”delivery_cust_state” value=”<?php echo $delivery_cust_state; ?>”>
<input type=”hidden” name=”delivery_cust_tel” value=”<?php echo $delivery_cust_tel; ?>”>
<input type=”hidden” name=”delivery_cust_notes” value=”<?php echo $delivery_cust_notes; ?>”>
<input type=”hidden” name=”Merchant_Param” value=”<?php echo $Merchant_Param; ?>”>
<input type=”hidden” name=”billing_cust_city” value=”<?php echo $billing_city; ?>”>
<input type=”hidden” name=”billing_zip_code” value=”<?php echo $billing_zip; ?>”>
<input type=”hidden” name=”delivery_cust_city” value=”<?php echo $delivery_city; ?>”>
<input type=”hidden” name=”delivery_zip_code” value=”<?php echo $delivery_zip; ?>”>
———————checkout page ends here——————–
Third file is redirect.php3 – see the code below
This is the sample RedirectURL PHP script. It can be directly used for integration with CCAvenue. You need to simply change the variables to match your variables as well as insert routines for handling a successful or unsuccessful transaction.
return values i.e the parameters namely Merchant_Id,Order_Id,Amount,AuthDesc,Checksum,billing_cust_name,billing_cust_address,billing_cust_country,billing_cust_tel,billing_cust_email,delivery_cust_name,delivery_cust_address,delivery_cust_tel,billing_cust_notes,Merchant_Param POSTED to this page by CCAvenue.
———————redirect page starts here——————–
$Checksum = verifyChecksum($Merchant_Id,$Order_Id,$Amount,$AuthDesc,$Checksum,$WorkingKey);
if($Checksum==”true” && $AuthDesc==”Y”)
$_SESSION[‘Msg’]=”Your credit card has been charged and your transaction is successful. For your ordered id : “.$Order_Id;
//Here you need to put in the routines for a successful
//transaction such as sending an email to customer,
//setting database status, informing logistics etc etc
else if($Checksum==”true” && $AuthDesc==”B”)
$_SESSION[‘Msg’]=”We will keep you posted regarding the status of your order through e-mail. For your header(“location:redirect_to_you_wissed_page);
//Here you need to put in the routines/e-mail for a “Batch Processing” order
//This is only if payment for this transaction has been made by an American Express Card
//since American Express authorisation status is available only after 5-6 hours by mail from ccavenue and at the “View Pending Orders”
else if($Checksum==”true” && $AuthDesc==”N”)
$_SESSION[‘Msg’]=”The transaction has been declined. For your ordered id : “.$Order_Id;
//Here you need to put in the routines for a failed
//transaction such as sending an email to customer
//setting database status etc etc
$_SESSION[‘Msg’]=”Security Error. Illegal access detected . For your ordered id : “.$Order_Id;
//Here you need to simply ignore this and dont need
//to perform any operation in this condition
———————redirect page ends here——————–
Upload these files in the same file name as I mentioned in your server.
3. In the checkout page you have seen a Form with following parameters. You need to pass corresponding values to these parameters.
3.1 Merchant_Id: This ID is generated for you at the time of activation of your site.This Member ID uniquely identifies you as a Member of CCAvenue.
You can get your CCAvenue Merchant Id/User Id at “Generate Key” of “Settings & Options” section.
3.2 Order_Id: A Unique alphanumeric ID generated by you to uniquely identify this order. The Description/Order ID should be unique since it would allow you to identify the transaction easily.
3.3 Amount: Amount is the total amount of the transaction(greater than 0) in INR, without a currency symbol or other non-numeric character. only a decimal allowed.
3.4 Checksum: This refers to a random numeric string generated using a mathematical algorithm (a complex quadratic equation) to ensure that data is not tampered along the way. The way it works is lets say a message has to be sent from A to B. A and B both mutually agree on a Key that only both of them possess. A checksum is generated by a mathematical function using the message and the Key as input. This checksum is then sent along with the message to B. B then recalculates this checksum using the Key and the same algorithm. If the checksum that B calculates is different from the checksum that A passed then the data was tampered along the way.
Note: This key also known as the Working Key is a 32 bit alphanumeric key is assigned to each merchant. Please note that you have to generate this key by logging in to your CCAvenue merchant account and using the “Generate Key” function at the “Settings & Options” menu. Please note that the working key is a vital security data and should not be shared with or exposed to anyone. CCAvenue strongly recommends changing of working key periodically (preferably monthly).
3.5 Merchant_param: This is an optional parameter you can send with any values of your choice.
3.6 Redirect_Url: Once the customer on your website has finished authenticating the transaction he is returned back to your website. The URL to which the customer returns back is called the Redirect URL.
Note: Once the authorization process has been completed the customer will be redirected to this URL to which we pass return values namely the AuthDesc parameter indicating the status of the transaction along with all of the parameters mentioned above.
4. Once all the above integration steps are taken care of and you are ready to go live/test,
4.1 Please login to your CCAvenue account
4.2 Go to “Settings & Options”
4.3 Click the “Generate Working Key”
4.4 Here, choose the “activate” option & click submit.
Note: The deactivate option will be checked by default. This means that the authorisation status of an order will not be available to you in real-time, but only by an order mail & at the “View Pending Orders”.
You could chose to activate/de-activate this real-time authorisation feature anytime by logging in to your CCAvenue account.
Once activated, you can test the integration with the gateway by placing an order using a LIVE card number for a nominal amount.(not more than Rs.10).Please enter the key word “SUB-MERCHANT TEST” in the Instructions/Notes text area in the CCAvenue Shipping/Billing Page.