You are here

public static function CreditCard::getTypes in Commerce Core 8.2

Gets all available credit card types.

Return value

\Drupal\commerce_payment\CreditCardType[] The credit card types.

7 calls to CreditCard::getTypes()
CommercePaymentGateway::__construct in modules/payment/src/Annotation/CommercePaymentGateway.php
Constructs a new CommercePaymentGateway object.
CreditCard::detectType in modules/payment/src/CreditCard.php
Detects the credit card type based on the number.
CreditCard::getType in modules/payment/src/CreditCard.php
Gets the credit card type with the given ID.
CreditCard::getTypeLabels in modules/payment/src/CreditCard.php
Gets the labels of all available credit card types.
CreditCardTest::testGetAvsResponseCodeMeanings in modules/payment/tests/src/Unit/CreditCardTest.php
@covers ::getAvsResponseCodeMeanings

... See full list

File

modules/payment/src/CreditCard.php, line 43

Class

CreditCard
Provides logic for listing card types and validating card details.

Namespace

Drupal\commerce_payment

Code

public static function getTypes() : array {
  $definitions = [
    'visa' => [
      'id' => 'visa',
      'label' => new TranslatableMarkup('Visa'),
      'number_prefixes' => [
        '4',
      ],
      'number_lengths' => [
        16,
        18,
        19,
      ],
    ],
    'mastercard' => [
      'id' => 'mastercard',
      'label' => new TranslatableMarkup('Mastercard'),
      'number_prefixes' => [
        '51-55',
        '222100-272099',
      ],
    ],
    'maestro' => [
      'id' => 'maestro',
      'label' => new TranslatableMarkup('Maestro'),
      'number_prefixes' => [
        '5018',
        '502',
        '503',
        '506',
        '56',
        '58',
        '639',
        '6220',
        '67',
      ],
      'number_lengths' => [
        12,
        13,
        14,
        15,
        16,
        17,
        18,
        19,
      ],
    ],
    'amex' => [
      'id' => 'amex',
      'label' => new TranslatableMarkup('American Express'),
      'number_prefixes' => [
        '34',
        '37',
      ],
      'number_lengths' => [
        15,
      ],
      'security_code_length' => 4,
    ],
    'dinersclub' => [
      'id' => 'dinersclub',
      'label' => new TranslatableMarkup('Diners Club'),
      'number_prefixes' => [
        '300-305',
        '309',
        '36',
        '38',
        '39',
      ],
      'number_lengths' => [
        14,
        16,
        19,
      ],
    ],
    'discover' => [
      'id' => 'discover',
      'label' => new TranslatableMarkup('Discover Card'),
      'number_prefixes' => [
        '6011',
        '622126-622925',
        '644-649',
        '65',
      ],
      'number_lengths' => [
        16,
        19,
      ],
    ],
    'jcb' => [
      'id' => 'jcb',
      'label' => new TranslatableMarkup('JCB'),
      'number_prefixes' => [
        '3528-3589',
      ],
      'number_lengths' => [
        16,
        17,
        18,
        19,
      ],
    ],
    'unionpay' => [
      'id' => 'unionpay',
      'label' => new TranslatableMarkup('UnionPay'),
      'number_prefixes' => [
        '62',
        '88',
      ],
      'number_lengths' => [
        16,
        17,
        18,
        19,
      ],
      'uses_luhn' => FALSE,
    ],
  ];
  foreach ($definitions as $id => $definition) {
    self::$types[$id] = new CreditCardType($definition);
  }
  return self::$types;
}