Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
/ card-bin-ex Public archive

💳 Elixir module to get the CreditCard brand based in the first digits

License

Notifications You must be signed in to change notification settings

ingresse/card-bin-ex

Repository files navigation

💳 CardBinEX

Elixir module to discover the CreditCard brand based in the first digits.

Valid CreditCard brands

brand alias
Visa visa
Elo elo
JCB jcb
Diners diners
Discover discover
MasterCard master
Hipercard hipercard
American Express amex

Install

def deps do
  [
    {:card_bin_ex, "~> 1.0"}
  ]
end

Usage

Get the creditcard brand base in the first digits.

iex> CardBinEx.brand_from_number("4716892")
{:ok, "visa"}

iex> CardBinEx.brand_from_number("9716892")
{:error, :card_brand, "9716892"}

Get the creditcard brand base in the first digits and return only the brand.

It will raise CardBinEx.Error if is an invalid bin.

iex> CardBinEx.brand_from_number!("4716892")
"visa"

iex> try do
...>   CardBinEx.brand_from_number!("9716892")
...> rescue
...>   e in CardBinEx.Error -> IO.puts(e.message)
..> end