[ Index ] |
|
Code source de osCommerce 2.2ms2-060817 |
1 <?php 2 /* 3 $Id: psigate.php,v 1.17 2003/06/30 20:30:37 hpdl Exp $ 4 5 osCommerce, Open Source E-Commerce Solutions 6 http://www.oscommerce.com 7 8 Copyright (c) 2003 osCommerce 9 10 Released under the GNU General Public License 11 */ 12 13 class psigate { 14 var $code, $title, $description, $enabled; 15 16 // class constructor 17 function psigate() { 18 global $order; 19 20 $this->code = 'psigate'; 21 $this->title = MODULE_PAYMENT_PSIGATE_TEXT_TITLE; 22 $this->description = MODULE_PAYMENT_PSIGATE_TEXT_DESCRIPTION; 23 $this->sort_order = MODULE_PAYMENT_PSIGATE_SORT_ORDER; 24 $this->enabled = ((MODULE_PAYMENT_PSIGATE_STATUS == 'True') ? true : false); 25 26 if ((int)MODULE_PAYMENT_PSIGATE_ORDER_STATUS_ID > 0) { 27 $this->order_status = MODULE_PAYMENT_PSIGATE_ORDER_STATUS_ID; 28 } 29 30 if (is_object($order)) $this->update_status(); 31 32 $this->form_action_url = 'https://order.psigate.com/psigate.asp'; 33 } 34 35 // class methods 36 function update_status() { 37 global $order; 38 39 if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PSIGATE_ZONE > 0) ) { 40 $check_flag = false; 41 $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_PSIGATE_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id"); 42 while ($check = tep_db_fetch_array($check_query)) { 43 if ($check['zone_id'] < 1) { 44 $check_flag = true; 45 break; 46 } elseif ($check['zone_id'] == $order->billing['zone_id']) { 47 $check_flag = true; 48 break; 49 } 50 } 51 52 if ($check_flag == false) { 53 $this->enabled = false; 54 } 55 } 56 } 57 58 function javascript_validation() { 59 if (MODULE_PAYMENT_PSIGATE_INPUT_MODE == 'Local') { 60 $js = 'if (payment_value == "' . $this->code . '") {' . "\n" . 61 ' var psigate_cc_number = document.checkout_payment.psigate_cc_number.value;' . "\n" . 62 ' if (psigate_cc_number == "" || psigate_cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" . 63 ' error_message = error_message + "' . MODULE_PAYMENT_PSIGATE_TEXT_JS_CC_NUMBER . '";' . "\n" . 64 ' error = 1;' . "\n" . 65 ' }' . "\n" . 66 '}' . "\n"; 67 68 return $js; 69 } else { 70 return false; 71 } 72 } 73 74 function selection() { 75 global $order; 76 77 if (MODULE_PAYMENT_PSIGATE_INPUT_MODE == 'Local') { 78 for ($i=1; $i<13; $i++) { 79 $expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000))); 80 } 81 82 $today = getdate(); 83 for ($i=$today['year']; $i < $today['year']+10; $i++) { 84 $expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i))); 85 } 86 87 $selection = array('id' => $this->code, 88 'module' => $this->title, 89 'fields' => array(array('title' => MODULE_PAYMENT_PSIGATE_TEXT_CREDIT_CARD_OWNER, 90 'field' => $order->billing['firstname'] . ' ' . $order->billing['lastname']), 91 array('title' => MODULE_PAYMENT_PSIGATE_TEXT_CREDIT_CARD_NUMBER, 92 'field' => tep_draw_input_field('psigate_cc_number')), 93 array('title' => MODULE_PAYMENT_PSIGATE_TEXT_CREDIT_CARD_EXPIRES, 94 'field' => tep_draw_pull_down_menu('psigate_cc_expires_month', $expires_month) . ' ' . tep_draw_pull_down_menu('psigate_cc_expires_year', $expires_year)))); 95 } else { 96 $selection = array('id' => $this->code, 97 'module' => $this->title); 98 } 99 100 return $selection; 101 } 102 103 function pre_confirmation_check() { 104 global $HTTP_POST_VARS; 105 106 if (MODULE_PAYMENT_PSIGATE_INPUT_MODE == 'Local') { 107 include(DIR_WS_CLASSES . 'cc_validation.php'); 108 109 $cc_validation = new cc_validation(); 110 $result = $cc_validation->validate($HTTP_POST_VARS['psigate_cc_number'], $HTTP_POST_VARS['psigate_cc_expires_month'], $HTTP_POST_VARS['psigate_cc_expires_year']); 111 112 $error = ''; 113 switch ($result) { 114 case -1: 115 $error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4)); 116 break; 117 case -2: 118 case -3: 119 case -4: 120 $error = TEXT_CCVAL_ERROR_INVALID_DATE; 121 break; 122 case false: 123 $error = TEXT_CCVAL_ERROR_INVALID_NUMBER; 124 break; 125 } 126 127 if ( ($result == false) || ($result < 1) ) { 128 $payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($error) . '&psigate_cc_owner=' . urlencode($HTTP_POST_VARS['psigate_cc_owner']) . '&psigate_cc_expires_month=' . $HTTP_POST_VARS['psigate_cc_expires_month'] . '&psigate_cc_expires_year=' . $HTTP_POST_VARS['psigate_cc_expires_year']; 129 130 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false)); 131 } 132 133 $this->cc_card_type = $cc_validation->cc_type; 134 $this->cc_card_number = $cc_validation->cc_number; 135 $this->cc_expiry_month = $cc_validation->cc_expiry_month; 136 $this->cc_expiry_year = $cc_validation->cc_expiry_year; 137 } else { 138 return false; 139 } 140 } 141 142 function confirmation() { 143 global $HTTP_POST_VARS, $order; 144 145 if (MODULE_PAYMENT_PSIGATE_INPUT_MODE == 'Local') { 146 $confirmation = array('title' => $this->title . ': ' . $this->cc_card_type, 147 'fields' => array(array('title' => MODULE_PAYMENT_PSIGATE_TEXT_CREDIT_CARD_OWNER, 148 'field' => $order->billing['firstname'] . ' ' . $order->billing['lastname']), 149 array('title' => MODULE_PAYMENT_PSIGATE_TEXT_CREDIT_CARD_NUMBER, 150 'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)), 151 array('title' => MODULE_PAYMENT_PSIGATE_TEXT_CREDIT_CARD_EXPIRES, 152 'field' => strftime('%B, %Y', mktime(0,0,0,$HTTP_POST_VARS['psigate_cc_expires_month'], 1, '20' . $HTTP_POST_VARS['psigate_cc_expires_year']))))); 153 154 return $confirmation; 155 } else { 156 return false; 157 } 158 } 159 160 function process_button() { 161 global $HTTP_SERVER_VARS, $order, $currencies; 162 163 switch (MODULE_PAYMENT_PSIGATE_TRANSACTION_MODE) { 164 case 'Always Good': 165 $transaction_mode = '1'; 166 break; 167 case 'Always Duplicate': 168 $transaction_mode = '2'; 169 break; 170 case 'Always Decline': 171 $transaction_mode = '3'; 172 break; 173 case 'Production': 174 default: 175 $transaction_mode = '0'; 176 break; 177 } 178 179 switch (MODULE_PAYMENT_PSIGATE_TRANSACTION_TYPE) { 180 case 'Sale': 181 $transaction_type = '0'; 182 break; 183 case 'PostAuth': 184 $transaction_type = '2'; 185 break; 186 case 'PreAuth': 187 default: 188 $transaction_type = '1'; 189 break; 190 } 191 192 $process_button_string = tep_draw_hidden_field('MerchantID', MODULE_PAYMENT_PSIGATE_MERCHANT_ID) . 193 tep_draw_hidden_field('FullTotal', number_format($order->info['total'] * $currencies->get_value(MODULE_PAYMENT_PSIGATE_CURRENCY), $currencies->currencies[MODULE_PAYMENT_PSIGATE_CURRENCY]['decimal_places'])) . 194 tep_draw_hidden_field('ThanksURL', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true)) . 195 tep_draw_hidden_field('NoThanksURL', tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code, 'NONSSL', true)) . 196 tep_draw_hidden_field('Bname', $order->billing['firstname'] . ' ' . $order->billing['lastname']) . 197 tep_draw_hidden_field('Baddr1', $order->billing['street_address']) . 198 tep_draw_hidden_field('Bcity', $order->billing['city']); 199 200 if ($order->billing['country']['iso_code_2'] == 'US') { 201 $billing_state_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_id = '" . (int)$order->billing['zone_id'] . "'"); 202 $billing_state = tep_db_fetch_array($billing_state_query); 203 204 $process_button_string .= tep_draw_hidden_field('Bstate', $billing_state['zone_code']); 205 } else { 206 $process_button_string .= tep_draw_hidden_field('Bstate', $order->billing['state']); 207 } 208 209 $process_button_string .= tep_draw_hidden_field('Bzip', $order->billing['postcode']) . 210 tep_draw_hidden_field('Bcountry', $order->billing['country']['iso_code_2']) . 211 tep_draw_hidden_field('Phone', $order->customer['telephone']) . 212 tep_draw_hidden_field('Email', $order->customer['email_address']) . 213 tep_draw_hidden_field('Sname', $order->delivery['firstname'] . ' ' . $order->delivery['lastname']) . 214 tep_draw_hidden_field('Saddr1', $order->delivery['street_address']) . 215 tep_draw_hidden_field('Scity', $order->delivery['city']) . 216 tep_draw_hidden_field('Sstate', $order->delivery['state']) . 217 tep_draw_hidden_field('Szip', $order->delivery['postcode']) . 218 tep_draw_hidden_field('Scountry', $order->delivery['country']['iso_code_2']) . 219 tep_draw_hidden_field('ChargeType', $transaction_type) . 220 tep_draw_hidden_field('Result', $transaction_mode) . 221 tep_draw_hidden_field('IP', $HTTP_SERVER_VARS['REMOTE_ADDR']); 222 223 if (MODULE_PAYMENT_PSIGATE_INPUT_MODE == 'Local') { 224 $process_button_string .= tep_draw_hidden_field('CardNumber', $this->cc_card_number) . 225 tep_draw_hidden_field('ExpMonth', $this->cc_expiry_month) . 226 tep_draw_hidden_field('ExpYear', substr($this->cc_expiry_year, -2)); 227 } 228 229 return $process_button_string; 230 } 231 232 function before_process() { 233 return false; 234 } 235 236 function after_process() { 237 return false; 238 } 239 240 function get_error() { 241 global $HTTP_GET_VARS; 242 243 if (isset($HTTP_GET_VARS['ErrMsg']) && tep_not_null($HTTP_GET_VARS['ErrMsg'])) { 244 $error = stripslashes(urldecode($HTTP_GET_VARS['ErrMsg'])); 245 } elseif (isset($HTTP_GET_VARS['Err']) && tep_not_null($HTTP_GET_VARS['Err'])) { 246 $error = stripslashes(urldecode($HTTP_GET_VARS['Err'])); 247 } elseif (isset($HTTP_GET_VARS['error']) && tep_not_null($HTTP_GET_VARS['error'])) { 248 $error = stripslashes(urldecode($HTTP_GET_VARS['error'])); 249 } else { 250 $error = MODULE_PAYMENT_PSIGATE_TEXT_ERROR_MESSAGE; 251 } 252 253 return array('title' => MODULE_PAYMENT_PSIGATE_TEXT_ERROR, 254 'error' => $error); 255 } 256 257 function check() { 258 if (!isset($this->_check)) { 259 $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PSIGATE_STATUS'"); 260 $this->_check = tep_db_num_rows($check_query); 261 } 262 return $this->_check; 263 } 264 265 function install() { 266 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 ('Enable PSiGate Module', 'MODULE_PAYMENT_PSIGATE_STATUS', 'True', 'Do you want to accept PSiGate payments?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); 267 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Merchant ID', 'MODULE_PAYMENT_PSIGATE_MERCHANT_ID', 'teststorewithcard', 'Merchant ID used for the PSiGate service', '6', '2', now())"); 268 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 ('Transaction Mode', 'MODULE_PAYMENT_PSIGATE_TRANSACTION_MODE', 'Always Good', 'Transaction mode to use for the PSiGate service', '6', '3', 'tep_cfg_select_option(array(\'Production\', \'Always Good\', \'Always Duplicate\', \'Always Decline\'), ', now())"); 269 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 ('Transaction Type', 'MODULE_PAYMENT_PSIGATE_TRANSACTION_TYPE', 'PreAuth', 'Transaction type to use for the PSiGate service', '6', '4', 'tep_cfg_select_option(array(\'Sale\', \'PreAuth\', \'PostAuth\'), ', now())"); 270 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 ('Credit Card Collection', 'MODULE_PAYMENT_PSIGATE_INPUT_MODE', 'Local', 'Should the credit card details be collected locally or remotely at PSiGate?', '6', '5', 'tep_cfg_select_option(array(\'Local\', \'Remote\'), ', now())"); 271 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 ('Transaction Currency', 'MODULE_PAYMENT_PSIGATE_CURRENCY', 'USD', 'The currency to use for credit card transactions', '6', '6', 'tep_cfg_select_option(array(\'CAD\', \'USD\'), ', now())"); 272 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_PSIGATE_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())"); 273 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 ('Payment Zone', 'MODULE_PAYMENT_PSIGATE_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())"); 274 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 ('Set Order Status', 'MODULE_PAYMENT_PSIGATE_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())"); 275 } 276 277 function remove() { 278 tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); 279 } 280 281 function keys() { 282 return array('MODULE_PAYMENT_PSIGATE_STATUS', 'MODULE_PAYMENT_PSIGATE_MERCHANT_ID', 'MODULE_PAYMENT_PSIGATE_TRANSACTION_MODE', 'MODULE_PAYMENT_PSIGATE_TRANSACTION_TYPE', 'MODULE_PAYMENT_PSIGATE_INPUT_MODE', 'MODULE_PAYMENT_PSIGATE_CURRENCY', 'MODULE_PAYMENT_PSIGATE_ZONE', 'MODULE_PAYMENT_PSIGATE_ORDER_STATUS_ID', 'MODULE_PAYMENT_PSIGATE_SORT_ORDER'); 283 } 284 } 285 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 19:48:25 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |