Zen Cart Logo
Forums / Addon Payment Modules / CCavenue plug in v 2.02

CCavenue plug in v 2.02

Views: 1,220

Results 1 to 1 of 1
11 Aug 2012, 6:00 AM
#1
vkd1980 avatar

vkd1980

New Zenner

Join Date:
Jul 2012
Location:
Kochi,Kerala
Posts:
58
Plugin Contributions:
2

CCavenue plug in v 2.02

There is a problem(http://www.zen-cart.com/showthread.php?170525-Super-Orders-v3-0-Support-Thread/page85) #850 in my installation of ZC1.5.0 while using CCavenue 2.02 modified by
Akhil123456, but not creating any problem when using CCavenue 2.01 by Dr Byte,

I have modified the code of 2.01 by DrByte , to use it in India, Can you check if there any bug or omission

<?php
class cavenue extends base
{
 var $code, $title, $description, $enabled;

////////////////////////////////////////////////////
// Class constructor -> initialize class variables.
// Sets the class code, description, and status.
////////////////////////////////////////////////////


 function cavenue()  {
   $this->code = 'cavenue';
   $this->title = MODULE_PAYMENT_CCAVENUE_TEXT_TITLE;
   $this->description = MODULE_PAYMENT_CCAVENUE_TEXT_DESCRIPTION;
   $this->sort_order = MODULE_PAYMENT_CCAVENUE_SORT_ORDER;
   $this->enabled = ((MODULE_PAYMENT_CCAVENUE_STATUS == 'True') ? true : false);
   if ((int)MODULE_PAYMENT_CCAVENUE_ORDER_STATUS_ID > 0) {
     $this->order_status = MODULE_PAYMENT_CCAVENUE_ORDER_STATUS_ID;
   }
   if (is_object($order)) $this->update_status();
   $this->form_action_url = 'https://www.ccavenue.com/shopzone/cc_details.jsp';
 }
 // class methods
 function update_status()
 {
   global $order, $db;
   if (($this->enabled == true) && ((int)MODULE_PAYMENT_CCAVENUE_ZONE > 0)) {
     $check_flag = false;
     $check_query = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_CCAVENUE_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
     while ($check = mysql_fetch_array($check_query)) {
       if ($check['zone_id'] < 1) {
         $check_flag = true;
         break;
       } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
         $check_flag = true;
         break;
       }
     }
     if ($check_flag == false) {
       $this->enabled = false;
     }
   }
   // disable the module if the order only contains virtual products
   if ($this->enabled == true) {
     if ($order->content_type == 'virtual') {
       $this->enabled = false;
     }
   }
 }

 function javascript_validation()
 {
   return false;
 }

 function selection()
 {
   return array('id' => $this->code , 'module' => $this->title);
 }

 function pre_confirmation_check()
 {
   return false;
 }

 function confirmation()
 {
   return false;
 }

 function process_button()
 {
   global $order, $currencies;
   if (MODULE_PAYMENT_CCAVENUE_CONVERSION == 'Enabled'){
   if (DEFAULT_CURRENCY <> 'INR'){
      $cOrderTotal = $currencies->get_value("INR") * $order->info['total'];
   }
} else {
 $cOrderTotal = $order->info['total'];
}
   $MerchantId = MODULE_PAYMENT_CCAVENUE_MERCHANT_ID;
   $Amount = $cOrderTotal //$order->info['total'];
   //$currencyType = "USD";
   $OrderId = $_SESSION['customer_id'] . '-' . date('Ymdhis');
   $Url = zen_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true, false);
   
   // Generate Checksum
   $WorkingKey = MODULE_PAYMENT_CCAVENUE_WORKING_KEY;
   $str = "$MerchantId|$OrderId|$Amount|$Url|$WorkingKey";
   $adler = 1;
   $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>";
   }
   $str = $s2;
   $num = 16;
   $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>";    
   }
   $num = $str;
   for ($n = 0; $n < strlen($num); $n ++) {
     $temp = $num[$n];
     $dec = $dec + $temp * pow(2, strlen($num) - $n - 1);
   }
   $Checksum = $dec + $s1;
   // End Generate Checksum
   
   //Variables to be passed to CCavenue as a POST  
   $process_button_string = zen_draw_hidden_field('Merchant_Id', $MerchantId) . 
                            zen_draw_hidden_field('Order_Id', $OrderId) . 
                            zen_draw_hidden_field('Amount', $Amount) . 
                            zen_draw_hidden_field('Checksum', $Checksum) . 
                            zen_draw_hidden_field('billing_cust_name', $order->customer['firstname']) . 
                            zen_draw_hidden_field('billing_last_name', $order->customer['lastname']) . 
                            zen_draw_hidden_field('billing_cust_address', $order->billing['street_address']) . 
                            zen_draw_hidden_field('billing_cust_city', $order->billing['city']) . 
                            zen_draw_hidden_field('billing_cust_state', $order->billing['state']) . 
                            zen_draw_hidden_field('billing_cust_country', $order->billing['country']['iso_code_2']) . 
                            zen_draw_hidden_field('billing_cust_zip', $order->billing['postcode']) . 
                            zen_draw_hidden_field('billing_cust_tel_No', $order->customer['telephone']) . 
                            zen_draw_hidden_field('billing_cust_email', $order->customer['email_address']) . 
                            zen_draw_hidden_field('delivery_cust_name', $order->delivery['firstname']) . 
                            zen_draw_hidden_field('delivery_last_name', $order->delivery['lastname']) . 
                            zen_draw_hidden_field('delivery_cust_address', $order->delivery['street_address']) . 
                            zen_draw_hidden_field('delivery_cust_city', $order->delivery['city']) . 
                            zen_draw_hidden_field('delivery_cust_state', $order->delivery['state']) . 
                            zen_draw_hidden_field('delivery_cust_country', $order->delivery['country']['iso_code_2']) . 
                            zen_draw_hidden_field('delivery_cust_zip', $order->delivery['postcode']) . 
                            zen_draw_hidden_field('delivery_cust_tel_No', $order->customer['telephone']) . 
                            zen_draw_hidden_field('Redirect_Url', urlencode($Url));
   return $process_button_string;
   
 }

 function before_process()
 {
   global $messageStack;
   $MerchantId = $_POST['Merchant_Id'];
   $Amount = $_POST['Amount'];
   $OrderId = $_POST['Order_Id'];
   $Checksum = $_POST['Checksum'];
   $AuthDesc = $_POST['AuthDesc'];
   
   // Generate Checksum
   $WorkingKey = MODULE_PAYMENT_CCAVENUE_WORKING_KEY;
   $str = "$MerchantId|$OrderId|$Amount|$AuthDesc|$WorkingKey";
   $adler = 1;
   $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>";
   }
   $str = $s2;
   $num = 16;
   $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>";
   }
   $num = $str;
   for ($n = 0; $n < strlen($num); $n ++) {
     $temp = $num[$n];
     $dec = $dec + $temp * pow(2, strlen($num) - $n - 1);
   }
   $sum = $dec + $s1;
   // End Generate Checksum

   if ($sum == $Checksum)
     $Checksum = 'true';
   else
     $Checksum = 'false';
   if ($Checksum != 'true') {
     $messageStack->add_session('checkout_payment', MODULE_PAYMENT_CCAVENUE_ALERT_ERROR_MESSAGE, 'error');
     zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
   }
   if ($Checksum == 'true' && $AuthDesc == 'N') {
     $messageStack->add_session('checkout_payment', MODULE_PAYMENT_CCAVENUE_TEXT_ERROR_MESSAGE, 'error');
     zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
   }
 }

 function after_process()
 {
   return false;
 }

 function output_error()
 {
   $output_error_string = '<table border="0" cellspacing="0" cellpadding="0" width="100%">' . "\n" . '  <tr>' . "\n" . '    <td class="main"> <font color="#FF0000"><b>' . MODULE_PAYMENT_CCAVENUE_TEXT_ERROR . '</b></font><br> ' . MODULE_PAYMENT_CCAVENUE_TEXT_ERROR_MESSAGE . ' </td>' . "\n" . '  </tr>' . "\n" . '</table>' . "\n";
   return $output_error_string;
 }

 function check()
 {
   global $db;
   if (! isset($this->_check)) {
     $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_CCAVENUE_STATUS'");
     $this->_check = $check_query->RecordCount();
   }
   return $this->_check;
 }

 function install()
 {
   global $db;
   $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable CCAVENUE Module', 'MODULE_PAYMENT_CCAVENUE_STATUS', 'True', 'Do you want to accept CCAVENUE payments?', '6', '1', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
   $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Merchant Id', 'MODULE_PAYMENT_CCAVENUE_MERCHANT_ID', 'CCAvenueMerchantID', 'The Merchant Id to use for the CCAVENUE service', '6', '2', now())");
   $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, use_function) values ('WorkingKey', 'MODULE_PAYMENT_CCAVENUE_WORKING_KEY', '', 'put in the 32 bit alphanumeric key.Please note that get this key ,login to your CCAvenue merchant account and visit the \"Generate Working Key\" section at the \"Settings & Options\" page.', '6', '2', now(), 'zen_cfg_password_display')");
   $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('CCAVENUE Payment Zone', 'MODULE_PAYMENT_CCAVENUE_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
   $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('CCAVENUE Sort order of  display.', 'MODULE_PAYMENT_CCAVENUE_SORT_ORDER', '0', 'Sort order of CCAVENUE display. Lowest is displayed first.', '6', '0', now())");
   $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Currency Converter', 'MODULE_PAYMENT_CCAVENUE_CONVERSION', 'Enabled', 'Currency Conversion', '6', '10', 'zen_cfg_select_option(array(\'Enabled\', \'Disable\'), ', now())");  
   $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('CCAVENUE Set Order Status', 'MODULE_PAYMENT_CCAVENUE_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
 }

 function remove()
 {
   $keys = implode(',', $this->keys());
   $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
 }

 function keys()
 {
   return array('MODULE_PAYMENT_CCAVENUE_STATUS' , 'MODULE_PAYMENT_CCAVENUE_MERCHANT_ID' , 'MODULE_PAYMENT_CCAVENUE_WORKING_KEY' , 'MODULE_PAYMENT_CCAVENUE_ZONE' , 'MODULE_PAYMENT_CCAVENUE_SORT_ORDER' , 'MODULE_PAYMENT_CCAVENUE_ORDER_STATUS_ID','MODULE_PAYMENT_CCAVENUE_CONVERSION');
 }
}

some one please guide me