Guest Posted February 17, 2003 Share Posted February 17, 2003 I was wondering if someone could give me a hand in writing a new osC Payment Module for SecurePay (www.securepay.com)? I have a new client who uses SecurePay as his processor. He has provided me with the documentation from SecurePay regarding what data they require for processing. I have been trying to modify an existing Payment Module in an attempt to get it to work with SecurePay, but I'm getting a little lost and sometimes feel like I'm going backwards. If you have created or modified a osC Payment Module, or know the osC Payment Module system fairly well, please let me know. I could really use your help. I would appreciate it. Thanks. -R Quote Link to comment Share on other sites More sharing options...
rseigel Posted February 17, 2003 Share Posted February 17, 2003 Something wrong with this one? http://www.oscommerce.com/community/contri...ions,842/page,4 :? I've never used it but it might be worth a peek. Quote Link to comment Share on other sites More sharing options...
Guest Posted February 17, 2003 Share Posted February 17, 2003 I am aware fo this mod and it's not that there is anything wrong with it... Its just that contribution happens to be for the Australian-based "www.securepay.com.AU", not for the US-based SecurePay (www.securepay.com). Unfortunately, they are not the same. And the data required is VERY different. I appreciate the heads-up though. Are you familiar with or have you written a Payment Module. If so... maybe you or someone that you can recommend could give me a hand? Thanks. -R Quote Link to comment Share on other sites More sharing options...
Guest Posted February 18, 2003 Share Posted February 18, 2003 I'm hoping someone can chime in and help me with this. I have been attempting to write a new payment module for SecurePay by modifying an exiting Payment Module. It shows up okay in Administration Program under Modules/Payment, but when I activate it (by pressing the green button), The SQL statements are being inserted into the MYSQL database. It doesn't change to green and is never "officially" activated. Here's the code I have been working on.... <?php /* $Id: securepay.php,v 1.0 2003/02/17 19:57:14 rn Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ class securepay { var $code, $title, $description, $enabled; // class constructor function securepay() { global $order; $this->code = 'securepay'; $this->title = MODULE_PAYMENT_SECUREPAY_TEXT_TITLE; $this->description = MODULE_PAYMENT_SECUREPAY_TEXT_DESCRIPTION; $this->enabled = ((MODULE_PAYMENT_SECUREPAY_STATUS == 'True') ? true : false); if ((int)MODULE_PAYMENT_SECUREPAY_ORDER_STATUS_ID > 0) { $this->order_status = MODULE_PAYMENT_SECUREPAY_ORDER_STATUS_ID; } if (is_object($order)) $this->update_status(); $this->form_action_url = 'https://www.securepay.com/secure1/index.asp'; } // class methods function update_status() { global $order; if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_SECUREPAY_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_SECUREPAY_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id"); while ($check = tep_db_fetch_array($check_query)) { if ($check['zone_id'] < 1) { $check_flag = true; break; } elseif ($check['zone_id'] == $order->billing['zone_id']) { $check_flag = true; break; } } if ($check_flag == false) { $this->enabled = false; } } } function javascript_validation() { $js = ' if (payment_value == "' . $this->code . '") {' . "n" . ' var cc_owner = document.checkout_payment.securepay_cc_owner.value;' . "n" . ' var cc_number = document.checkout_payment.securepay_cc_number.value;' . "n" . ' if (cc_owner == "" || cc_owner.length < ' . CC_OWNER_MIN_LENGTH . ') {' . "n" . ' error_message = error_message + "' . MODULE_PAYMENT_SECUREPAY_TEXT_JS_CC_OWNER . '";' . "n" . ' error = 1;' . "n" . ' }' . "n" . ' if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "n" . ' error_message = error_message + "' . MODULE_PAYMENT_SECUREPAY_TEXT_JS_CC_NUMBER . '";' . "n" . ' error = 1;' . "n" . ' }' . "n" . ' }' . "n"; return $js; } function selection() { global $order; for ($i=1; $i<13; $i++) { $expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000))); } $today = getdate(); for ($i=$today['year']; $i < $today['year']+10; $i++) { $expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i))); } $selection = array('id' => $this->code, 'module' => $this->title, 'fields' => array(array('title' => MODULE_PAYMENT_SECUREPAY_TEXT_CREDIT_CARD_OWNER, 'field' => tep_draw_input_field('securepay_cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'])), array('title' => MODULE_PAYMENT_SECUREPAY_TEXT_CREDIT_CARD_NUMBER, 'field' => tep_draw_input_field('securepay_cc_number')), array('title' => MODULE_PAYMENT_SECUREPAY_TEXT_CREDIT_CARD_EXPIRES, 'field' => tep_draw_pull_down_menu('securepay_cc_expires_month', $expires_month) . ' ' . tep_draw_pull_down_menu('securepay_cc_expires_year', $expires_year)))); return $selection; } function pre_confirmation_check() { global $HTTP_POST_VARS; include(DIR_WS_CLASSES . 'cc_validation.php'); $cc_validation = new cc_validation(); $result = $cc_validation->validate($HTTP_POST_VARS['securepay_cc_number'], $HTTP_POST_VARS['securepay_cc_expires_month'], $HTTP_POST_VARS['securepay_cc_expires_year']); $error = ''; switch ($result) { case -1: $error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4)); break; case -2: case -3: case -4: $error = TEXT_CCVAL_ERROR_INVALID_DATE; break; case false: $error = TEXT_CCVAL_ERROR_INVALID_NUMBER; break; } if ( ($result == false) || ($result < 1) ) { $payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($error) . '&securepay_cc_owner=' . urlencode($HTTP_POST_VARS['securepay_cc_owner']) . '&securepay_cc_expires_month=' . $HTTP_POST_VARS['securepay_cc_expires_month'] . '&securepay_cc_expires_year=' . $HTTP_POST_VARS['securepay_cc_expires_year']; tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false)); } $this->cc_card_type = $cc_validation->cc_type; $this->cc_card_number = $cc_validation->cc_number; $this->cc_expiry_month = $cc_validation->cc_expiry_month; $this->cc_expiry_year = $cc_validation->cc_expiry_year; } function confirmation() { global $HTTP_POST_VARS; $confirmation = array('title' => $this->title . ': ' . $this->cc_card_type, 'fields' => array(array('title' => MODULE_PAYMENT_SECUREPAY_TEXT_CREDIT_CARD_OWNER, 'field' => $HTTP_POST_VARS['securepay_cc_owner']), array('title' => MODULE_PAYMENT_SECUREPAY_TEXT_CREDIT_CARD_NUMBER, 'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)), array('title' => MODULE_PAYMENT_SECUREPAY_TEXT_CREDIT_CARD_EXPIRES, 'field' => strftime('%B, %Y', mktime(0,0,0,$HTTP_POST_VARS['securepay_cc_expires_month'], 1, '20' . $HTTP_POST_VARS['securepay_cc_expires_year']))))); return $confirmation; } function process_button() { global $HTTP_SERVER_VARS, $order, $customer_id; $process_button_string = tep_draw_hidden_field('x_Login', MODULE_PAYMENT_SECUREPAY_LOGIN) . tep_draw_hidden_field('x_Card_Num', $CardNumber) . tep_draw_hidden_field('x_Exp_Month', $HTTP_POST_VARS['securepay_cc_expires_month']) . tep_draw_hidden_field('x_Exp_Year', $HTTP_POST_VARS['securepay_cc_expires_year']) . tep_draw_hidden_field('x_Exp_Date', $HTTP_POST_VARS['securepay_cc_expires_month'] . $HTTP_POST_VARS['securepay_cc_expires_year']) . tep_draw_hidden_field('x_Amount', number_format($order->info['total'], 2)) . tep_draw_hidden_field('x_ADC_Relay_Response', 'TRUE') . tep_draw_hidden_field('x_ADC_URL', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', false)) . tep_draw_hidden_field('x_Method', MODULE_PAYMENT_SECUREPAY_METHOD) . tep_draw_hidden_field('x_Cust_ID', $customer_id) . tep_draw_hidden_field('x_Email_Customer', (MODULE_PAYMENT_SECUREPAY_EMAIL == '1'? 'TRUE': 'FALSE')) . tep_draw_hidden_field('x_Email_Merchant', (MODULE_PAYMENT_SECUREPAY_EMAIL_MERCHANT == '1'? 'TRUE': 'FALSE')) . tep_draw_hidden_field('x_Cust_Name', $order->customer['firstname'] . ' ' . $order->customer['lastname']) . tep_draw_hidden_field('x_first_name', $order->customer['firstname']) . tep_draw_hidden_field('x_last_name', $order->customer['lastname']) . tep_draw_hidden_field('x_address', $order->customer['street_address']) . tep_draw_hidden_field('x_city', $order->customer['city']) . tep_draw_hidden_field('x_state', $order->customer['state']) . tep_draw_hidden_field('x_zip', $order->customer['postcode']) . tep_draw_hidden_field('x_country', $order->customer['country']) . tep_draw_hidden_field('x_phone', $order->customer['telephone']) . tep_draw_hidden_field('x_email', $order->customer['email_address']) . tep_draw_hidden_field('x_ship_to_name', $order->delivery['firstname'] . ' ' . $order->delivery['lastname']) . tep_draw_hidden_field('x_ship_to_first_name', $order->delivery['firstname']) . tep_draw_hidden_field('x_ship_to_last_name', $order->delivery['lastname']) . tep_draw_hidden_field('x_ship_to_address', $order->delivery['street_address']) . tep_draw_hidden_field('x_ship_to_city', $order->delivery['city']) . tep_draw_hidden_field('x_ship_to_state', $order->delivery['state']) . tep_draw_hidden_field('x_ship_to_zip', $order->delivery['postcode']) . tep_draw_hidden_field('x_ship_to_country', $order->delivery['country']) . tep_draw_hidden_field('x_Customer_IP', $HTTP_SERVER_VARS['REMOTE_ADDR']); $process_button_string .= tep_draw_hidden_field(tep_session_name(), tep_session_id()); return $process_button_string; } function before_process() { global $HTTP_POST_VARS; $myorder["Merch_ID"] = $HTTP_POST_VARS['x_Login']; $myorder["Tr_Type"] = "SALE"; $myorder["CC_Method"] = "DataEntry"; $myorder["AVSREQ"] = "0"; /************ Convert Order Variables ********************/ $myorder["Amount"] = $HTTP_POST_VARS['x_Amount']; $myorder["Email"] = $HTTP_POST_VARS['x_email']; $myorder["CC_Number"] = $HTTP_POST_VARS['x_Card_Num']; $myorder["Name"] = $HTTP_POST_VARS['x_Cust_Name']; $myorder["Month"] = $HTTP_POST_VARS['x_Exp_Date']; $myorder["Year"] = $HTTP_POST_VARS['x_Exp_Year']; $myorder["Address"] = $HTTP_POST_VARS['x_address']; $myorder["City"] = $HTTP_POST_VARS['x_city']; $myorder["State"] = $HTTP_POST_VARS['x_state']; $myorder["Zip"] = $HTTP_POST_VARS['x_zip']; if ($HTTP_POST_VARS['Return_Code'] == Y) return; if ($HTTP_POST_VARS['Return_Code'] == N) { tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(MODULE_PAYMENT_SECUREPAY_TEXT_DECLINED_MESSAGE), 'SSL', true, false)); } // Code 3 is an error - but anything else is an error too (IMHO) tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(MODULE_PAYMENT_SECUREPAY_TEXT_ERROR_MESSAGE), 'SSL', true, false)); } function after_process() { return false; } function get_error() { global $HTTP_GET_VARS; $error = array('title' => MODULE_PAYMENT_SECUREPAY_TEXT_ERROR, 'error' => stripslashes(urldecode($HTTP_GET_VARS['error']))); return $error; } function check() { if (!isset($this->_check)) { $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_AUTHORIZENET_STATUS'"); $this->_check = tep_db_num_rows($check_query); } return $this->_check; } function install() { tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('900', 'Enable SecurePay Module', 'MODULE_PAYMENT_SECUREPAY_STATUS', 'True', 'Do you want to accept SecurePay payments?', '6', '0', 'tep_cfg_select_option(array('True', 'False'), ', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('901', 'Merchant ID', 'MODULE_PAYMENT_SECUREPAY_LOGIN', '000000', 'Your SecurePay Merchant ID used to access SecurePay', '6', '0', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('902', 'SecurePay Email', 'MODULE_PAYMENT_SECUREPAY_EMAIL', 'NONE', 'Email where to send the middle 8 number of the credit card (NONE for not to send)', '6', '0', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('903', 'SecurePay Server', 'MODULE_PAYMENT_SECUREPAY_SERVER', 'https://www.securepay.com/secure1/index.asp', 'SecurePay secure server', '6', '0', now())"); } function remove() { tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } function keys() { return array('MODULE_PAYMENT_SECUREPAY_STATUS', 'MODULE_PAYMENT_SECUREPAY_LOGIN', 'MODULE_PAYMENT_SECUREPAY_EMAIL', 'MODULE_PAYMENT_SECUREPAY_SERVER'); } } ?> Any ideas? Am I missing something? Please let me know! I really want to finish my clients new store, and this is the last piece to thye puzzle. Thanks! -R Quote Link to comment Share on other sites More sharing options...
elari Posted February 18, 2003 Share Posted February 18, 2003 look this function check() { if (!isset($this->_check)) { $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_AUTHORIZENET_STATUS'"); $this->_check = tep_db_num_rows($check_query); [/b] Quote Link to comment Share on other sites More sharing options...
Guest Posted February 19, 2003 Share Posted February 19, 2003 Thanks for catching that, elari! Now the SecurePay module shows a green light and active. Whether or not its actually going to work is a different story. I'm gonna do some testing tonite and see if I can get it to function correctly. I will post my test results later. Thanks again! -R Quote Link to comment Share on other sites More sharing options...
elari Posted February 20, 2003 Share Posted February 20, 2003 :) hope will work 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.