[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

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

   1  <?php
   2  /*
   3    $Id: ipayment_cc.php 1815 2008-01-14 10:55:23Z 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 ipayment_cc {
  14      var $code, $title, $description, $enabled;
  15  
  16  // class constructor
  17      function ipayment_cc() {
  18        global $order;
  19  
  20        $this->signature = 'ipayment|ipayment_cc|1.0|2.2';
  21  
  22        $this->code = 'ipayment_cc';
  23        $this->title = MODULE_PAYMENT_IPAYMENT_CC_TEXT_TITLE;
  24        $this->public_title = MODULE_PAYMENT_IPAYMENT_CC_TEXT_PUBLIC_TITLE;
  25        $this->description = MODULE_PAYMENT_IPAYMENT_CC_TEXT_DESCRIPTION;
  26        $this->sort_order = MODULE_PAYMENT_IPAYMENT_CC_SORT_ORDER;
  27        $this->enabled = ((MODULE_PAYMENT_IPAYMENT_CC_STATUS == 'True') ? true : false);
  28  
  29        if ((int)MODULE_PAYMENT_IPAYMENT_CC_ORDER_STATUS_ID > 0) {
  30          $this->order_status = MODULE_PAYMENT_IPAYMENT_CC_ORDER_STATUS_ID;
  31        }
  32  
  33        if (is_object($order)) $this->update_status();
  34  
  35        $this->form_action_url = 'https://ipayment.de/merchant/' . MODULE_PAYMENT_IPAYMENT_CC_ID . '/processor.php';
  36      }
  37  
  38  // class methods
  39      function update_status() {
  40        global $order;
  41  
  42        if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_IPAYMENT_CC_ZONE > 0) ) {
  43          $check_flag = false;
  44          $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_IPAYMENT_CC_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
  45          while ($check = tep_db_fetch_array($check_query)) {
  46            if ($check['zone_id'] < 1) {
  47              $check_flag = true;
  48              break;
  49            } elseif ($check['zone_id'] == $order->billing['zone_id']) {
  50              $check_flag = true;
  51              break;
  52            }
  53          }
  54  
  55          if ($check_flag == false) {
  56            $this->enabled = false;
  57          }
  58        }
  59      }
  60  
  61      function javascript_validation() {
  62        return false;
  63      }
  64  
  65      function selection() {
  66        return array('id' => $this->code,
  67                     'module' => $this->public_title);
  68      }
  69  
  70      function pre_confirmation_check() {
  71        return false;
  72      }
  73  
  74      function confirmation() {
  75        global $order;
  76  
  77        for ($i=1; $i<13; $i++) {
  78          $expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));
  79        }
  80  
  81        $today = getdate(); 
  82        for ($i=$today['year']; $i < $today['year']+10; $i++) {
  83          $expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
  84        }
  85  
  86        $confirmation = array('fields' => array(array('title' => MODULE_PAYMENT_IPAYMENT_CC_TEXT_CREDIT_CARD_OWNER,
  87                                                      'field' => tep_draw_input_field('addr_name', $order->billing['firstname'] . ' ' . $order->billing['lastname'])),
  88                                                array('title' => MODULE_PAYMENT_IPAYMENT_CC_TEXT_CREDIT_CARD_NUMBER,
  89                                                      'field' => tep_draw_input_field('cc_number')),
  90                                                array('title' => MODULE_PAYMENT_IPAYMENT_CC_TEXT_CREDIT_CARD_EXPIRES,
  91                                                      'field' => tep_draw_pull_down_menu('cc_expdate_month', $expires_month) . '&nbsp;' . tep_draw_pull_down_menu('cc_expdate_year', $expires_year)),
  92                                                array('title' => MODULE_PAYMENT_IPAYMENT_CC_TEXT_CREDIT_CARD_CHECKNUMBER,
  93                                                      'field' => tep_draw_input_field('cc_checkcode', '', 'size="5" maxlength="4"'))));
  94  
  95        return $confirmation;
  96      }
  97  
  98      function process_button() {
  99        global $order, $currency;
 100  
 101        $zone_code = '';
 102  
 103        if (is_numeric($order->billing['zone_id']) && ($order->billing['zone_id'] > 0)) {
 104          $zone_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_id = '" . (int)$order->billing['zone_id'] . "'");
 105          if (tep_db_num_rows($zone_query)) {
 106            $zone = tep_db_fetch_array($zone_query);
 107  
 108            $zone_code = $zone['zone_code'];
 109          }
 110        }
 111  
 112        $process_button_string = tep_draw_hidden_field('silent', '1') .
 113                                 tep_draw_hidden_field('trx_paymenttyp', 'cc') .
 114                                 tep_draw_hidden_field('trxuser_id', MODULE_PAYMENT_IPAYMENT_CC_USER_ID) .
 115                                 tep_draw_hidden_field('trxpassword', MODULE_PAYMENT_IPAYMENT_CC_PASSWORD) .
 116  //                               tep_draw_hidden_field('order_id', '') .
 117  //                               tep_draw_hidden_field('strict_id_check', 1) .
 118                                 tep_draw_hidden_field('from_ip', tep_get_ip_address()) .
 119                                 tep_draw_hidden_field('trx_currency', $currency) .
 120                                 tep_draw_hidden_field('trx_amount', $this->format_raw($order->info['total'])*100) .
 121                                 tep_draw_hidden_field('trx_typ', ((MODULE_PAYMENT_IPAYMENT_CC_TRANSACTION_METHOD == 'Capture') ? 'auth' : 'preauth')) .
 122                                 tep_draw_hidden_field('addr_email', $order->customer['email_address']) .
 123                                 tep_draw_hidden_field('addr_street', $order->billing['street_address']) .
 124                                 tep_draw_hidden_field('addr_city', $order->billing['city']) .
 125                                 tep_draw_hidden_field('addr_zip', $order->billing['postcode']) .
 126                                 tep_draw_hidden_field('addr_country', $order->billing['country']['iso_code_2']) .
 127                                 tep_draw_hidden_field('addr_state', $zone_code) .
 128                                 tep_draw_hidden_field('addr_telefon', $order->customer['telephone']) .
 129                                 tep_draw_hidden_field('redirect_url', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true)) .
 130                                 tep_draw_hidden_field('silent_error_url', tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code, 'SSL', true)) .
 131                                 tep_draw_hidden_field('client_name', 'oscommerce') .
 132                                 tep_draw_hidden_field('client_version', PROJECT_VERSION);
 133  
 134        if (tep_not_null(MODULE_PAYMENT_IPAYMENT_CC_SECRET_HASH_PASSWORD)) {
 135          $process_button_string .= tep_draw_hidden_field('trx_securityhash', md5(MODULE_PAYMENT_IPAYMENT_CC_USER_ID . ($this->format_raw($order->info['total']) * 100) . $currency . MODULE_PAYMENT_IPAYMENT_CC_PASSWORD . MODULE_PAYMENT_IPAYMENT_CC_SECRET_HASH_PASSWORD));
 136        }
 137  
 138        return $process_button_string;
 139      }
 140  
 141      function before_process() {
 142        global $HTTP_GET_VARS, $order, $currency;
 143  
 144        if ($HTTP_GET_VARS['ret_errorcode'] != '0') {
 145          tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . tep_output_string_protected($HTTP_GET_VARS['ret_errormsg'])));
 146        }
 147  
 148        if (tep_not_null(MODULE_PAYMENT_IPAYMENT_CC_SECRET_HASH_PASSWORD) && ($HTTP_GET_VARS['ret_param_checksum'] != md5(MODULE_PAYMENT_IPAYMENT_CC_USER_ID . ($this->format_raw($order->info['total']) * 100) . $currency . $HTTP_GET_VARS['ret_authcode'] . $HTTP_GET_VARS['ret_booknr'] . MODULE_PAYMENT_IPAYMENT_CC_SECRET_HASH_PASSWORD))) {
 149          tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code));
 150        }
 151  
 152        return false;
 153      }
 154  
 155      function after_process() {
 156        return false;
 157      }
 158  
 159      function get_error() {
 160        global $HTTP_GET_VARS;
 161  
 162        $error = array('title' => MODULE_PAYMENT_IPAYMENT_CC_ERROR_HEADING,
 163                       'error' => ((isset($HTTP_GET_VARS['error'])) ? stripslashes(urldecode($HTTP_GET_VARS['error'])) : MODULE_PAYMENT_IPAYMENT_CC_ERROR_MESSAGE));
 164  
 165        return $error;
 166      }
 167  
 168      function check() {
 169        if (!isset($this->_check)) {
 170          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_IPAYMENT_CC_STATUS'");
 171          $this->_check = tep_db_num_rows($check_query);
 172        }
 173        return $this->_check;
 174      }
 175  
 176      function install() {
 177        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 iPayment', 'MODULE_PAYMENT_IPAYMENT_CC_STATUS', 'False', 'Do you want to accept iPayment payments?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 178        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Account Number', 'MODULE_PAYMENT_IPAYMENT_CC_ID', '99999', 'The account number used for the iPayment service', '6', '2', now())");
 179        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('User ID', 'MODULE_PAYMENT_IPAYMENT_CC_USER_ID', '99999', 'The user ID for the iPayment service', '6', '3', now())");
 180        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('User Password', 'MODULE_PAYMENT_IPAYMENT_CC_PASSWORD', '0', 'The user password for the iPayment service', '6', '4', now())");
 181        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_IPAYMENT_CC_TRANSACTION_METHOD', 'Authorization', 'The processing method to use for each transaction.', '6', '0', 'tep_cfg_select_option(array(\'Authorization\', \'Capture\'), ', now())");
 182        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Secret Hash Password', 'MODULE_PAYMENT_IPAYMENT_CC_SECRET_HASH_PASSWORD', '', 'The secret hash password to validate transactions with', '6', '4', now())");
 183        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_IPAYMENT_CC_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
 184        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_IPAYMENT_CC_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())");
 185        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_IPAYMENT_CC_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())");
 186      }
 187  
 188      function remove() {
 189        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 190      }
 191  
 192      function keys() {
 193        return array('MODULE_PAYMENT_IPAYMENT_CC_STATUS', 'MODULE_PAYMENT_IPAYMENT_CC_ID', 'MODULE_PAYMENT_IPAYMENT_CC_USER_ID', 'MODULE_PAYMENT_IPAYMENT_CC_PASSWORD', 'MODULE_PAYMENT_IPAYMENT_CC_TRANSACTION_METHOD', 'MODULE_PAYMENT_IPAYMENT_CC_SECRET_HASH_PASSWORD', 'MODULE_PAYMENT_IPAYMENT_CC_ZONE', 'MODULE_PAYMENT_IPAYMENT_CC_ORDER_STATUS_ID', 'MODULE_PAYMENT_IPAYMENT_CC_SORT_ORDER');
 194      }
 195  
 196  // format prices without currency formatting
 197      function format_raw($number, $currency_code = '', $currency_value = '') {
 198        global $currencies, $currency;
 199  
 200        if (empty($currency_code) || !$this->is_set($currency_code)) {
 201          $currency_code = $currency;
 202        }
 203  
 204        if (empty($currency_value) || !is_numeric($currency_value)) {
 205          $currency_value = $currencies->currencies[$currency_code]['value'];
 206        }
 207  
 208        return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', '');
 209      }
 210    }
 211  ?>


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