[ Index ]
 

Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

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

   1  <?php
   2  /**

   3   * cc payment method class

   4   *

   5   * @package paymentMethod

   6   * @copyright Copyright 2003-2006 Zen Cart Development Team

   7   * @copyright Portions Copyright 2003 osCommerce

   8   * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0

   9   * @version $Id: cc.php 4903 2006-11-10 10:26:06Z drbyte $

  10   */
  11  /**

  12   * Manual Credit Card payment module

  13   * This module is used for MANUAL processing of credit card data collected from customers.

  14   * It should ONLY be used if no other gateway is suitable, AND you must have SSL active on your server for your own protection.

  15   */
  16  class cc extends base {
  17    /**

  18     * $code determines the internal 'code' name used to designate "this" payment module

  19     *

  20     * @var string

  21     */
  22    var $code;
  23    /**

  24     * $title is the displayed name for this payment method

  25     *

  26     * @var string

  27     */
  28    var $title;
  29    /**

  30     * $description is a soft name for this payment method

  31     *

  32     * @var string

  33     */
  34    var $description;
  35    /**

  36     * $enabled determines whether this module shows or not... in catalog.

  37     *

  38     * @var boolean

  39     */
  40    var $enabled;
  41    /**

  42     * @return cc

  43     */
  44    function cc() {
  45      global $order;
  46  
  47      $this->code = 'cc';
  48      $this->title = MODULE_PAYMENT_CC_TEXT_TITLE;
  49      $this->description = MODULE_PAYMENT_CC_TEXT_DESCRIPTION;
  50      $this->sort_order = MODULE_PAYMENT_CC_SORT_ORDER;
  51      $this->enabled = ((MODULE_PAYMENT_CC_STATUS == 'True') ? true : false);
  52  
  53      if ((int)MODULE_PAYMENT_CC_ORDER_STATUS_ID > 0) {
  54        $this->order_status = MODULE_PAYMENT_CC_ORDER_STATUS_ID;
  55      }
  56  
  57      if (is_object($order)) $this->update_status();
  58    }
  59    /**

  60     * calculate zone matches and flag settings to determine whether this module should display to customers or not

  61     *

  62     */
  63    function update_status() {
  64      global $order, $db;
  65  
  66      if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_CC_ZONE > 0) ) {
  67        $check_flag = false;
  68        $check = $db->Execute("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");
  69        while (!$check->EOF) {
  70          if ($check->fields['zone_id'] < 1) {
  71            $check_flag = true;
  72            break;
  73          } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
  74            $check_flag = true;
  75            break;
  76          }
  77          $check->MoveNext();
  78        }
  79  
  80        if ($check_flag == false) {
  81          $this->enabled = false;
  82        }
  83      }
  84    }
  85    /**

  86     * JS validation which does error-checking of data-entry if this module is selected for use

  87     * (Number, Owner, and CVV Lengths)

  88     *

  89     * @return string

  90     */
  91    function javascript_validation() {
  92      $js = '  if (payment_value == "' . $this->code . '") {' . "\n" .
  93      '    var cc_owner = document.checkout_payment.cc_owner.value;' . "\n" .
  94      '    var cc_number = document.checkout_payment.cc_number.value;' . "\n";
  95  
  96      if (MODULE_PAYMENT_CC_COLLECT_CVV == 'True')  {
  97        $js .= '    var cc_cvv = document.checkout_payment.cc_cvv.value;' . "\n";
  98      }
  99  
 100      $js .= '    if (cc_owner == "" || cc_owner.length < ' . CC_OWNER_MIN_LENGTH . ') {' . "\n" .
 101      '      error_message = error_message + "' . MODULE_PAYMENT_CC_TEXT_JS_CC_OWNER . '";' . "\n" .
 102      '      error = 1;' . "\n" .
 103      '    }' . "\n" .
 104      '    if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" .
 105      '      error_message = error_message + "' . MODULE_PAYMENT_CC_TEXT_JS_CC_NUMBER . '";' . "\n" .
 106      '      error = 1;' . "\n" .
 107      '    }' . "\n";
 108  
 109      if (MODULE_PAYMENT_CC_COLLECT_CVV == 'True')  {
 110        $js .= '    if (cc_cvv == "" || cc_cvv.length < ' . CC_CVV_MIN_LENGTH . ') {' . "\n" .
 111        '      error_message = error_message + "' . MODULE_PAYMENT_CC_TEXT_JS_CC_CVV . '";' . "\n" .
 112        '      error = 1;' . "\n" .
 113        '    }' . "\n";
 114      }
 115  
 116      $js .= '  }' . "\n";
 117      return $js;
 118    }
 119    /**

 120     * Builds set of input fields for collecting cc info

 121     *

 122     * @return array

 123     */
 124    function selection() {
 125      global $order;
 126  
 127      for ($i=1; $i<13; $i++) {
 128        $expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));
 129      }
 130  
 131      $today = getdate();
 132      for ($i=$today['year']; $i < $today['year']+10; $i++) {
 133        $expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
 134      }
 135  
 136      $onFocus = ' onfocus="methodSelect(\'pmt-' . $this->code . '\')"';
 137  
 138      $selection = array('id' => $this->code,
 139                         'module' => $this->title,
 140                         'fields' => array(array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_OWNER,
 141                                                 'field' => zen_draw_input_field('cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'], 'id="'.$this->code.'-cc-owner"' . $onFocus),
 142                                                 'tag' => $this->code.'-cc-owner'),
 143                                           array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_NUMBER,
 144                                                 'field' => zen_draw_input_field('cc_number', '', 'id="' . $this->code . '-cc-number"' . $onFocus),
 145                                                 'tag' => $this->code . '-cc-number'),
 146                                           array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_EXPIRES,
 147                                                 'field' => zen_draw_pull_down_menu('cc_expires_month', $expires_month, '', 'id="'.$this->code.'-cc-expires-month"' . $onFocus) . '&nbsp;' . zen_draw_pull_down_menu('cc_expires_year', $expires_year,  '', 'id="'.$this->code.'-cc-expires-year"' . $onFocus),
 148                                                 'tag' => $this->code.'-cc-expires-month')
 149                         ));
 150  
 151      if (MODULE_PAYMENT_CC_COLLECT_CVV == 'True')  {
 152        $selection['fields'][] = array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_CVV,
 153                                       'field' => zen_draw_input_field('cc_cvv', '', 'size="4" maxlength="4" id="'.$this->code.'-cc-cvv"' . $onFocus),
 154                                       'tag' => $this->code.'-cc-cvv');
 155      }
 156      return $selection;
 157    }
 158    /**

 159     * Evaluates the Credit Card Type for acceptance and the validity of the Credit Card Number & Expiration Date

 160     *

 161     */
 162    function pre_confirmation_check() {
 163      global $_POST, $messageStack;
 164      /**

 165       * Load the cc_validation class

 166       */
 167      include(DIR_WS_CLASSES . 'cc_validation.php');
 168  
 169      $cc_validation = new cc_validation();
 170      $result = $cc_validation->validate($_POST['cc_number'], $_POST['cc_expires_month'], $_POST['cc_expires_year']);
 171  
 172      $error = '';
 173      switch ($result) {
 174        case -1:
 175        $error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
 176        break;
 177        case -2:
 178        case -3:
 179        case -4:
 180        $error = TEXT_CCVAL_ERROR_INVALID_DATE;
 181        break;
 182        case false:
 183        $error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
 184        break;
 185      }
 186      /**

 187       *

 188       */
 189      if ( ($result == false) || ($result < 1) ) {
 190        $payment_error_return = 'payment_error=' . $this->code . '&cc_owner=' . urlencode($_POST['cc_owner']) . '&cc_expires_month=' . $_POST['cc_expires_month'] . '&cc_expires_year=' . $_POST['cc_expires_year'];
 191  
 192        $messageStack->add_session('checkout_payment', $error . '<!-- ['.$this->code.'] -->', 'error');
 193        zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));
 194      }
 195  
 196      $this->cc_card_type = $cc_validation->cc_type;
 197      $this->cc_card_number = $cc_validation->cc_number;
 198    }
 199    /**

 200     * Display Credit Card Information on the Checkout Confirmation Page

 201     *

 202     * @return array

 203     */
 204    function confirmation() {
 205      global $_POST;
 206  
 207      $confirmation = array('title' => $this->title . ': ' . $this->cc_card_type,
 208                            'fields' => array(array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_OWNER,
 209                            'field' => $_POST['cc_owner']),
 210                      array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_NUMBER,
 211                            'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)),
 212                      array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_EXPIRES,
 213                            'field' => strftime('%B, %Y', mktime(0,0,0,$_POST['cc_expires_month'], 1, '20' . $_POST['cc_expires_year'])))));
 214  
 215      if (MODULE_PAYMENT_CC_COLLECT_CVV == 'True')  {
 216        $confirmation['fields'][] = array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_CVV,
 217                                          'field' => $_POST['cc_cvv']);
 218      }
 219      return $confirmation;
 220    }
 221    /**

 222     * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.

 223     * This sends the data to the payment gateway for processing.

 224     * (These are hidden fields on the checkout confirmation page)

 225     *

 226     * @return string

 227     */
 228    function process_button() {
 229      global $_POST;
 230  
 231      $process_button_string = zen_draw_hidden_field('cc_owner', $_POST['cc_owner']) .
 232                               zen_draw_hidden_field('cc_expires', $_POST['cc_expires_month'] . $_POST['cc_expires_year']) .
 233                               zen_draw_hidden_field('cc_type', $this->cc_card_type) .
 234                               zen_draw_hidden_field('cc_number', $this->cc_card_number);
 235      if (MODULE_PAYMENT_CC_COLLECT_CVV == 'True')  {
 236        $process_button_string .= zen_draw_hidden_field('cc_cvv', $_POST['cc_cvv']);
 237      }
 238  
 239      return $process_button_string;
 240    }
 241    /**

 242     * Store the CC info to the order

 243     *

 244     */
 245    function before_process() {
 246      global $_POST, $order;
 247  
 248      if (defined('MODULE_PAYMENT_CC_STORE_NUMBER') && MODULE_PAYMENT_CC_STORE_NUMBER == 'True') {
 249        $order->info['cc_number'] = $_POST['cc_number'];
 250      }
 251      $order->info['cc_expires'] = $_POST['cc_expires'];
 252      $order->info['cc_type'] = $_POST['cc_type'];
 253      $order->info['cc_owner'] = $_POST['cc_owner'];
 254      $order->info['cc_cvv'] = $_POST['cc_cvv'];
 255  
 256      $len = strlen($_POST['cc_number']);
 257      $this->cc_middle = substr($_POST['cc_number'], 4, ($len-8));
 258      if ( (defined('MODULE_PAYMENT_CC_EMAIL')) && (zen_validate_email(MODULE_PAYMENT_CC_EMAIL)) ) {
 259        $order->info['cc_number'] = substr($_POST['cc_number'], 0, 4) . str_repeat('X', (strlen($_POST['cc_number']) - 8)) . substr($_POST['cc_number'], -4);
 260      }
 261    }
 262    /**

 263     * Send the collected information via email to the store owner, storing outer digits and emailing middle digits

 264     *

 265     */
 266    function after_process() {
 267      global $insert_id;
 268  
 269      $message = sprintf(MODULE_PAYMENT_CC_TEXT_MIDDLE_DIGITS_MESSAGE, $insert_id, $this->cc_middle);
 270      $html_msg['EMAIL_MESSAGE_HTML'] = str_replace("\n\n",'<br />',$message);
 271  
 272      if ( (defined('MODULE_PAYMENT_CC_EMAIL')) && (zen_validate_email(MODULE_PAYMENT_CC_EMAIL)) ) {
 273        zen_mail(MODULE_PAYMENT_CC_EMAIL, MODULE_PAYMENT_CC_EMAIL, SEND_EXTRA_CC_EMAILS_TO_SUBJECT . $insert_id, $message, STORE_NAME, EMAIL_FROM, $html_msg, 'cc_middle_digs');
 274      } else {
 275        $message = MODULE_PAYMENT_CC_TEXT_EMAIL_WARNING . $message;
 276        $html_msg['EMAIL_MESSAGE_HTML'] = str_replace("\n\n",'<br />',$message);
 277        zen_mail(EMAIL_FROM, EMAIL_FROM, MODULE_PAYMENT_CC_TEXT_EMAIL_ERROR . SEND_EXTRA_CC_EMAILS_TO_SUBJECT . $insert_id, $message, STORE_NAME, EMAIL_FROM, $html_msg, 'cc_middle_digs');
 278      }
 279    }
 280    /**

 281     * Store additional order information

 282     *

 283     * @param int $zf_order_id

 284     */
 285    function after_order_create($zf_order_id) {
 286      global $db, $order;
 287      if (MODULE_PAYMENT_CC_COLLECT_CVV == 'True')  {
 288        $db->execute("update "  . TABLE_ORDERS . " set cc_cvv ='" . $order->info['cc_cvv'] . "' where orders_id = '" . $zf_order_id ."'");
 289      }
 290    }
 291    /**

 292     * Used to display error message details

 293     *

 294     * @return array

 295     */
 296    function get_error() {
 297      global $_GET;
 298  
 299      $error = array('title' => MODULE_PAYMENT_CC_TEXT_ERROR,
 300                     'error' => stripslashes(urldecode($_GET['error'])));
 301  
 302      return $error;
 303    }
 304    /**

 305     * Check to see whether module is installed

 306     *

 307     * @return boolean

 308     */
 309    function check() {
 310      global $db;
 311      if (!isset($this->_check)) {
 312        $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_CC_STATUS'");
 313        $this->_check = $check_query->RecordCount();
 314      }
 315      return $this->_check;
 316    }
 317    /**

 318     * Install the payment module and its configuration settings

 319     *

 320     */
 321    function install() {
 322      global $db;
 323      $db->Execute("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', '130', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
 324      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Split Credit Card Email Address', 'MODULE_PAYMENT_CC_EMAIL', '" . STORE_OWNER_EMAIL_ADDRESS . "', 'If an email address is entered, the middle digits of the credit card number will be sent to the email address (the outside digits are stored in the database with the middle digits censored)', '6', '131', now())");
 325      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Collect & store the CVV number', 'MODULE_PAYMENT_CC_COLLECT_CVV', 'True', 'Do you want to collect the CVV number. Note: If you do the CVV number will be stored in the database in an encoded format.', '6', '132', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
 326      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Store the Credit Card Number', 'MODULE_PAYMENT_CC_STORE_NUMBER', 'False', 'Do you want to store the Credit Card Number?<br /><br /><strong>WARNING: The Credit Card Number will be stored unenecrypted, and as such may represent a security problem.</strong>', '6', '133', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
 327      $db->Execute("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', '134' , now())");
 328      $db->Execute("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', '135', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
 329      $db->Execute("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', '136', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
 330    }
 331    /**

 332     * Remove the module and all its settings

 333     *

 334     */
 335    function remove() {
 336      global $db;
 337      $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key like 'MODULE_PAYMENT_CC_%'");
 338    }
 339    /**

 340     * Internal list of configuration keys used for configuration of the module

 341     *

 342     * @return array

 343     */
 344    function keys() {
 345      return array('MODULE_PAYMENT_CC_STATUS', 'MODULE_PAYMENT_CC_COLLECT_CVV', 'MODULE_PAYMENT_CC_EMAIL', 'MODULE_PAYMENT_CC_ZONE', 'MODULE_PAYMENT_CC_ORDER_STATUS_ID', 'MODULE_PAYMENT_CC_SORT_ORDER');
 346    }
 347  }
 348  ?>


Généré le : Mon Nov 26 16:45:43 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics