CCAvenue payment integration : PHP
1. Implementation of CCAvenue gateway is very simple.
2. First you need to register with CCAvenue, they will provide you a merchant id and working key, we need that Merchant ID in working to implement the payment gateway.
3. Basically CCAvenue use a redirect method to implement gateway, means they will redirect you to their site for the payment and thereafter they will return some values from their, these values contains status of your payment weather payment is successful or not.
4. So before sending the details to the CCAvenue we need to save the details so that latter we can compare and verify the payment.
5. We need to generate a signature(checksum) that is it contain some details like amount, orderid, working key, merchantid and rediecturl.
6. So on the buy page we need to validate the details at the server side, and after validation we need to STORE the details to our DB.
7. After saving all the details we need to redirect to another page it contains a form and the CCAvenue form variables in HIDDEN form and we need to auto submit after loading the page.
----------------------Page content--------------------------------------
$Merchant_Id = "your_merchantid";//
$Order_Id ="orderid";//unique ORDER ID that should be passed to payment gateway
$WorkingKey = "working_key";//Given to merchant by CCAavenue
$Redirect_Url ="sucessurl";
$Checksum = getCheckSum($Merchant_Id,$Amount,$Order_Id ,$Redirect_Url,$WorkingKey); // Validate All value
//******************************creating a signature using the given details for security reasons
function getchecksum($MerchantId,$Amount,$OrderId ,$URL,$WorkingKey)
$str ="$MerchantId|$OrderId|$Amount|$URL|$WorkingKey";
$adler = adler32($adler,$str);
function adler32($adler , $str)
$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;
//************************************************************leftshift function
function leftshift($str , $num)
for( $i = 0 ; $i < (64 - strlen($str)) ; $i++)
for($i = 0 ; $i < $num ; $i++)
$str = substr($str , 1 ) ;
for ($n = 0 ; $n < strlen($num) ; $n++)
$dec = $dec + $temp*pow(2 , strlen($num) - $n - 1);
<form id="ccavenue" method="post" action="https://www.ccavenue.com/shopzone/cc_details.jsp">
<input type=hidden name="Merchant_Id" value="Merchant_Id">
<input type="hidden" name="Amount" value="Amount">
<input type="hidden" name="Order_Id" value="Order_Id">
<input type="hidden" name="Redirect_Url" value="success url">
<input type="hidden" name="TxnType" value="A">
<input type="hidden" name="ActionID" value="TXN">
<input type="hidden" name="Checksum" value="<?php echo $Checksum; ?>">
<input type="hidden" name="billing_cust_name" value="name of user">
<input type="hidden" name="billing_cust_address" value="address of user">
<input type="hidden" name="billing_cust_country" value="user country">
<input type="hidden" name="billing_cust_state" value="state of user">
<input type="hidden" name="billing_cust_city" value="city">
<input type="hidden" name="billing_zip" value="zip/pin code">
<input type="hidden" name="billing_cust_tel" value="telphone no">
<input type="hidden" name="billing_cust_email" value="emailid">
<input type="hidden" name="delivery_cust_name" value="user name">
<input type="hidden" name="delivery_cust_address" value="delivering address">
<input type="hidden" name="delivery_cust_country" value="delivering country">
<input type="hidden" name="delivery_cust_state" value="delivering state">
<input type="hidden" name="delivery_cust_tel" value="telphone no">
<input type="hidden" name="delivery_cust_notes" value="this is a test">
<input type="hidden" name="Merchant_Param" value="">
<input type="hidden" name="billing_zip_code" value="zip/pin">
<input type="hidden" name="delivery_cust_city" value="city">
<input type="submit" value="Buy Now" />
------------------End of page content--------------------------------------
8. After submitting these values the gateway will return some values like post url/get url
9. There are mainly 3 auth_status they are
a) Y successfully authorised by gateway
b) N Unsuccessful transaction
c) B not authenicated at this pont of time
10. Now we need to verify the payment gateway details send by CCavenue, as tampered or not for that we have to use the Verify checksum function.
--------------------------------------------------------------------------------------------
//Verify the the checksum
function verifychecksum($MerchantId,$OrderId,$Amount,$AuthDesc,$CheckSum,$WorkingKey)
$str = "$MerchantId|$OrderId|$Amount|$AuthDesc|$WorkingKey";
$adler = adler32($adler,$str);
function adler32($adler , $str)
$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;
function leftshift($str , $num)
for( $i = 0 ; $i < (64 - strlen($str)) ; $i++)
for($i = 0 ; $i < $num ; $i++)
$str = substr($str , 1 ) ;
for ($n = 0 ; $n < strlen($num) ; $n++)
$dec = $dec + $temp*pow(2 , strlen($num) - $n - 1);
---------------------------------------------------------------------------------
11. We need to pass the details into it, if it returns true than the details are ok and payment was successfull redirect to success page
12.If it function returns false then the details are tampered/manipulated while sending to our application and something wrong has occured and redirect to failed /unsuccessful page