Documentation
¶
Index ¶
- Constants
- func FormatIBAN(iban string) (string, error)
- func FormatPaymentCard(number, issuer string) (string, error)
- func GetABARTNCheckDigit(aba string) (string, string, error)
- func GetCountryConfiguration(countryCode string) (*configuration, error)
- func GetIBANCheckDigits(iban string) (string, string, error)
- func GetPaymentCardCheckDigits(number string) (string, string, error)
- func GetPaymentCardConfiguration(issuer string) (*paymentCardConfiguration, error)
- func IsABARTNValid(aba string) error
- func IsIBANValid(iban string) error
- func MatchPaymentCard(number string, issuers ...string) ([]string, error)
- func PrintFormatIBAN(iban string) (string, error)
- func SplitABARTN(aba string) ([]string, []string, error)
- func SplitIBAN(iban string) ([]string, []string, error)
Examples ¶
Constants ¶
const ( // ErrIBANTooshort is the error when an IBAN is too short for the validation process ErrIBANTooshort = mimirError("IBAN is too short") // ErrIBANIncorrectLength is the error when a IBAN does not have the required length ErrIBANIncorrectLength = mimirError("IBAN incorrect length") // ErrIBANInvalidChecksum is the error when a IBAN is invalid ErrIBANInvalidChecksum = mimirError("IBAN invalid checksum") // ErrCountryCodeDoesNotExist is the error when you lookup for a country code that does not exists ErrCountryCodeDoesNotExist = mimirError("Country Code does not exist") // ErrABARTNInvalidLength is the error when an ABA Routing Number is too short the the validation process ErrABARTNInvalidLength = mimirError("ABA is too short. 9 digits is expected") // ErrABAInvalidChecksum is the error when a ABA Routing Number is invalid ErrABAInvalidChecksum = mimirError("ABA Routing Number invalid checksum") // ErrPaymentCardInvalidChecksum is the error when a Payment card number is invalid ErrPaymentCardDoesNotMatchAnyIssuer = mimirError("Payment card does not match any issuer") // ErrPaymentCardTooShort is the error when a Payment card number is too short for the validation process ErrPaymentCardTooShort = mimirError("Payment card number is too short") // ErrIssuerDoesNotExist is the error when you lookup for an issuer that does not exists ErrIssuerDoesNotExist = mimirError("Issuer does not exist") // ErrStructureNotFound is the error when you try to format a payment card which does not have supported structure ErrStructureNotFound = mimirError("Structure not found") )
Errors
const ( AccountNumberIBANDigitKey = "a" // alphanumeric NationalBankCodeIBANDigitKey = "b" // numeric CountryCodeIBANDigitKey = "c" // alphabetic CheckIBANDigitKey = "k" // checksum NationalIdentificationNumberIBANDigitKey = "i" CurrencyIBANDigitKey = "m" // alphanumeric AccountHolderIBANDigitKey = "n" ReserveNumberIBANDigitKey = "o" // always 0 BranchCodeIBANDigitKey = "s" // counter code AccountTypeIBANDigitKey = "t" SWIFTBICCodeIBANDigitKey = "w" // alphanumeric NationalCheckIBANDigitKey = "x" // numeric )
IBAN - Structure digit keys
const ( FederalReserveRoutingSymbolABADigitKey = "f" // numeric ABAInstitutionIdentifierDigitKey = "a" // numeric CheckABADigitKey = "k" // checksum // numeric )
ABA Routing Number - Structure digit keys
const ( AmericanExpress = "American Express" ChinaUnionPay = "China UnionPay" DinnerClubInternational = "Dinner Club International" DinnerClubCarteBlanche = "Dinner Club Carte Blanche" DinnerClub = "Dinner Club" Discover = "Discover" Rupay = "Rupay" InterPayment = "InterPayment" InstaPayment = "InstaPayment" JCB = "JCB" Maestro = "Maestro" Dankort = "Dankort" MIR = "MIR" Mastercard = "Mastercard" Visa = "Visa" UATP = "UATP" )
Major industry identifier name / Issuer keys
Variables ¶
This section is empty.
Functions ¶
func FormatIBAN ¶ added in v0.5.0
FormatIBAN formats the given IBAN with the different parts that are defined in its structure.
func FormatPaymentCard ¶ added in v0.9.0
FormatPaymentCard formats the given payment card based on the structure of the issuer.
func GetABARTNCheckDigit ¶ added in v0.7.0
GetABARTNCheckDigit compute the check digits from a given ABA Routing Number. Returns the computed digit and the ABA updated with the check digits or an error if something goes wrong. The ABA must contains 9 digits but the last one will ignored. It's possible to use this function by adding an extra 0 at the end if the ABA is not a valid one.
Example ¶
fmt.Println(GetABARTNCheckDigit("111000020")) fmt.Println(GetABARTNCheckDigit("111000025"))
Output: 5 111000025 <nil> 5 111000025 <nil>
func GetCountryConfiguration ¶ added in v0.1.1
GetCountryConfiguration returns ISO 13616-Compliant IBAN Formats from a given country code If the countryCode does not exist in the list, returns an error `ErrCountryCodeDoesNotExist`
func GetIBANCheckDigits ¶ added in v0.6.0
GetIBANCheckDigits compute the check digits from a given IBAN. Returns the computed digits, the IBAN set with the check digits or an error if something goes wrong.
Example ¶
fmt.Println(GetIBANCheckDigits("FR1420041010050500013M02606")) fmt.Println(GetIBANCheckDigits("FR0020041010050500013M02606"))
Output: 14 FR1420041010050500013M02606 <nil> 14 FR1420041010050500013M02606 <nil>
func GetPaymentCardCheckDigits ¶ added in v0.8.0
GetPaymentCardCheckDigits compute the check digits from a given payment card number. If you need to compute the check digit for 1234, please add an extra 0 at the end, otherwise, it's going to compute the check digit for 123. The last digit is ignored. Returns the computed digit, the payment card number set with the check digit or an error if something goes wrong.
Example ¶
fmt.Println(GetPaymentCardCheckDigits("12340")) fmt.Println(GetPaymentCardCheckDigits("1234"))
Output: 4 12344 <nil> 6 1236 <nil>
func GetPaymentCardConfiguration ¶ added in v0.8.0
GetPaymentCardConfiguration returns informations about the payment cards from a given issuer name If the countryCode does not exist in the list, returns an error `ErrCountryCodeDoesNotExist`
func IsABARTNValid ¶ added in v0.7.0
IsABARTNValid checks if the given ABA Routing Number is valid.
func IsIBANValid ¶
IsIBANValid checks if the given IBAN is valid based on the country its belong to.
Example ¶
fmt.Println(IsIBANValid("FR1420041010050500013M02606")) fmt.Println(IsIBANValid("FR1420041010050500013M02605"))
Output: <nil> IBAN invalid checksum
func MatchPaymentCard ¶ added in v0.8.0
MatchPaymentCard returns a list of the issuers that match the given number. If the issuers list has been filled with valid issuer keys, it will only check the number for those ones. So it can be useful when it comes to check if a payment card number belongs to a specific issuer. It can also return an error if something goes wrong or if the number does not match any known issuer.
Example ¶
fmt.Println(MatchPaymentCard("4012888888881881")) fmt.Println(MatchPaymentCard("4012888888881881", Visa)) fmt.Println(MatchPaymentCard("4012888888881881", Mastercard)) fmt.Println(MatchPaymentCard("30037174022893"))
Output: [Visa] <nil> [Visa] <nil> [] Payment card does not match any issuer [Dinner Club Carte Blanche Dinner Club International] <nil>
func PrintFormatIBAN ¶ added in v0.2.0
PrintFormatIBAN formats the given IBAN based on the regular way to print it depending the country. It will use the PrintFormat of the configuration to insure the result.
func SplitABARTN ¶ added in v0.7.0
SplitABARTN splits a given valid ABA Routing Number depending its structure. It returns a list of digit keys and a list that contains each part of the structure or an error if something went wrong.
Types ¶
This section is empty.