[ 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/classes/ -> cc_validation.php (source)

   1  <?php
   2  /**

   3   * cc_validation Class.

   4   *

   5   * @package classes

   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_validation.php 5209 2006-12-11 22:09:09Z drbyte $

  10   */
  11  if (!defined('IS_ADMIN_FLAG')) {
  12    die('Illegal Access');
  13  }
  14  /**

  15   * cc_validation Class.

  16   * Class to validate credit card numbers etc

  17   *

  18   * @package classes

  19   */
  20  class cc_validation extends base {
  21    var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year;
  22  
  23      function validate($number, $expiry_m, $expiry_y, $start_m = null, $start_y = null) {
  24      $this->cc_number = ereg_replace('[^0-9]', '', $number);
  25  
  26        // Check specific card-types based on first 6 digits:

  27        $NumberLeft6 = substr($this->cc_number, 0, 6);
  28  
  29        /***** MASTERCARD *****/

  30        if (($NumberLeft6 >= 510000) && ($NumberLeft6 <= 559999)
  31            && (ereg('[0-9]{16}', $this->cc_number)) and CC_ENABLED_MC=='1') {
  32            $this->cc_type = "MasterCard";
  33        }
  34  
  35        /***** SWITCH *****/

  36        elseif (( (($NumberLeft6 >= 490302) && ($NumberLeft6 <= 490309))
  37                  || (($NumberLeft6 >= 490335) && ($NumberLeft6 <= 490339))
  38                  || (($NumberLeft6 >= 491101) && ($NumberLeft6 <= 491102))
  39                  || (($NumberLeft6 >= 491174) && ($NumberLeft6 <= 491182))
  40                  || (($NumberLeft6 >= 493600) && ($NumberLeft6 <= 493699))
  41                  ||  ($NumberLeft6 == 564182)
  42                  || (($NumberLeft6 >= 633300) && ($NumberLeft6 <= 633349))
  43                  || (($NumberLeft6 >= 675900) && ($NumberLeft6 <= 675999))
  44                  ) && (ereg('[0-9]{16}|[0-9]{18}|[0-9]{19}', $this->cc_number))  and CC_ENABLED_SWITCH=='1') {
  45            $this->cc_type = "Switch";
  46        }
  47  
  48        /***** SOLO *****/

  49        elseif (( (($NumberLeft6 >= 633450) && ($NumberLeft6 <= 633460))
  50                  || (($NumberLeft6 >= 633462) && ($NumberLeft6 <= 633472))
  51                  || (($NumberLeft6 >= 633474) && ($NumberLeft6 <= 633475))
  52                  ||  ($NumberLeft6 == 633477)
  53                  || (($NumberLeft6 >= 633479) && ($NumberLeft6 <= 633480))
  54                  || (($NumberLeft6 >= 633482) && ($NumberLeft6 <= 633489))
  55                  ||  ($NumberLeft6 == 633498)
  56                  || (($NumberLeft6 >= 676700) && ($NumberLeft6 <= 676799))
  57                  ) && (ereg('[0-9]{16}|[0-9]{18}|[0-9]{19}', $this->cc_number))  and CC_ENABLED_SOLO=='1') {
  58            $this->cc_type = "Solo";
  59        }
  60  
  61        /***** JCB *****/

  62        elseif (( (($NumberLeft6 >= 352800) && ($NumberLeft6 <= 358999))
  63                  ||  ($NumberLeft6 == 411111)
  64                  )
  65                && (ereg('[0-9]{16}', $this->cc_number))  and CC_ENABLED_JCB=='1') {
  66            $this->cc_type = "JCB";
  67        }
  68  
  69        /***** MAESTRO *****/

  70        elseif (( (($NumberLeft6 >= 493698) && ($NumberLeft6 <= 493699))
  71                  ||  ($NumberLeft6 == 490303)
  72                  || (($NumberLeft6 >= 633302) && ($NumberLeft6 <= 633349))
  73                  || (($NumberLeft6 >= 675900) && ($NumberLeft6 <= 675999))
  74                  || (($NumberLeft6 >= 500000) && ($NumberLeft6 <= 509999))
  75                  || (($NumberLeft6 >= 560000) && ($NumberLeft6 <= 589999))
  76                  || (($NumberLeft6 >= 600000) && ($NumberLeft6 <= 699999))
  77                  ) && (ereg('[0-9]{16}', $this->cc_number))  and CC_ENABLED_MAESTRO=='1') {
  78            $this->cc_type = "Maestro";
  79        }
  80  
  81        /***** VISA *****/

  82        elseif (( (($NumberLeft6 >= 400000) && ($NumberLeft6 <= 499999))
  83                  // ensure we exclude AMT only cards

  84                  && !( (($NumberLeft6 >= 490300) && ($NumberLeft6 <= 490301))
  85                        || (($NumberLeft6 >= 490310) && ($NumberLeft6 <= 490334))
  86                        || (($NumberLeft6 >= 490340) && ($NumberLeft6 <= 490399))
  87                        || (($NumberLeft6 >= 490400) && ($NumberLeft6 <= 490409))
  88                        ||  ($NumberLeft6 == 490419)
  89                        ||  ($NumberLeft6 == 490451)
  90                        ||  ($NumberLeft6 == 490459)
  91                        ||  ($NumberLeft6 == 490467)
  92                        || (($NumberLeft6 >= 490475) && ($NumberLeft6 <= 490478))
  93                        || (($NumberLeft6 >= 490500) && ($NumberLeft6 <= 490599))
  94                        || (($NumberLeft6 >= 491103) && ($NumberLeft6 <= 491173))
  95                        || (($NumberLeft6 >= 491183) && ($NumberLeft6 <= 491199))
  96                        || (($NumberLeft6 >= 492800) && ($NumberLeft6 <= 492899))
  97                        || (($NumberLeft6 >= 498700) && ($NumberLeft6 <= 498799))
  98                        )
  99                  ) && (ereg('[0-9]{16}|[0-9]{13}', $this->cc_number))  and CC_ENABLED_VISA=='1') {
 100            $this->cc_type = 'Visa';
 101  
 102      // traditional CC hash checks:

 103      } elseif (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number) and CC_ENABLED_VISA=='1') {
 104        $this->cc_type = 'Visa';
 105      } elseif (ereg('^5[1-5][0-9]{14}$', $this->cc_number) and CC_ENABLED_MC=='1') {
 106        $this->cc_type = 'Master Card';
 107      } elseif (ereg('^3[47][0-9]{13}$', $this->cc_number) and CC_ENABLED_AMEX=='1') {
 108        $this->cc_type = 'American Express';
 109      } elseif (ereg('^3(0[0-5]|[68][0-9])[0-9]{11}$', $this->cc_number) and CC_ENABLED_DINERS_CLUB=='1') {
 110        $this->cc_type = 'Diners Club';
 111      } elseif (ereg('^6011[0-9]{12}$', $this->cc_number) and CC_ENABLED_DISCOVER=='1') {
 112        $this->cc_type = 'Discover';
 113      } elseif (ereg('^(3[0-9]{4}|2131|1800)[0-9]{11}$', $this->cc_number) and CC_ENABLED_JCB=='1') {
 114        $this->cc_type = 'JCB';
 115      } elseif (ereg('^5610[0-9]{12}$', $this->cc_number) and CC_ENABLED_AUSTRALIAN_BANKCARD=='1') {
 116        $this->cc_type = 'Australian BankCard';
 117      } else {
 118        return -1;
 119      }
 120  
 121      if (is_numeric($expiry_m) && ($expiry_m > 0) && ($expiry_m < 13)) {
 122        $this->cc_expiry_month = $expiry_m;
 123      } else {
 124        return -2;
 125      }
 126  
 127      $current_year = date('Y');
 128      $expiry_y = substr($current_year, 0, 2) . $expiry_y;
 129      if (is_numeric($expiry_y) && ($expiry_y >= $current_year) && ($expiry_y <= ($current_year + 10))) {
 130        $this->cc_expiry_year = $expiry_y;
 131      } else {
 132        return -3;
 133      }
 134  
 135      if ($expiry_y == $current_year) {
 136        if ($expiry_m < date('n')) {
 137          return -4;
 138        }
 139      }
 140  
 141      // check the issue month & year but only for Switch/Solo cards

 142      if (($start_m || $start_y) && in_array($this->cc_type, array('Switch', 'Solo'))) {
 143        if (!(is_numeric($start_m) && ($start_m > 0) && ($start_m < 13))) {
 144          return -2;
 145        }
 146  
 147        if (strlen($start_y) == 2) {
 148          if ($start_y > 80) {
 149            $start_y = '19' . $start_y;
 150          } else {
 151            $start_y = '20' . $start_y;
 152          }
 153        }
 154  
 155        if (!is_numeric($start_y) || ($start_y > $current_year)) {
 156          return -3;
 157        }
 158        if (!($start_y >= ($current_year - 10))) {
 159          return -3;
 160        }
 161      }
 162      return $this->is_valid();
 163    }
 164  
 165    function is_valid() {
 166      $cardNumber = strrev($this->cc_number);
 167      $numSum = 0;
 168  
 169      for ($i=0; $i<strlen($cardNumber); $i++) {
 170        $currentNum = substr($cardNumber, $i, 1);
 171  
 172        // Double every second digit

 173        if ($i % 2 == 1) {
 174          $currentNum *= 2;
 175        }
 176  
 177        // Add digits of 2-digit numbers together

 178        if ($currentNum > 9) {
 179          $firstNum = $currentNum % 10;
 180          $secondNum = ($currentNum - $firstNum) / 10;
 181          $currentNum = $firstNum + $secondNum;
 182        }
 183  
 184        $numSum += $currentNum;
 185      }
 186  
 187      // If the total has no remainder it's OK

 188      return ($numSum % 10 == 0);
 189    }
 190  }
 191  ?>


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