iecwillow Posted March 19, 2009 Share Posted March 19, 2009 Hey all, I'm helping out a friend with his osCommerce-based store, and tried to add CTOPAY payment module, everything works fine, however CTOPAY claim that they could not get the web address where the payment coming from, the result on request.getHeader("referer") shows "null". Here is the code I currently use: <?php class ctopay { var $code, $title, $description, $enabled; /** * order status setting for pending orders * * @var int */ var $order_pending_status = 1; /** * order status setting for completed orders * * @var int */ var $order_status = DEFAULT_ORDERS_STATUS_ID; // class constructor function ctopay() { global $order; $this->code = 'ctopay'; if ($_GET['main_page'] != '') { $this->title = MODULE_PAYMENT_CTOPAY_TEXT_CATALOG_TITLE; // Payment Module title in Catalog } else { $this->title = MODULE_PAYMENT_CTOPAY_TEXT_ADMIN_TITLE; // Payment Module title in Admin } $this->description = MODULE_PAYMENT_CTOPAY_TEXT_DESCRIPTION; $this->sort_order = MODULE_PAYMENT_CTOPAY_SORT_ORDER; $this->enabled = ((MODULE_PAYMENT_CTOPAY_STATUS == 'True') ? true : false); if ((int)MODULE_PAYMENT_CTOPAY_ORDER_STATUS_ID > 0) { $this->order_status = MODULE_PAYMENT_CTOPAY_ORDER_STATUS_ID; } if (is_object($order)) $this->update_status(); $this->form_action_url = MODULE_PAYMENT_CTOPAY_HANDLER; } // class methods function update_status() { global $order, $db; if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_CTOPAY_ZONE > 0) ) { $check_flag = false; $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_CTOPAY_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id"); while ($check = tep_db_fetch_array($check_query)) { if ($check_query->fields['zone_id'] < 1) { $check_flag = true; break; } elseif ($check['zone_id'] == $order->delivery['zone_id']) { $check_flag = true; break; } $check_query->MoveNext(); } if ($check_flag == false) { $this->enabled = false; } } } function javascript_validation() { return false; } function selection() { return array('id' => $this->code, 'module' => MODULE_PAYMENT_CTOPAY_TEXT_CATALOG_LOGO, 'icon' => MODULE_PAYMENT_CTOPAY_TEXT_CATALOG_LOGO ); } function pre_confirmation_check() { return false; } function confirmation() { return array('title' => MODULE_PAYMENT_CTOPAY_TEXT_DESCRIPTION); } function process_button() { global $db, $order, $currencies; $MD5key = MODULE_PAYMENT_CTOPAY_MD5KEY; // $MerNo = MODULE_PAYMENT_CTOPAY_SELLER; // $BillNo =date("Ymdhis"); // $Currency = MODULE_PAYMENT_CTOPAY_MONEYTYPE; // if (MODULE_PAYMENT_CTOPAY_MONEYTYPE == 1) { $my_currency = 'CNY'; } else { $my_currency = 'USD'; } $Amount = number_format(($order->info['total']) * $currencies->get_value($my_currency), 2, '.', ''); // $DispAmount = $Amount; // //$ReturnURL = tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL'); // $ReturnURL = tep_href_link(FILENAME_PAYRESULT, '', 'SSL'); // for ($i=0; $i<sizeof($order->products); $i++) { $OrderDesc = $order->products[$i]["qty"] . ' x ' . $order->products[$i]["name"]; } $Remark = $OrderDesc; // $Language = MODULE_PAYMENT_CTOPAY_LANGUAGE; // $md5src = $MerNo.$BillNo.$Currency.$Amount.$Language.$ReturnURL.$MD5key; // $MD5info = strtoupper(md5($md5src)); // $process_button_string = tep_draw_hidden_field('MerNo', $MerNo) . tep_draw_hidden_field('Currency', $Currency) . tep_draw_hidden_field('BillNo', $BillNo) . tep_draw_hidden_field('Amount', $Amount) . tep_draw_hidden_field('DispAmount', $DispAmount) . tep_draw_hidden_field('ReturnURL', $ReturnURL) . tep_draw_hidden_field('Language', $Language) . tep_draw_hidden_field('MD5info', $MD5info) . tep_draw_hidden_field('OrderDesc', $OrderDesc) . tep_draw_hidden_field('Remark', $Remark) ; return $process_button_string; } function before_process() { global $_POST, $order, $currencies, $messageStack; // $BillNo = $_POST["BillNo"]; // $Currency = $_POST["Currency"]; // $BankID = $_POST["BankID"]; // $Amount = $_POST["Amount"]; // $Succeed = $_POST["Succeed"]; // $TradeNo = $_POST["TradeNo"]; // $Result = $_POST["Result"]; // $MD5info = $_POST["MD5info"]; // $Remark = $_POST["Remark"]; // $Drawee = $_POST["Drawee"]; // $MD5key = MODULE_PAYMENT_CTOPAY_MD5KEY; // $md5src = $BillNo.$Currency.$Amount.$Succeed.$MD5key; // $md5sign = strtoupper(md5($md5src)); // $this->tradeno = $TradeNo; $this->result = $Result; if($MD5info==$md5sign){ return true; // }else{ $messageStack->add_session('checkout_payment', 'FAILED', 'error'); tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false)); } } function after_process() { global $insert_id,$db; tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (comments, orders_id, orders_status_id, date_added) values ('Serial Number: " . $this->tradeno . " - Payment results: " . $this->result . " ' , '". (int)$insert_id . "','" . $this->order_status . "', now() )"); return true; } function after_order_create($zf_order_id) { global $db, $order; unset($_SESSION['payment']); } function output_error() { return false; } function check() { if (!isset($this->_check)) { $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_CTOPAY_STATUS'"); $this->_check = tep_db_num_rows($check_query); } return $this->_check; } function install() { global $db, $language, $module_type; if (!defined('MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_1_1')) include(DIR_FS_CATALOG_LANGUAGES . $_SESSION['language'] . '/modules/' . $module_type . '/' . $this->code . '.php'); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_1_1 . "', 'MODULE_PAYMENT_CTOPAY_STATUS', 'True', '" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_1_2 . "', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_2_1 . "', 'MODULE_PAYMENT_CTOPAY_SELLER', '1000', '" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_2_2 . "', '6', '2', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_3_1 . "', 'MODULE_PAYMENT_CTOPAY_MD5KEY', '12345678', '" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_3_2 . "', '6', '4', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_4_1 . "', 'MODULE_PAYMENT_CTOPAY_MONEYTYPE', 'CNY', '" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_4_2 . "', '6', '6', 'tep_cfg_select_option(array(\'1\', \'6\', \'7\', \'10\', \'15\'), ', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_5_1 . "', 'MODULE_PAYMENT_CTOPAY_LANGUAGE', 'CNY', '" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_5_2 . "', '6', '8', 'tep_cfg_select_option(array(\'1\', \'2\', \'3\'), ', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_6_1 . "', 'MODULE_PAYMENT_CTOPAY_ZONE', '0', '" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_6_2 . "', '6', '10', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_7_1 . "', 'MODULE_PAYMENT_CTOPAY_ORDER_STATUS_ID', '2', '" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_7_2 . "', '6', '12', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_8_1 . "', 'MODULE_PAYMENT_CTOPAY_SORT_ORDER', '0', '" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_8_2 . "', '6', '12', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_9_1 . "', 'MODULE_PAYMENT_CTOPAY_HANDLER', 'http://payment.ctopay.com/payment/Interface', '" . MODULE_PAYMENT_CTOPAY_TEXT_CONFIG_9_2 . "', '6', '14', '', now())"); } function remove() { tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key LIKE 'MODULE_PAYMENT_CTOPAY%'"); } function keys() { return array( 'MODULE_PAYMENT_CTOPAY_STATUS', 'MODULE_PAYMENT_CTOPAY_SELLER', 'MODULE_PAYMENT_CTOPAY_MD5KEY', 'MODULE_PAYMENT_CTOPAY_ZONE', 'MODULE_PAYMENT_CTOPAY_MONEYTYPE', 'MODULE_PAYMENT_CTOPAY_LANGUAGE', 'MODULE_PAYMENT_CTOPAY_ORDER_STATUS_ID', 'MODULE_PAYMENT_CTOPAY_SORT_ORDER', 'MODULE_PAYMENT_CTOPAY_HANDLER' ); } } ?> Just for reference, here is the CTOPAY website: http://www.ctopay.com/ctopay/en/service.jsp Any help would be much appreciated. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.