[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/modules/payment/ -> authorizenet_cc_sim.php (source)

   1  <?php
   2  /*
   3    $Id: authorizenet_cc_sim.php 1803 2008-01-11 18:16:37Z user $
   4  
   5    osCMax Power E-Commerce
   6    http://oscdox.com
   7  
   8    Copyright 2008 osCMax
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13    class authorizenet_cc_sim {
  14      var $code, $title, $description, $enabled;
  15  
  16  // class constructor
  17      function authorizenet_cc_sim() {
  18        global $order;
  19  
  20        $this->signature = 'authorizenet|authorizenet_cc_sim|1.0|2.2';
  21  
  22        $this->code = 'authorizenet_cc_sim';
  23        $this->title = MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TEXT_TITLE;
  24        $this->public_title = MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TEXT_PUBLIC_TITLE;
  25        $this->description = MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TEXT_DESCRIPTION;
  26        $this->sort_order = MODULE_PAYMENT_AUTHORIZENET_CC_SIM_SORT_ORDER;
  27        $this->enabled = ((MODULE_PAYMENT_AUTHORIZENET_CC_SIM_STATUS == 'True') ? true : false);
  28  
  29        if ((int)MODULE_PAYMENT_AUTHORIZENET_CC_SIM_ORDER_STATUS_ID > 0) {
  30          $this->order_status = MODULE_PAYMENT_AUTHORIZENET_CC_SIM_ORDER_STATUS_ID;
  31        }
  32  
  33        if (is_object($order)) $this->update_status();
  34  
  35        switch (MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TRANSACTION_SERVER) {
  36          case 'Live':
  37            $this->form_action_url = 'https://secure.authorize.net/gateway/transact.dll';
  38            break;
  39  
  40          default:
  41            $this->form_action_url = 'https://test.authorize.net/gateway/transact.dll';
  42            break;
  43        }
  44      }
  45  
  46  // class methods
  47      function update_status() {
  48        global $order;
  49  
  50        if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_AUTHORIZENET_CC_SIM_ZONE > 0) ) {
  51          $check_flag = false;
  52          $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_AUTHORIZENET_CC_SIM_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
  53          while ($check = tep_db_fetch_array($check_query)) {
  54            if ($check['zone_id'] < 1) {
  55              $check_flag = true;
  56              break;
  57            } elseif ($check['zone_id'] == $order->billing['zone_id']) {
  58              $check_flag = true;
  59              break;
  60            }
  61          }
  62  
  63          if ($check_flag == false) {
  64            $this->enabled = false;
  65          }
  66        }
  67      }
  68  
  69      function javascript_validation() {
  70        return false;
  71      }
  72  
  73      function selection() {
  74        return array('id' => $this->code,
  75                     'module' => $this->public_title);
  76      }
  77  
  78      function pre_confirmation_check() {
  79        return false;
  80      }
  81  
  82      function confirmation() {
  83        return false;
  84      }
  85  
  86      function process_button() {
  87        global $customer_id, $order, $sendto, $currency;
  88  
  89        $process_button_string = $this->_InsertFP(MODULE_PAYMENT_AUTHORIZENET_CC_SIM_LOGIN_ID, MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TRANSACTION_KEY, $this->format_raw($order->info['total']), rand(1, 1000), $currency);
  90  
  91        $process_button_string .= tep_draw_hidden_field('x_login', substr(MODULE_PAYMENT_AUTHORIZENET_CC_SIM_LOGIN_ID, 0, 20)) .
  92                                  tep_draw_hidden_field('x_version', '3.1') .
  93                                  tep_draw_hidden_field('x_show_form', 'PAYMENT_FORM') .
  94                                  tep_draw_hidden_field('x_relay_response', 'TRUE') .
  95                                  tep_draw_hidden_field('x_relay_url', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', false)) .
  96                                  tep_draw_hidden_field('x_first_name', substr($order->billing['firstname'], 0, 50)) .
  97                                  tep_draw_hidden_field('x_last_name', substr($order->billing['lastname'], 0, 50)) .
  98                                  tep_draw_hidden_field('x_company', substr($order->billing['company'], 0, 50)) .
  99                                  tep_draw_hidden_field('x_address', substr($order->billing['street_address'], 0, 60)) .
 100                                  tep_draw_hidden_field('x_city', substr($order->billing['city'], 0, 40)) .
 101                                  tep_draw_hidden_field('x_state', substr($order->billing['state'], 0, 40)) .
 102                                  tep_draw_hidden_field('x_zip', substr($order->billing['postcode'], 0, 20)) .
 103                                  tep_draw_hidden_field('x_country', substr($order->billing['country']['title'], 0, 60)) .
 104                                  tep_draw_hidden_field('x_phone', substr($order->customer['telephone'], 0, 25)) .
 105                                  tep_draw_hidden_field('x_cust_id', substr($customer_id, 0, 20)) .
 106                                  tep_draw_hidden_field('x_customer_ip', tep_get_ip_address()) .
 107                                  tep_draw_hidden_field('x_email', substr($order->customer['email_address'], 0, 255)) .
 108                                  tep_draw_hidden_field('x_description', substr(STORE_NAME, 0, 255)) .
 109                                  tep_draw_hidden_field('x_amount', substr($this->format_raw($order->info['total']), 0, 15)) .
 110                                  tep_draw_hidden_field('x_currency_code', substr($currency, 0, 3)) .
 111                                  tep_draw_hidden_field('x_method', 'CC') .
 112                                  tep_draw_hidden_field('x_type', ((MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TRANSACTION_METHOD == 'Capture') ? 'AUTH_CAPTURE' : 'AUTH_ONLY'));
 113  
 114        if (is_numeric($sendto) && ($sendto > 0)) {
 115          $process_button_string .= tep_draw_hidden_field('x_ship_to_first_name', substr($order->delivery['firstname'], 0, 50)) .
 116                                    tep_draw_hidden_field('x_ship_to_last_name', substr($order->delivery['lastname'], 0, 50)) .
 117                                    tep_draw_hidden_field('x_ship_to_company', substr($order->delivery['company'], 0, 50)) .
 118                                    tep_draw_hidden_field('x_ship_to_address', substr($order->delivery['street_address'], 0, 60)) .
 119                                    tep_draw_hidden_field('x_ship_to_city', substr($order->delivery['city'], 0, 40)) .
 120                                    tep_draw_hidden_field('x_ship_to_state', substr($order->delivery['state'], 0, 40)) .
 121                                    tep_draw_hidden_field('x_ship_to_zip', substr($order->delivery['postcode'], 0, 20)) .
 122                                    tep_draw_hidden_field('x_ship_to_country', substr($order->delivery['country']['title'], 0, 60));
 123        }
 124  
 125        if (MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TRANSACTION_MODE == 'Test') {
 126          $process_button_string .= tep_draw_hidden_field('x_test_request', 'TRUE');
 127        }
 128  
 129        for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
 130          $process_button_string .= tep_draw_hidden_field('x_line_item', ($i+1) . '<|>' . substr($order->products[$i]['name'], 0, 31) . '<|>' . substr($order->products[$i]['name'], 0, 255) . '<|>' . $order->products[$i]['qty'] . '<|>' . $this->format_raw($order->products[$i]['final_price']) . '<|>' . ($order->products[$i]['tax'] > 0 ? 'YES' : 'NO'));
 131        }
 132  
 133        $tax_value = 0;
 134  
 135        reset($order->info['tax_groups']);
 136        while (list($key, $value) = each($order->info['tax_groups'])) {
 137          if ($value > 0) {
 138            $tax_value += $this->format_raw($value);
 139          }
 140        }
 141  
 142        if ($tax_value > 0) {
 143          $process_button_string .= tep_draw_hidden_field('x_tax', $this->format_raw($tax_value));
 144        }
 145  
 146        $process_button_string .= tep_draw_hidden_field('x_freight', $this->format_raw($order->info['shipping_cost'])) .
 147                                  tep_draw_hidden_field(tep_session_name(), tep_session_id());
 148  
 149        return $process_button_string;
 150      }
 151  
 152      function before_process() {
 153        global $HTTP_POST_VARS, $order;
 154  
 155        $error = false;
 156  
 157        if ($HTTP_POST_VARS['x_response_code'] == '1') {
 158          if (tep_not_null(MODULE_PAYMENT_AUTHORIZENET_CC_SIM_MD5_HASH) && ($HTTP_POST_VARS['x_MD5_Hash'] != strtoupper(md5(MODULE_PAYMENT_AUTHORIZENET_CC_SIM_MD5_HASH . MODULE_PAYMENT_AUTHORIZENET_CC_SIM_LOGIN_ID . $HTTP_POST_VARS['x_trans_id'] . $this->format_raw($order->info['total']))))) {
 159            $error = 'verification';
 160          } elseif ($HTTP_POST_VARS['x_amount'] != $this->format_raw($order->info['total'])) {
 161            $error = 'verification';
 162          }
 163        } elseif ($HTTP_POST_VARS['x_response_code'] == '2') {
 164          $error = 'declined';
 165        } else {
 166          $error = 'general';
 167        }
 168  
 169        if ($error != false) {
 170          tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . $error, 'SSL', true, false));
 171        }
 172      }
 173  
 174      function after_process() {
 175        return false;
 176      }
 177  
 178      function get_error() {
 179        global $HTTP_GET_VARS;
 180  
 181        $error_message = MODULE_PAYMENT_AUTHORIZENET_CC_SIM_ERROR_GENERAL;
 182  
 183        switch ($HTTP_GET_VARS['error']) {
 184          case 'verification':
 185            $error_message = MODULE_PAYMENT_AUTHORIZENET_CC_SIM_ERROR_VERIFICATION;
 186            break;
 187  
 188          case 'declined':
 189            $error_message = MODULE_PAYMENT_AUTHORIZENET_CC_SIM_ERROR_DECLINED;
 190            break;
 191  
 192          default:
 193            $error_message = MODULE_PAYMENT_AUTHORIZENET_CC_SIM_ERROR_GENERAL;
 194            break;
 195        }
 196  
 197        $error = array('title' => MODULE_PAYMENT_AUTHORIZENET_CC_SIM_ERROR_TITLE,
 198                       'error' => $error_message);
 199  
 200        return $error;
 201      }
 202  
 203      function check() {
 204        if (!isset($this->_check)) {
 205          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_STATUS'");
 206          $this->_check = tep_db_num_rows($check_query);
 207        }
 208        return $this->_check;
 209      }
 210  
 211      function install() {
 212        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 Authorize.net Credit Card SIM', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_STATUS', 'False', 'Do you want to accept Authorize.net Credit Card SIM payments?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 213        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Login ID', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_LOGIN_ID', '', 'The login ID used for the Authorize.net service', '6', '0', now())");
 214        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Transaction Key', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TRANSACTION_KEY', '', 'Transaction key used for encrypting data', '6', '0', now())");
 215        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('MD5 Hash', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_MD5_HASH', '', 'The MD5 hash value to verify transactions with', '6', '0', now())");
 216        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 Server', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TRANSACTION_SERVER', 'Live', 'Perform transactions on the live or test server. The test server should only be used by developers with Authorize.net test accounts.', '6', '0', 'tep_cfg_select_option(array(\'Live\', \'Test\'), ', now())");
 217        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_AUTHORIZENET_CC_SIM_TRANSACTION_MODE', 'Test', 'Transaction mode used for processing orders', '6', '0', 'tep_cfg_select_option(array(\'Live\', \'Test\'), ', now())");
 218        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 Method', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TRANSACTION_METHOD', 'Authorization', 'The processing method to use for each transaction.', '6', '0', 'tep_cfg_select_option(array(\'Authorization\', \'Capture\'), ', now())");
 219        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_AUTHORIZENET_CC_SIM_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
 220        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_AUTHORIZENET_CC_SIM_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())");
 221        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_AUTHORIZENET_CC_SIM_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())");
 222      }
 223  
 224      function remove() {
 225        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 226      }
 227  
 228      function keys() {
 229        return array('MODULE_PAYMENT_AUTHORIZENET_CC_SIM_STATUS', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_LOGIN_ID', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TRANSACTION_KEY', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_MD5_HASH', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TRANSACTION_SERVER', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TRANSACTION_MODE', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_TRANSACTION_METHOD', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_ZONE', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_ORDER_STATUS_ID', 'MODULE_PAYMENT_AUTHORIZENET_CC_SIM_SORT_ORDER');
 230      }
 231  
 232      function _hmac($key, $data) {
 233        if (function_exists('mhash') && defined('MHASH_MD5')) {
 234          return bin2hex(mhash(MHASH_MD5, $data, $key));
 235        }
 236  
 237  // RFC 2104 HMAC implementation for php.
 238  // Creates an md5 HMAC.
 239  // Eliminates the need to install mhash to compute a HMAC
 240  // Hacked by Lance Rushing
 241  
 242        $b = 64; // byte length for md5
 243        if (strlen($key) > $b) {
 244          $key = pack("H*",md5($key));
 245        }
 246  
 247        $key = str_pad($key, $b, chr(0x00));
 248        $ipad = str_pad('', $b, chr(0x36));
 249        $opad = str_pad('', $b, chr(0x5c));
 250        $k_ipad = $key ^ $ipad ;
 251        $k_opad = $key ^ $opad;
 252  
 253        return md5($k_opad . pack("H*",md5($k_ipad . $data)));
 254      }
 255  
 256      function _InsertFP($loginid, $x_tran_key, $amount, $sequence, $currency = '') {
 257        $tstamp = time();
 258  
 259        $fingerprint = $this->_hmac($x_tran_key, $loginid . '^' . $sequence . '^' . $tstamp . '^' . $amount . '^' . $currency);
 260  
 261        return tep_draw_hidden_field('x_fp_sequence', $sequence) .
 262               tep_draw_hidden_field('x_fp_timestamp', $tstamp) .
 263               tep_draw_hidden_field('x_fp_hash', $fingerprint);
 264      }
 265  
 266  // format prices without currency formatting
 267      function format_raw($number, $currency_code = '', $currency_value = '') {
 268        global $currencies, $currency;
 269  
 270        if (empty($currency_code) || !$this->is_set($currency_code)) {
 271          $currency_code = $currency;
 272        }
 273  
 274        if (empty($currency_value) || !is_numeric($currency_value)) {
 275          $currency_value = $currencies->currencies[$currency_code]['value'];
 276        }
 277  
 278        return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', '');
 279      }
 280    }
 281  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7