public static function CommercePaymentCreditCard::detectType in Commerce Core 7
Detects the credit card type based on the number.
Parameters
string $number: The credit card number.
Return value
array|false The credit card type, or NULL if unknown.
4 calls to CommercePaymentCreditCard::detectType()
- CommercePaymentCreditCardTest::testValidateNumber in modules/
payment/ tests/ commerce_payment_credit_card.test - Tests type detection.
- commerce_payment_validate_credit_card_number in modules/
payment/ includes/ commerce_payment.credit_card.inc - Validates a credit card number using the Luhn algorithm.
- commerce_payment_validate_credit_card_security_code in modules/
payment/ includes/ commerce_payment.credit_card.inc - Validates a card security code based on the type of the credit card.
- commerce_payment_validate_credit_card_type in modules/
payment/ includes/ commerce_payment.credit_card.inc - Validates a credit card number using an array of approved card types.
File
- modules/
payment/ includes/ commerce_payment.credit_card.inc, line 515 - Credit-card helper functions for Drupal commerce.
Class
- CommercePaymentCreditCard
- Provides logic for listing card types and validating card details.
Code
public static function detectType($number) {
if (!is_numeric($number)) {
return FALSE;
}
$types = self::getTypes();
foreach ($types as $type) {
foreach ($type['number_prefixes'] as $prefix) {
if (self::matchPrefix($number, $prefix)) {
return $type;
}
}
}
return FALSE;
}