View Source SimpleCardBrand (SimpleCardBrand v1.0.1)
Identify the card brand from the PAN or the first six or eight (UkrCard) PAN digits. The PAN must contain only digits without leading or trailing spaces.
Supports:
- American Express (:americanexpress)
- BORICA (:borica)
- China T-Union (:chinatunion)
- China UnionPay (:chinaunionpay)
- Dankort (:dankort)
- Diners Club (:dinersclub)
- Diners Club International (:dinersclubinternational)
- Discover (:discover)
- GPN (:gpn)
- Humo (:humo)
- InstaPayment (:instapayment)
- InterPayment (:interpayment)
- JCB: (:jcb)
- LankaPay: (:lankapay)
- Maestro (:maestro)
- Maestro UK (:maestrouk)
- Mastercard (:mastercard)
- Mir (:mir)
- Napas (:napas)
- RuPay (:rupay)
- Troy (:troy)
- UATP (:uatp)
- UkrCard (:ukrcard)
- UzCard (:uzcard)
- Verve (:verve)
- Visa (:visa)
- Visa Electron (:visaelectron)
Rules as per: https://en.wikipedia.org/wiki/Payment_card_number
Summary
Functions
Identify the card brand from the pan
.
Identify the card brand from a full or partial pan
and the actual PAN length.
Useful when identifying brands from previously-stored PANs.
Functions
@spec card_brand(String.t()) :: {:error, {:pan_too_long, String.t()} | {:pan_too_short, String.t()} | {:pan_unknown, String.t()}} | {:ok, atom()}
Identify the card brand from the pan
.
Examples
iex> SimpleCardBrand.card_brand("4111111111111111")
{:ok, :visa}
iex> SimpleCardBrand.card_brand("6040010012121161819")
{:ok, :ukrcard}
iex> SimpleCardBrand.card_brand("5060994444444416")
{:ok, :verve}
iex> SimpleCardBrand.card_brand("41111111111")
{:error, {:pan_too_short, "Minimum PAN length is 12, found 11."}}
iex> SimpleCardBrand.card_brand("41111111111111111120")
{:error, {:pan_too_long, "Maximum PAN length is 19, found 20."}}
@spec card_brand(String.t(), integer()) :: {:error, {:pan_too_long, String.t()} | {:pan_too_short, String.t()} | {:pan_unknown, String.t()}} | {:ok, atom()}
Identify the card brand from a full or partial pan
and the actual PAN length.
Useful when identifying brands from previously-stored PANs.
Check for UkrCard and Verve early.
Examples
iex> SimpleCardBrand.card_brand("411111", 16)
{:ok, :visa}
iex> SimpleCardBrand.card_brand("6040010012", 18)
{:ok, :ukrcard}
iex> SimpleCardBrand.card_brand("50609944444", 19)
{:ok, :verve}
iex> SimpleCardBrand.card_brand("4111111111111111", 10)
{:error, {:pan_too_short,"Minimum PAN length is 12, found 10."}}
iex> SimpleCardBrand.card_brand("0123456789012345678")
{:error, {:pan_unknown,"Unknown card brand."}}