goiban

package module
v0.0.0-...-3d469fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2019 License: MIT Imports: 11 Imported by: 0

README

goiban

Goiban implements functions for validating international bank account numbers using GO. You may freely use this code. Used at http://openiban.com .

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SELECT_BIC                   = "SELECT bic FROM BANK_DATA WHERE bankcode = ? AND country = ?;"
	SELECT_BIC_STMT              *sql.Stmt
	SELECT_BANK_INFORMATION      = "SELECT bankcode, name, zip, city, bic FROM BANK_DATA WHERE bankcode = ? AND country = ?;"
	SELECT_BANK_INFORMATION_STMT *sql.Stmt
)
View Source
var (
	COUNTRY_CODE_TO_BANK_CODE_LENGTH = map[string]int{
		"DE": 8,
		"BE": 3,
		"NL": 4,
		"LU": 3,
		"CH": 5,
		"AT": 5,
		"LI": 5,
	}

	COUNTRY_CODE_TO_LENGTH_MAP = map[string]int{
		"LV": 21,
		"LU": 20,
		"LT": 20,
		"HR": 21,
		"RO": 24,
		"DZ": 24,
		"VG": 24,
		"HU": 28,
		"MG": 27,
		"DO": 28,
		"ME": 22,
		"MK": 19,
		"ML": 28,
		"DE": 22,
		"MC": 27,
		"MD": 24,
		"DK": 18,
		"IE": 22,
		"AT": 20,
		"MU": 30,
		"IL": 23,
		"MZ": 25,
		"IR": 26,
		"AZ": 28,
		"IS": 26,
		"IT": 27,
		"MR": 27,
		"BA": 20,
		"MT": 31,
		"PT": 25,
		"AD": 24,
		"UA": 29,
		"ES": 24,
		"AE": 23,
		"NL": 18,
		"PS": 29,
		"EG": 27,
		"AL": 28,
		"EE": 20,
		"AO": 25,
		"GE": 22,
		"BR": 29,
		"GA": 27,
		"GB": 22,
		"TN": 24,
		"TR": 26,
		"NO": 15,
		"BF": 27,
		"FR": 27,
		"BG": 22,
		"BH": 22,
		"BI": 16,
		"FO": 18,
		"BE": 16,
		"BJ": 28,
		"FI": 18,
		"CZ": 24,
		"CY": 28,
		"SE": 24,
		"CV": 25,
		"SI": 19,
		"KW": 30,
		"SK": 24,
		"SN": 28,
		"KZ": 20,
		"SM": 27,
		"CI": 28,
		"PL": 28,
		"RS": 22,
		"GT": 28,
		"CG": 27,
		"LB": 28,
		"CH": 21,
		"GR": 27,
		"PK": 24,
		"LI": 21,
		"CR": 22,
		"GL": 18,
		"CM": 27,
		"GI": 23,
		"SA": 24,
	}
)
View Source
var (
	COUNTRY_TO_CC_MAP = map[string]string{
		"Albania":                   "AL",
		"Algeria":                   "DZ",
		"Andorra":                   "AD",
		"Angola":                    "AO",
		"Austria":                   "AT",
		"Azerbaijan":                "AZ",
		"Bahrain":                   "BH",
		"Belgium":                   "BE",
		"Benin":                     "BJ",
		"Bosnia and Herzegovina":    "BA",
		"Brazil":                    "BR",
		"British Virgin Islands":    "VG",
		"Bulgaria":                  "BG",
		"Burkina Faso":              "BF",
		"Burundi":                   "BI",
		"Cameroon":                  "CM",
		"Cape Verde":                "CV",
		"Central African Republic":  "FR",
		"Congo":                     "CG",
		"Costa Rica":                "CR",
		"Croatia":                   "HR",
		"Cyprus":                    "CY",
		"Czech Republic":            "CZ",
		"Denmark":                   "DK",
		"Dominican Republic":        "DO",
		"Egypt":                     "EG",
		"Estonia":                   "EE",
		"Faroe Islands":             "FO",
		"Finland":                   "FI",
		"France":                    "FR",
		"French Guiana":             "FR",
		"French Polynesia":          "FR",
		"Gabon":                     "GA",
		"Georgia":                   "GE",
		"Germany":                   "DE",
		"Gibraltar":                 "GI",
		"Greece":                    "GR",
		"Greenland":                 "GL",
		"Guadeloupe":                "FR",
		"Guatemala":                 "GT",
		"Guernsey":                  "GB",
		"Hungary":                   "HU",
		"Iceland":                   "IS",
		"Iran":                      "IR",
		"Ireland":                   "IE",
		"Isle of Man":               "GB",
		"Israel":                    "IL",
		"Italy":                     "IT",
		"Ivory Coast":               "CI",
		"Jersey":                    "GB",
		"Kazakhstan":                "KZ",
		"Kuwait":                    "KW",
		"Latvia":                    "LV",
		"Lebanon":                   "LB",
		"Liechtenstein":             "LI",
		"Lithuania":                 "LT",
		"Luxembourg":                "LU",
		"Macedonia":                 "MK",
		"Madagascar":                "MG",
		"Mali":                      "ML",
		"Malta":                     "MT",
		"Martinique":                "FR",
		"Mauritania":                "MR",
		"Mauritius":                 "MU",
		"Moldova":                   "MD",
		"Monaco":                    "MC",
		"Montenegro":                "ME",
		"Mozambique":                "MZ",
		"Netherlands":               "NL",
		"New Caledonia":             "FR",
		"Norway":                    "NO",
		"Pakistan":                  "PK",
		"Palestine, State of":       "PS",
		"Poland":                    "PL",
		"Portugal":                  "PT",
		"Romania":                   "RO",
		"Réunion":                   "FR",
		"Saint-Pierre and Miquelon": "FR",
		"San Marino":                "SM",
		"Sao Tome and Principe":     "PT",
		"Saudi Arabia":              "SA",
		"Senegal":                   "SN",
		"Serbia":                    "RS",
		"Slovakia":                  "SK",
		"Slovenia":                  "SI",
		"Spain":                     "ES",
		"Sweden":                    "SE",
		"Switzerland":               "CH",
		"Tunisia":                   "TN",
		"Turkey":                    "TR",
		"Ukraine":                   "UA",
		"United Arab Emirates":      "AE",
		"United Kingdom":            "GB",
		"Wallis and Futuna":         "FR",
	}
)

