7.1.12

CCAvenue payment integration php








  • Integrating CCavenue payment gateway is simple
  • We need a merchant id and working for implementing payment gateway
  • These two details will be given by CCavenue
  • They use a redirect model for payment
  • ie the user will be rediected to there site for making the payment
  • Before for sending the details to CCavenue we need to save the details so that we can verify the details after the payment
  • we need to generate a signature(checksum) that is it contain some details like amount, orderid, working key, merchantid and rediecturl
  • On the buy page on submitting we need a serverside validation of the details the user have entered and after that the user details need to be stored in our DB after the payment is successfully completed 
  • After entering all the details we need to redirect to another page it contain a form and the CCavenue form variables which are in hidden and we need to auto submit after loading the page

----------------------Page content--------------------------------------
<?php
$Merchant_Id = "your_merchantid";//
$Amount = "amount";
$Order_Id ="orderid";//unique Id that should be passed to payment gateway
$WorkingKey = "working_key";//Given to merchant by ccavenue
$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 = 1;
$adler = adler32($adler,$str);
return $adler;
}
//functions
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;
}
//leftshift function
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) ;
}
//cdec function
function cdec($num)
{
for ($n = 0 ; $n < strlen($num) ; $n++)
{
$temp = $num[$n] ;
$dec = $dec + $temp*pow(2 , strlen($num) - $n - 1);
}
return $dec;
}
?>
<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" />
</form>

------------------End of page content--------------------------------------


  • After the successful payment,CCavenue will redirect to our successurl with the some details as post url/get url


  • there are mainly 3 auth_status are there they are 
  • Y successfully authorised by gateway
  • N Unsuccessful transaction
  • B not authenicated at this pont of time


  • we need to verify the payment gateway details send by CCavenue is 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 = 1;
$adler = adler32($adler,$str);

if($adler == $CheckSum)
return "true" ;
else
return "false" ;
}
//functions
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;
}
//leftshift function
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) ;
}
//cdec function
function cdec($num)
{
for ($n = 0 ; $n < strlen($num) ; $n++)
{
$temp = $num[$n] ;
$dec = $dec + $temp*pow(2 , strlen($num) - $n - 1);
}
return $dec;
}
           ---------------------------------------------------------------------------------

  • 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
  • if it returns false then the details are tampered while sending to our application and something wrong has occured and redirect to failed /unsuccessful page

22 comments:

  1. Hey, nice post...love the way you have presented the whole story...it's
    always good to read and get to know quality stuff...

    Do visit my page and leave a comment if you like any of it...

    Techiezens Payment Gateway

    ReplyDelete
    Replies
    1. Hi I am new to payment gateway and i have an assignment. Need help .

      Delete
  2. Hi
    Thank you for this post. It helped me to integrate ccavenue payment gateway to my client website
    Rapid CMS Development

    ReplyDelete
  3. Hey, useful post...love the way you have presented the whole detail's...it's
    always good to read and get to know quality stuff...

    Do visit my page and leave a comment if you like any of it...

    Techiezens Payment Gateway

    ReplyDelete
  4. Anonymous13/12/12

    i m using ccavenue with php but when i fill up the form with merchant id and bit working key it redirect me to a blank page which has the url as:
    http://www.ccavenue.com/shopzone/cc_details.jsp

    i m unable to understand that whats going wrong.

    ReplyDelete
  5. Hi Manindra ... are u testing ur pages in live environment ??
    Plz check it on live environment (on ur live site)

    ReplyDelete
  6. Hi i need the ccavenue integration kit to be installed in my website legalserviceindia.com can you do it for me i will make the necessary service payment

    ReplyDelete
    Replies
    1. hey if u want i can provide u with the payment gateway integration services

      Delete
    2. i need too ccavenue integration in my website, I will pay website is http://booking.yahvihotels.in thanks

      Mubarak Malek
      9924444644
      sarvodaymobile @ gmail com

      Delete
  7. Hi, i am facing a issue that... after successful payment by the customer the page re-directs to order cancel page so the value is not storing in the db.. could some one help me to resolve this issue...thax.

    ReplyDelete
  8. what does the Authdesc means, from where will we get that. jelp me

    ReplyDelete
  9. Great post...

    But you didn't mentioned anything about how to track values that returning after payment.

    ReplyDelete
  10. I am designer and not a programmer, can anyone guide. Just i want when the users click the button , they will be redirected to the payment page. And they will enter the basic details(5 fields) + the amount.

    whether the above code come in payment page, where the pay now button is placed.

    What code has to be provided to button?

    Kindly please guide me.

    Thanks

    ReplyDelete
  11. Hi Akhilraj,

    Now this is for CCAvenue. What about integrating a Payment gateway which is given by our bank? they said that they will provide the API and we need to make some programming to get it worked. Will this method will work?

    ReplyDelete
    Replies
    1. Hi
      http://integrate-payment-gateway.blogspot.in/2012/08/what-is-authorize-and-capturing-in.html
      this might help you in getting Types of Payment method you are using
      and
      http://integrate-payment-gateway.blogspot.in/2012/07/how-to-integrate-payment-gateways-to.html
      this will help you in how to integrate payment gateway on your applictaion

      Delete
  12. Anonymous11/7/13

    It would be very kind if u explain this via a video tutorial.
    ping me: 2coldnot@gmail.com / fazilamir@rocketmail.com

    ReplyDelete
  13. Hi Guys, can just elaborate more on payment gateway integration using php

    ReplyDelete
    Replies
    1. Hi Romil

      http://integrate-payment-gateway.blogspot.in/2012/07/how-to-integrate-payment-gateways-to.html

      From this blog u will get a basic idea of hw to integrate a payment gateway

      http://integrate-payment-gateway.blogspot.in/2012/08/what-is-authorize-and-capturing-in.html

      And this will help u in different methods used by payment gateways.

      i think these two links will be helpful to you

      AKHILRAJ

      Delete
  14. Hello I m not getting anything in response please help me...however when some one make payment correctly with correct details payments is successfully deposited in account ..but how to check if payment is failed or success i m using bellow code for checking response please check it and help me to get out of this..

    ReplyDelete
  15. Hey, excellent post.the way you have offered the whole story.

    Do check out my web page and keep a statement if you like any of it
    Payment gateway for tech support

    ReplyDelete
  16. Anonymous22/11/13

    i am using your code to make a template for get payment for my wordpress ngo site.

    but this show error:Cannot redeclare adler32() (previously declared in C:\xampp\htdocs\cc.php:18) in C:\xampp\htdocs\cc.php on line 108
    can anyone tell me the solution?please help me.

    ReplyDelete
  17. Hi This is excellent one .
    I checked lot of blogs but this one is good and worked properly

    ReplyDelete