[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

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

   1  <?php
   2  /*

   3  $Id: cc.php 14 2006-07-28 17:42:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   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->public_title = MODULE_PAYMENT_CC_TEXT_PUBLIC_TITLE;
  23        $this->description = MODULE_PAYMENT_CC_TEXT_DESCRIPTION;
  24        $this->sort_order = MODULE_PAYMENT_CC_SORT_ORDER;
  25        $this->enabled = ((MODULE_PAYMENT_CC_STATUS == 'True') ? true : false);
  26  
  27        if ((int)MODULE_PAYMENT_CC_ORDER_STATUS_ID > 0) {
  28          $this->order_status = MODULE_PAYMENT_CC_ORDER_STATUS_ID;
  29        }
  30  
  31        if (is_object($order)) $this->update_status();
  32      }
  33  
  34  // class methods

  35      function update_status() {
  36        global $order;
  37  
  38        if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_CC_ZONE > 0) ) {
  39          $check_flag = false;
  40          $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");
  41          while ($check = tep_db_fetch_array($check_query)) {
  42            if ($check['zone_id'] < 1) {
  43              $check_flag = true;
  44              break;
  45            } elseif ($check['zone_id'] == $order->billing['zone_id']) {
  46              $check_flag = true;
  47              break;
  48            }
  49          }
  50  
  51          if ($check_flag == false) {
  52            $this->enabled = false;
  53          }
  54        }
  55      }
  56  
  57      function javascript_validation() {
  58        return false;
  59      }
  60  
  61      function selection() {
  62        return array('id' => $this->code,
  63                     'module' => $this->public_title);
  64      }
  65  
  66      function pre_confirmation_check() {
  67        return false;
  68      }
  69  
  70      function confirmation() {
  71        global $order;
  72  
  73        for ($i=1; $i<13; $i++) {
  74          $expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));
  75        }
  76  
  77        $today = getdate(); 
  78        for ($i=$today['year']; $i < $today['year']+10; $i++) {
  79          $expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
  80        }
  81  
  82        $confirmation = array('fields' => array(array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_OWNER,
  83                                                      'field' => tep_draw_input_field('cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'])),
  84                                                array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_NUMBER,
  85                                                      'field' => tep_draw_input_field('cc_number_nh-dns')),
  86                                                array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_EXPIRES,
  87                                                      'field' => tep_draw_pull_down_menu('cc_expires_month', $expires_month) . '&nbsp;' . tep_draw_pull_down_menu('cc_expires_year', $expires_year))));
  88  
  89        return $confirmation;
  90      }
  91  
  92      function process_button() {
  93        return false;
  94      }
  95  
  96      function before_process() {
  97        global $HTTP_POST_VARS, $order;
  98  
  99        include (DIR_WS_CLASSES . 'cc_validation.php');
 100  
 101        $cc_validation = new cc_validation();
 102        $result = $cc_validation->validate($HTTP_POST_VARS['cc_number_nh-dns'], $HTTP_POST_VARS['cc_expires_month'], $HTTP_POST_VARS['cc_expires_year'], $HTTP_POST_VARS['cc_checkcode'], $HTTP_POST_VARS['cc_card_type']);
 103        $error = '';
 104        switch ($result) {
 105          case -1:
 106            $error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
 107            break;
 108          case -2:
 109          case -3:
 110          case -4:
 111            $error = TEXT_CCVAL_ERROR_INVALID_DATE;
 112            break;
 113          case false:
 114            $error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
 115            break;
 116        }
 117  
 118        if ( ($result == false) || ($result < 1) ) {
 119          $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'];
 120  
 121          tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));
 122        }
 123  
 124        $order->info['cc_owner'] = $HTTP_POST_VARS['cc_owner'];
 125        $order->info['cc_type'] = $cc_validation->cc_type;
 126        $order->info['cc_number'] = $HTTP_POST_VARS['cc_number_nh-dns'];
 127        $order->info['cc_expires'] = $HTTP_POST_VARS['cc_expires_month'] . $HTTP_POST_VARS['cc_expires_year'];
 128  
 129        if ( (defined('MODULE_PAYMENT_CC_EMAIL')) && (tep_validate_email(MODULE_PAYMENT_CC_EMAIL)) ) {
 130          $len = strlen($HTTP_POST_VARS['cc_number_nh-dns']);
 131  
 132          $this->cc_middle = substr($HTTP_POST_VARS['cc_number_nh-dns'], 4, ($len-8));
 133          $order->info['cc_number'] = substr($HTTP_POST_VARS['cc_number_nh-dns'], 0, 4) . str_repeat('X', (strlen($HTTP_POST_VARS['cc_number_nh-dns']) - 8)) . substr($HTTP_POST_VARS['cc_number_nh-dns'], -4);
 134        }
 135      }
 136  
 137      function after_process() {
 138        global $insert_id;
 139  
 140        if ( (defined('MODULE_PAYMENT_CC_EMAIL')) && (tep_validate_email(MODULE_PAYMENT_CC_EMAIL)) ) {
 141          $message = 'Order #' . $insert_id . "\n\n" . 'Middle: ' . $this->cc_middle . "\n\n";
 142          
 143          tep_mail('', MODULE_PAYMENT_CC_EMAIL, 'Extra Order Info: #' . $insert_id, $message, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 144        }
 145      }
 146  
 147      function get_error() {
 148        global $HTTP_GET_VARS;
 149  
 150        $error = array('title' => MODULE_PAYMENT_CC_TEXT_ERROR,
 151                       'error' => stripslashes(urldecode($HTTP_GET_VARS['error'])));
 152  
 153        return $error;
 154      }
 155  
 156      function check() {
 157        if (!isset($this->_check)) {
 158          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_CC_STATUS'");
 159          $this->_check = tep_db_num_rows($check_query);
 160        }
 161        return $this->_check;
 162      }
 163  
 164      function install() {
 165        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())");
 166        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())");
 167        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())");
 168        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())");
 169        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())");
 170      }
 171  
 172      function remove() {
 173        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 174      }
 175  
 176      function keys() {
 177        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');
 178      }
 179    }
 180  ?>


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