You are here

function commerce_payment_validate_credit_card_type in Commerce Core 7

Validates a credit card number using an array of approved card types.

Parameters

int $number: The credit card number to validate.

array $card_types: An array of credit card types containing any of the keys from the array returned by commerce_payment_credit_card_types(). Only numbers determined to be of the types specified will pass validation. This determination is based on the length of the number and the valid number ranges for the various types of known credit card types.

Return value

FALSE if a number is not valid based on approved credit card types or the credit card type if it is valid and could be determined.

See also

http://en.wikipedia.org/wiki/Bank_card_number#Issuer_Identification_Numb...

commerce_payment_credit_card_types()

1 call to commerce_payment_validate_credit_card_type()
commerce_payment_credit_card_validate in modules/payment/includes/commerce_payment.credit_card.inc
Validates a set of credit card details entered via the credit card form.

File

modules/payment/includes/commerce_payment.credit_card.inc, line 280
Credit-card helper functions for Drupal commerce.

Code

function commerce_payment_validate_credit_card_type($number, array $card_types = array()) {
  $type = CommercePaymentCreditCard::detectType($number);
  if (!$type || !in_array($type['id'], $card_types)) {
    return FALSE;
  }
  return $type['id'];
}