public static function CommercePaymentCreditCard::getTypes in Commerce Core 7
Gets all available card types.
Return value
array The array of card types, keyed by card type ID.
3 calls to CommercePaymentCreditCard::getTypes()
- CommercePaymentCreditCard::detectType in modules/
payment/ includes/ commerce_payment.credit_card.inc - Detects the credit card type based on the number.
- CommercePaymentCreditCard::getTypeLabels in modules/
payment/ includes/ commerce_payment.credit_card.inc - Gets the labels of all available credit card types.
- CommercePaymentCreditCardTest::testsValidateSecurityCode in modules/
payment/ tests/ commerce_payment_credit_card.test - @covers ::validateSecurityCode
File
- modules/
payment/ includes/ commerce_payment.credit_card.inc, line 422 - Credit-card helper functions for Drupal commerce.
Class
- CommercePaymentCreditCard
- Provides logic for listing card types and validating card details.
Code
public static function getTypes() {
$definitions = array(
'visa' => array(
'id' => 'visa',
'label' => t('Visa'),
'number_prefixes' => array(
'4',
),
'number_lengths' => array(
16,
18,
19,
),
),
'mastercard' => array(
'id' => 'mastercard',
'label' => t('Mastercard'),
'number_prefixes' => array(
'51-55',
'222100-272099',
),
),
'maestro' => array(
'id' => 'maestro',
'label' => t('Maestro'),
'number_prefixes' => array(
'5018',
'502',
'503',
'506',
'56',
'58',
'639',
'6220',
'67',
),
'number_lengths' => array(
12,
13,
14,
15,
16,
17,
18,
19,
),
),
'amex' => array(
'id' => 'amex',
'label' => t('American Express'),
'number_prefixes' => array(
'34',
'37',
),
'number_lengths' => array(
15,
),
'security_code_length' => 4,
),
'dc' => array(
'id' => 'dc',
'label' => t('Diners Club'),
'number_prefixes' => array(
'300-305',
'309',
'36',
'38',
'39',
),
'number_lengths' => array(
14,
16,
19,
),
),
'discover' => array(
'id' => 'discover',
'label' => t('Discover Card'),
'number_prefixes' => array(
'6011',
'622126-622925',
'644-649',
'65',
),
'number_lengths' => array(
16,
19,
),
),
'jcb' => array(
'id' => 'jcb',
'label' => t('JCB'),
'number_prefixes' => array(
'3528-3589',
),
'number_lengths' => array(
16,
17,
18,
19,
),
),
'unionpay' => array(
'id' => 'unionpay',
'label' => t('UnionPay'),
'number_prefixes' => array(
'62',
'88',
),
'number_lengths' => array(
16,
17,
18,
19,
),
'uses_luhn' => FALSE,
),
);
drupal_alter('commerce_card_type_info', $definitions);
foreach ($definitions as &$definition) {
$definition += array(
'number_lengths' => array(
16,
),
'security_code_length' => 3,
'uses_luhn' => TRUE,
);
}
return $definitions;
}