Functions

func ExtractCountryCode

func ExtractCountryCode(val string) string

Returns a country code from a string value representing an IBAN.

Can return an empty string if value is invalid.

func GetBankInformationByCountryAndBankCodeFromDb

func GetBankInformationByCountryAndBankCodeFromDb(countryCode string, bankCode string, repo data.BankDataRepository) *data.BankInfo

func ReadFileToEntries

func ReadFileToEntries(path string, t interface{}, out chan interface{})

Types

type Iban

type Iban struct {
	// contains filtered or unexported fields
}

describes the structure of an IBAN

func ParseToIban

func ParseToIban(val string) *Iban

* Returns a pointer to an Iban instance or nil on structural errors.

func (*Iban) GetCountryCode

func (i *Iban) GetCountryCode() string

func (*Iban) Validate

func (iban *Iban) Validate() *ValidationResult

Returns a pointer to a goiban.ValidationResult.

type ParserResult

type ParserResult struct {
	Valid   bool   `json:"valid"`
	Message string `json:"message"`
	Data    string `json:"data"`
}

Represents the result of a parsing attempt.

func CalculateIBAN

func CalculateIBAN(countryCode string, bankCode string, account string) *ParserResult

CalculateIBAN returns a parser result with an IBAN

func IsParseable

func IsParseable(val string) *ParserResult

Returns true if the string val can be parsed to an Iban Struct.

func NewParserResult

func NewParserResult(valid bool, message string, data string) *ParserResult

Factory method

type ValidationResult

type ValidationResult struct {
	Valid        bool            `json:"valid"`
	Messages     []string        `json:"messages"`
	Iban         string          `json:"iban"`
	BankData     data.BankInfo   `json:"bankData"`
	CheckResults map[string]bool `json:"checkResults"`
}

Represents the result of an IBAN validation.

func GetBic

func GetBic(iban *Iban, intermediateResult *ValidationResult, repo data.BankDataRepository) *ValidationResult

func NewValidationResult

func NewValidationResult(valid bool, message string, iban string) *ValidationResult

Factory method

func ValidateBankCode

func ValidateBankCode(iban *Iban, intermediateResult *ValidationResult, repo data.BankDataRepository) *ValidationResult

Directories

Path Synopsis
The MIT License (MIT) Copyright (c) 2015 Chris Grieger Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The MIT License (MIT) Copyright (c) 2015 Chris Grieger Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL