Пример #1
0
 /**
  * Validates the credit card type
  *
  * Uses Validate_Finance_CreditCard to validate the type.
  *
  * @author Joe Stump <*****@*****.**>
  * @return mixed PEAR_Error on failure, TRUE on success
  * @see Payment_Process_Type_CreditCard::_getValidateTypeMap()
  * @see Validate_Finance_CreditCard
  */
 function _validateType()
 {
     if (!($type = $this->_mapType())) {
         return PEAR::raiseError('Invalid type map provided in driver');
     }
     if (!Validate_Finance_CreditCard::type($this->cardNumber, $type)) {
         return PEAR::raiseError('Credit card type not recognized or does not match the card number given');
     }
     return true;
 }
 /**
  * Validates a credit card number
  *
  * If a type is passed, the card will be checked against it.
  * This method only checks the number locally. No banks or payment
  * gateways are involved.
  * This method doesn't guarantee that the card is legitimate. It merely
  * checks the card number passes a mathematical algorithm.
  *
  * @param string $creditCard number (spaces and dashes tolerated)
  * @param string $cardType   type/brand of card (case insensitive)
  *               "MasterCard", "Visa", "AMEX", "AmericanExpress",
  *               "American Express", "Diners", "DinersClub", "Diners Club",
  *               "CarteBlanche", "Carte Blanche", "Discover", "JCB",
  *               "EnRoute", "Eurocard", "Eurocard/MasterCard".
  *
  * @return bool   TRUE if number is valid, FALSE otherwise
  * @access public
  * @static
  */
 function number($creditCard, $cardType = null)
 {
     $cc = str_replace(array('-', ' '), '', $creditCard);
     if (($len = strlen($cc)) < 13 || strspn($cc, '0123456789') != $len) {
         return false;
     }
     // Only apply the Luhn algorithm for cards other than enRoute
     // So check if we have a enRoute card now
     if (strlen($cc) != 15 || substr($cc, 0, 4) != '2014' && substr($cc, 0, 4) != '2149') {
         if (!Validate_Finance_CreditCard::_luhn($cc)) {
             return false;
         }
     }
     if (is_string($cardType)) {
         return Validate_Finance_CreditCard::type($cc, $cardType);
     }
     return true;
 }
Пример #3
0
 /**
  * Validates the credit card type
  *
  * Uses Validate_Finance_CreditCard to validate the type.
  *
  * @author Joe Stump <*****@*****.**>
  * @return bool
  * @throws Payment_Process2_Exception
  * @see Payment_Process2_Type_CreditCard::_mapType()
  * @see Validate_Finance_CreditCard
  */
 function _validateType()
 {
     if (!($type = $this->_mapType())) {
         throw new Payment_Process2_Exception('Credit card type not recognized by in driver');
     }
     if (!Validate_Finance_CreditCard::type($this->cardNumber, $type)) {
         throw new Payment_Process2_Exception('Credit card type not recognized or does not match the card number given');
     }
     return true;
 }