title: Integrating CCAvenue with php
body: <p>I am a total newbie to payment gateways.
  I would like to integrate CCAvenue to my website using PHP.
  I have downloaded their Intergration kit, Included my merchant id and working key, set the account to active and tried to do a dummy transaction on the index file they have provided in my localhost. </p>
  
  <p>But,when I click on submit on the form it is taking me to CCAvenue Transaction error page without any error code and error description. </p>
  
  <p>Please let me know where I am making the mistake and what else I need to do.</p>
  
  <p>I would be great if anyone pointed to me to a tutorial other then the CCAvenue integration manual.</p>
  
  <p>Codes:
      Checkout.php   </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt; Checkout&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
   &lt;?php include('adler32.php')?&gt;
   &lt;?php include('Aes.php')?&gt;
   &lt;?php 
  
   error_reporting(0);
   $merchant_id=$_POST['Merchant_Id'];  // Merchant id(also User_Id) 
   $amount=$_POST['Amount'];            // your script should substitute the amount here                        in the quotes provided here
   $order_id=$_POST['Order_Id'];        //your script should substitute the order   description here in the quotes provided here
   $url=$_POST['Redirect_Url'];         //your redirect URL where your customer will be redirected after authorisation from CCAvenue
   $billing_cust_name=$_POST['billing_cust_name'];
   $billing_cust_address=$_POST['billing_cust_address'];
   $billing_cust_country=$_POST['billing_cust_country'];
   $billing_cust_state=$_POST['billing_cust_state'];
   $billing_city=$_POST['billing_city'];
   $billing_zip=$_POST['billing_zip'];
   $billing_cust_tel=$_POST['billing_cust_tel'];
   $billing_cust_email=$_POST['billing_cust_email'];
   $delivery_cust_name=$_POST['delivery_cust_name'];
   $delivery_cust_address=$_POST['delivery_cust_address'];
   $delivery_cust_country=$_POST['delivery_cust_country'];
   $delivery_cust_state=$_POST['delivery_cust_state'];
   $delivery_city=$_POST['delivery_city'];
   $delivery_zip=$_POST['delivery_zip'];
   $delivery_cust_tel=$_POST['delivery_cust_tel'];
   $delivery_cust_notes=$_POST['delivery_cust_notes'];
  
  
  $working_key=/*MY working Key*/;    //Put in the 32 bit alphanumeric key in the quotes provided here.
  
  
   $checksum=getchecksum($merchant_id,$amount,$order_id,$url,$working_key); // Method to       generate checksum
  
    $merchant_data=    'Merchant_Id='.$merchant_id.'&amp;Amount='.$amount.'&amp;Order_Id='.$order_id.'&amp;Redirect_Url='.$url  '&amp;billing_cust_name='.$billing_cust_name.'&amp;billing_cust_address='.$billing_cust_address.'&amp;billing_cust_country='.$billing_cust_country.'&amp;billing_cust_state='.$billing_cust_state.'&amp;billing_cust_city='.$billing_city.'&amp;billing_zip_code='.$billing_zip.'&amp;billing_cust_tel='.$billing_cust_tel.'&amp;billing_cust_email='.$billing_cust_email.'&amp;delivery_cust_name='.$delivery_cust_name.'&amp;delivery_cust_address='.$delivery_cust_address.'&amp;delivery_cust_country='.$delivery_cust_country.'&amp;delivery_cust_state='.$delivery_cust_state.'&amp;delivery_cust_city='.$delivery_city.'&amp;delivery_zip_code='.$delivery_zip.'&amp;delivery_cust_tel='.$delivery_cust_tel.'&amp;billing_cust_notes='.$delivery_cust_notes.'&amp;Checksum='.$checksum  ;
  
  $encrypted_data=encrypt($merchant_data,$working_key); // Method for encrypting the data.
  
  ?&gt;
  
  &lt;form method="post" name="redirect"   action="http://www.ccavenue.com/shopzone/cc_details.jsp"&gt; 
  &lt;?php
     echo "&lt;input type=hidden name=encRequest value=$encrypted_data&gt;";
     echo "&lt;input type=hidden name=Merchant_Id value=$merchant_id&gt;";
  
      ?&gt;
   &lt;/form&gt;
   &lt;script type='text/javascript'&gt;document.redirect.submit();&lt;/script&gt;
   &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>And my Redirecturl.php</p>
  
  <pre><code>&lt;?php include('Aes.php')?&gt;
  &lt;?php include('adler32.php')?&gt;
  &lt;?php
  
  
  error_reporting(0);
  $workingKey=/*My Working Key*/;     //Working Key should be provided here.
  $encResponse=$_POST["encResponse"];         //This is the response sent by the CCAvenue Server
  
  
  $rcvdString=decrypt($encResponse,$workingKey);      //AES Decryption used as per the specified working key.
  $AuthDesc="";
  $MerchantId="";
  $OrderId="";
  $Amount=0;
  $Checksum=0;
  $veriChecksum=false;
  
  $decryptValues=explode('&amp;', $rcvdString);
  $dataSize=sizeof($decryptValues);
  //******************************    Messages based on Checksum &amp; AuthDesc   **********************************//
  echo "&lt;center&gt;";
  
  
  for($i = 0; $i &lt; $dataSize; $i++) 
  {
      $information=explode('=',$decryptValues[$i]);
      if($i==0)   $MerchantId=$information[1];    
      if($i==1)   $OrderId=$information[1];
      if($i==2)   $Amount=$information[1];    
      if($i==3)   $AuthDesc=$information[1];
      if($i==4)   $Checksum=$information[1];  
  }
  
  $rcvdString=$MerchantId.'|'.$OrderId.'|'.$Amount.'|'.$AuthDesc.'|'.$workingKey;
  $veriChecksum=verifyChecksum(genchecksum($rcvdString), $Checksum);
  
  if($veriChecksum==TRUE &amp;&amp; $AuthDesc==="Y")
  {
      echo "&lt;br&gt;Thank you for shopping with us. Your credit card has been charged and your transaction is successful. We will be shipping your order to you soon.";
  
      //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($veriChecksum==TRUE &amp;&amp; $AuthDesc==="B")
  {
      echo "&lt;br&gt;Thank you for shopping with us.We will keep you posted regarding the status of your order through e-mail";
  
      //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($veriChecksum==TRUE &amp;&amp; $AuthDesc==="N")
  {
      echo "&lt;br&gt;Thank you for shopping with us.However,the transaction has been declined.";
  
      //Here you need to put in the routines for a failed
      //transaction such as sending an email to customer
      //setting database status etc etc
  }
  else
  {
      echo "&lt;br&gt;Security Error. Illegal access detected";
  
      //Here you need to simply ignore this and dont need
      //to perform any operation in this condition
  }
  
  
  echo "&lt;br&gt;&lt;br&gt;";
  
  
  //************************************  DISPLAYING DATA RCVD ******************************************//
  
  echo "&lt;table cellspacing=4 cellpadding=4&gt;";
  for($i = 0; $i &lt; $dataSize; $i++) 
  {
      $information=explode('=',$decryptValues[$i]);
          echo '&lt;tr&gt;&lt;td&gt;'.$information[0].'&lt;/td&gt;&lt;td&gt;'.$information[1].'&lt;/td&gt;&lt;/tr&gt;';
  }
  
  echo "&lt;/table&gt;&lt;br&gt;";
  echo "&lt;/center&gt;";
  ?&gt;
  </code></pre>
  
  <p>I have also included Adler.php and Aes.php which comes with the integration kit</p>