View Source Appwrite.Consts.CreditCard (appwrite v0.1.9)

Provides constants and validation functions for different credit card types.

This module defines the allowed credit card types and provides helper functions to validate them, ensuring only recognized credit card types are used within the application.

Summary

Functions

Returns true if the given credit_card type is valid, otherwise false.

Guard clause to check if a given credit card type is valid.

Validates the given credit_card type and returns {:ok, credit_card} if it is valid, or {:error, "Invalid credit card type"} otherwise.

Validates the given credit_card type and returns it if it is valid. Raises an ArgumentError if the credit_card type is invalid.

Functions

is_valid_credit_card?(card)

@spec is_valid_credit_card?(String.t()) :: boolean()

Returns true if the given credit_card type is valid, otherwise false.

Examples

iex> CreditCard.is_valid_credit_card?("mastercard")
true

iex> CreditCard.is_valid_credit_card?("unknown")
false

valid_credit_card(card)

(macro)
@spec valid_credit_card(String.t()) :: boolean()

Guard clause to check if a given credit card type is valid.

Examples

iex> CreditCard.valid_credit_card("amex")
true

iex> CreditCard.valid_credit_card("unknown")
false

validate_credit_card(card)

@spec validate_credit_card(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Validates the given credit_card type and returns {:ok, credit_card} if it is valid, or {:error, "Invalid credit card type"} otherwise.

Examples

iex> CreditCard.validate_credit_card("amex")
{:ok, "amex"}

iex> CreditCard.validate_credit_card("unknown")
{:error, "Invalid credit card type"}

validate_credit_card!(card)

@spec validate_credit_card!(String.t()) :: String.t()

Validates the given credit_card type and returns it if it is valid. Raises an ArgumentError if the credit_card type is invalid.

Examples

iex> CreditCard.validate_credit_card!("visa")
"visa"

iex> CreditCard.validate_credit_card!("unknown")
** (ArgumentError) Invalid credit card type: "unknown"