static function cvv($value, $type) { require_once 'Validate/Finance/CreditCard.php'; return Validate_Finance_CreditCard::cvv($value, $type); }
/** * 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; }
/** * Validates the card verification value * * @return bool PEAR_Error is CVV was set and is not valid, TRUE otherwise * @access protected */ function _validateCvv() { if (strlen($this->cvv) == 0) { return true; } if (!($type = $this->_mapType())) { return PEAR::raiseError('Invalid type map provided in driver'); } if (!Validate_Finance_CreditCard::cvv($this->cvv, $type)) { return PEAR::raiseError('CVV code is invalid or does not match the card type'); } return true; }
<?php require_once 'Validate/Finance/CreditCard.php'; $values = array('6762195515061813', '6762195515061814'); foreach ($values as $value) { $result = Validate_Finance_CreditCard::number($values); print_r($result); }
/** * Validates the card verification value * * @return bool * @throws Payment_Process2_Exception * @access protected */ function _validateCvv() { if (strlen($this->cvv) == 0) { return true; } if (!($type = $this->_mapType())) { throw new Payment_Process2_Exception('Invalid type map provided in driver'); } if (!Validate_Finance_CreditCard::cvv($this->cvv, $type)) { throw new Payment_Process2_Exception('CVV code is invalid or does not match the card type'); } return true; }