CreditCard

Credit card validations library

Summary

Functions

Returns the type of card

Returns true if number is among the list of test credit card numbers ;otherwise, it returns false

Returns CreditCard options map

Returns True if card matches the allowed card patterns. By default, the set of cards matched against are Amex, VISA, MasterCard, Discover, Diners Club and JCB. Otherwise, false

Performs luhn check on the credit card number

Types

opts :: %{atom => String.t}
validation_error :: {:error, :unrecognized_card_type}

Functions

card_is(number, atom)

Specs

card_is(String.t, atom) :: boolean
card_type(number)

Specs

card_type(String.t) :: atom | validation_error

Returns the type of card

Examples

iex> CreditCard.card_type("3566002020360505")
:jcb
is_allowed_card_type?(number, opts \\ %{allowed_card_types: [:visa, :master_card, :maestro, :diners_club, :amex, :discover, :jcb], test_numbers_are_valid: false})

Specs

is_allowed_card_type?(String.t, opts) :: boolean

Returns true if the validation options is set to recognize the card’s class. Otherwise, false.

Examples

iex> CreditCard.is_allowed_card_type?("5555555555554444")
true
is_test_number(number)

Specs

is_test_number(String.t) :: boolean

Returns true if number is among the list of test credit card numbers ;otherwise, it returns false.

new()

Specs

new :: opts

Returns CreditCard options map.

valid?(number, opts \\ %{allowed_card_types: [:visa, :master_card, :maestro, :diners_club, :amex, :discover, :jcb], test_numbers_are_valid: false})

Specs

valid?(String.t, opts) :: boolean

Returns True if card matches the allowed card patterns. By default, the set of cards matched against are Amex, VISA, MasterCard, Discover, Diners Club and JCB. Otherwise, false

Examples

iex> CreditCard.valid?(“4000111111111115”) false

verify_luhn(number)

Specs

verify_luhn(String.t) :: boolean

Performs luhn check on the credit card number