[ Index ]
 

Code source de osCommerce 2.2ms2-060817

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/catalog/includes/modules/payment/ -> cc.php (source)

   1  <?php
   2  /*
   3    $Id: cc.php,v 1.53 2003/02/04 09:55:01 project3000 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 cc {
  14      var $code, $title, $description, $enabled;
  15  
  16  // class constructor
  17      function cc() {
  18        global $order;
  19  
  20        $this->code = 'cc';
  21        $this->title = MODULE_PAYMENT_CC_TEXT_TITLE;
  22        $this->description = MODULE_PAYMENT_CC_TEXT_DESCRIPTION;
  23        $this->sort_order = MODULE_PAYMENT_CC_SORT_ORDER;
  24        $this->enabled = ((MODULE_PAYMENT_CC_STATUS == 'True') ? true : false);
  25  
  26        if ((int)MODULE_PAYMENT_CC_ORDER_STATUS_ID > 0) {
  27          $this->order_status = MODULE_PAYMENT_CC_ORDER_STATUS_ID;
  28        }
  29  
  30        if (is_object($order)) $this->update_status();
  31      }
  32  
  33  // class methods
  34      function update_status() {
  35        global $order;
  36  
  37        if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_CC_ZONE > 0) ) {
  38          $check_flag = false;
  39          $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_CC_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
  40          while ($check = tep_db_fetch_array($check_query)) {
  41            if ($check['zone_id'] < 1) {
  42              $check_flag = true;
  43              break;
  44            } elseif ($check['zone_id'] == $order->billing['zone_id']) {
  45              $check_flag = true;
  46              break;
  47            }
  48          }
  49  
  50          if ($check_flag == false) {
  51            $this->enabled = false;
  52          }
  53        }
  54      }
  55  
  56      function javascript_validation() {
  57        $js = '  if (payment_value == "' . $this->code . '") {' . "\n" .
  58              '    var cc_owner = document.checkout_payment.cc_owner.value;' . "\n" .
  59              '    var cc_number = document.checkout_payment.cc_number.value;' . "\n" .
  60              '    if (cc_owner == "" || cc_owner.length < ' . CC_OWNER_MIN_LENGTH . ') {' . "\n" .
  61              '      error_message = error_message + "' . MODULE_PAYMENT_CC_TEXT_JS_CC_OWNER . '";' . "\n" .
  62              '      error = 1;' . "\n" .
  63              '    }' . "\n" .
  64              '    if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" .
  65              '      error_message = error_message + "' . MODULE_PAYMENT_CC_TEXT_JS_CC_NUMBER . '";' . "\n" .
  66              '      error = 1;' . "\n" .
  67              '    }' . "\n" .
  68              '  }' . "\n";
  69  
  70        return $js;
  71      }
  72  
  73      function selection() {
  74        global $order;
  75  
  76        for ($i=1; $i<13; $i++) {
  77          $expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));
  78        }
  79  
  80        $today = getdate(); 
  81        for ($i=$today['year']; $i < $today['year']+10; $i++) {
  82          $expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
  83        }
  84  
  85        $selection = array('id' => $this->code,
  86                           'module' => $this->title,
  87                           'fields' => array(array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_OWNER,
  88                                                   'field' => tep_draw_input_field('cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'])),
  89                                             array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_NUMBER,
  90                                                   'field' => tep_draw_input_field('cc_number')),
  91                                             array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_EXPIRES,
  92                                                   'field' => tep_draw_pull_down_menu('cc_expires_month', $expires_month) . '&nbsp;' . tep_draw_pull_down_menu('cc_expires_year', $expires_year))));
  93  
  94        return $selection;
  95      }
  96  
  97      function pre_confirmation_check() {
  98        global $HTTP_POST_VARS;
  99  
 100        include(DIR_WS_CLASSES . 'cc_validation.php');
 101  
 102        $cc_validation = new cc_validation();
 103        $result = $cc_validation->validate($HTTP_POST_VARS['cc_number'], $HTTP_POST_VARS['cc_expires_month'], $HTTP_POST_VARS['cc_expires_year']);
 104  
 105        $error = '';
 106        switch ($result) {
 107          case -1:
 108            $error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
 109            break;
 110          case -2:
 111          case -3:
 112          case -4:
 113            $error = TEXT_CCVAL_ERROR_INVALID_DATE;
 114            break;
 115          case false:
 116            $error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
 117            break;
 118        }
 119  
 120        if ( ($result == false) || ($result < 1) ) {
 121          $payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($error) . '&cc_owner=' . urlencode($HTTP_POST_VARS['cc_owner']) . '&cc_expires_month=' . $HTTP_POST_VARS['cc_expires_month'] . '&cc_expires_year=' . $HTTP_POST_VARS['cc_expires_year'];
 122  
 123          tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));
 124        }
 125  
 126        $this->cc_card_type = $cc_validation->cc_type;
 127        $this->cc_card_number = $cc_validation->cc_number;
 128      }
 129  
 130      function confirmation() {
 131        global $HTTP_POST_VARS;
 132  
 133        $confirmation = array('title' => $this->title . ': ' . $this->cc_card_type,
 134                              'fields' => array(array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_OWNER,
 135                                                      'field' => $HTTP_POST_VARS['cc_owner']),
 136                                                array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_NUMBER,
 137                                                      'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)),
 138                                                array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_EXPIRES,
 139                                                      'field' => strftime('%B, %Y', mktime(0,0,0,$HTTP_POST_VARS['cc_expires_month'], 1, '20' . $HTTP_POST_VARS['cc_expires_year'])))));
 140  
 141        return $confirmation;
 142      }
 143  
 144      function process_button() {
 145        global $HTTP_POST_VARS;
 146  
 147        $process_button_string = tep_draw_hidden_field('cc_owner', $HTTP_POST_VARS['cc_owner']) .
 148                                 tep_draw_hidden_field('cc_expires', $HTTP_POST_VARS['cc_expires_month'] . $HTTP_POST_VARS['cc_expires_year']) .
 149                                 tep_draw_hidden_field('cc_type', $this->cc_card_type) .
 150                                 tep_draw_hidden_field('cc_number', $this->cc_card_number);
 151  
 152        return $process_button_string;
 153      }
 154  
 155      function before_process() {
 156        global $HTTP_POST_VARS, $order;
 157  
 158        if ( (defined('MODULE_PAYMENT_CC_EMAIL')) && (tep_validate_email(MODULE_PAYMENT_CC_EMAIL)) ) {
 159          $len = strlen($HTTP_POST_VARS['cc_number']);
 160  
 161          $this->cc_middle = substr($HTTP_POST_VARS['cc_number'], 4, ($len-8));
 162          $order->info['cc_number'] = substr($HTTP_POST_VARS['cc_number'], 0, 4) . str_repeat('X', (strlen($HTTP_POST_VARS['cc_number']) - 8)) . substr($HTTP_POST_VARS['cc_number'], -4);
 163        }
 164      }
 165  
 166      function after_process() {
 167        global $insert_id;
 168  
 169        if ( (defined('MODULE_PAYMENT_CC_EMAIL')) && (tep_validate_email(MODULE_PAYMENT_CC_EMAIL)) ) {
 170          $message = 'Order #' . $insert_id . "\n\n" . 'Middle: ' . $this->cc_middle . "\n\n";
 171          
 172          tep_mail('', MODULE_PAYMENT_CC_EMAIL, 'Extra Order Info: #' . $insert_id, $message, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 173        }
 174      }
 175  
 176      function get_error() {
 177        global $HTTP_GET_VARS;
 178  
 179        $error = array('title' => MODULE_PAYMENT_CC_TEXT_ERROR,
 180                       'error' => stripslashes(urldecode($HTTP_GET_VARS['error'])));
 181  
 182        return $error;
 183      }
 184  
 185      function check() {
 186        if (!isset($this->_check)) {
 187          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_CC_STATUS'");
 188          $this->_check = tep_db_num_rows($check_query);
 189        }
 190        return $this->_check;
 191      }
 192  
 193      function install() {
 194        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 Credit Card Module', 'MODULE_PAYMENT_CC_STATUS', 'True', 'Do you want to accept credit card payments?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 195        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Split Credit Card E-Mail Address', 'MODULE_PAYMENT_CC_EMAIL', '', 'If an e-mail address is entered, the middle digits of the credit card number will be sent to the e-mail address (the outside digits are stored in the database with the middle digits censored)', '6', '0', now())");
 196        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_CC_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0' , now())");
 197        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_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())");
 198        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_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())");
 199      }
 200  
 201      function remove() {
 202        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 203      }
 204  
 205      function keys() {
 206        return array('MODULE_PAYMENT_CC_STATUS', 'MODULE_PAYMENT_CC_EMAIL', 'MODULE_PAYMENT_CC_ZONE', 'MODULE_PAYMENT_CC_ORDER_STATUS_ID', 'MODULE_PAYMENT_CC_SORT_ORDER');
 207      }
 208    }
 209  ?>


Généré le : Mon Nov 26 19:48:25 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics