Documentation
¶
Overview ¶
Package ibanchecker is the official Go client for the ibanchecker.cash IBAN validation API.
Validate IBANs across 92 countries, validate up to 100 IBANs per request, extract IBANs from free text, look up country format specifications and resolve SWIFT/BIC codes.
Every method except CountryFormat needs an API key, LookupBIC included; without one the API answers HTTP 401, returned as ErrAuthentication. A free key covers 100 requests a month and arrives by email in seconds; request it at https://ibanchecker.cash/api-docs, and see https://ibanchecker.cash/pricing for paid plans.
What a key can call follows its plan. A free key covers Validate only; ValidateBulk and LookupBIC need the Basic plan or above (Basic, Starter, Growth, Enterprise), and Extract the Growth plan or above (Growth, Enterprise). A key whose email address has a verified account at https://ibanchecker.cash/dashboard can try the methods its plan lacks: ValidateBulk with up to 10 IBANs per call, LookupBIC, and Extract with up to 5,000 characters per call. Outside the trial, a call the key's plan does not include gets HTTP 403 with the code "PLAN_REQUIRED"; this client has no sentinel for 403, so the *Error unwraps to ErrAPI.
Validate and LookupBIC count one request against the monthly quota, ValidateBulk one per IBAN in the call, and Extract one per IBAN found (at least one per call). CountryFormat works without a key, limited to 100 requests an hour per IP.
client := ibanchecker.New(os.Getenv("IBANCHECKER_API_KEY"))
result, err := client.Validate(context.Background(), "DE89 3704 0044 0532 0130 00")
if err != nil {
log.Fatal(err)
}
if result.Valid {
fmt.Println(result.BankName, result.BIC)
}
A malformed IBAN is not an error: Validate returns a ValidationResult with Valid false and an Error plus ErrorCode explaining why. Errors are returned for transport, authentication, plan, quota and server-side problems only.
Index ¶
- Constants
- Variables
- type BankRecord
- type BatchResult
- type BbanField
- type Client
- func (c *Client) CountryFormat(ctx context.Context, country string) (*FormatSpec, error)
- func (c *Client) Extract(ctx context.Context, text string) (*BatchResult, error)
- func (c *Client) LookupBIC(ctx context.Context, bic string) (*BankRecord, error)
- func (c *Client) Validate(ctx context.Context, iban string) (*ValidationResult, error)
- func (c *Client) ValidateBulk(ctx context.Context, ibans []string) (*BatchResult, error)
- type Error
- type FormatSpec
- type Option
- type ValidationResult
Constants ¶
const DefaultBaseURL = "https://ibanchecker.cash/api/v1"
DefaultBaseURL is the production API.
const Version = "0.1.2"
Version goes out in the User-Agent header.
Variables ¶
var ( // ErrBadRequest is returned for HTTP 400: the request was malformed, or a // trial call went over the trial size (Code "TOO_MANY_IBANS" for // ValidateBulk, "TEXT_TOO_LONG" for Extract). ErrBadRequest = errors.New("bad request") // ErrAuthentication is returned for HTTP 401: the API key is missing, // invalid or inactive. Every method except CountryFormat needs a key, so // a LookupBIC call without one also gets it from the API's 401. ErrAuthentication = errors.New("authentication failed") // ErrNotFound is returned for HTTP 404: no such country code or BIC. ErrNotFound = errors.New("not found") // ErrRateLimit is returned for HTTP 429: the key's monthly quota was // used up, or the call costs more than the requests left this month // (Code "QUOTA_EXCEEDED"; ValidateBulk counts one request per IBAN and // Extract one per IBAN found), or a CountryFormat call without a key went // over 100 requests an hour per IP (Code "RATE_LIMIT_EXCEEDED"). The // hourly limit applies to CountryFormat only. ErrRateLimit = errors.New("rate limited") // ErrAPI is returned for any other error status, and for a response body // that could not be read as JSON. That includes HTTP 403 with Code // "PLAN_REQUIRED", a call the key's plan does not include; Response then // carries "required_plan" ("basic" or "growth") and "upgrade_url". ErrAPI = errors.New("api error") // ErrTransport is returned when the request never reached the API: DNS, // TLS, connection or timeout. ErrTransport = errors.New("transport error") )
Sentinel errors for the failures a caller usually branches on. Compare them with errors.Is; reach for errors.As and *Error when you need the status, the machine-readable code or the decoded body.
Functions ¶
This section is empty.
Types ¶
type BankRecord ¶
type BankRecord struct {
BIC string `json:"bic"`
BIC8 string `json:"bic8"`
BankCode string `json:"bank_code"`
CountryCode string `json:"country_code"`
LocationCode string `json:"location_code"`
BranchCode string `json:"branch_code"`
BankName string `json:"bank_name"`
City string `json:"city"`
CountryName string `json:"country_name"`
SEPA *bool `json:"sepa"`
Type string `json:"type"`
Status string `json:"status"`
// Raw is the untouched response body.
Raw map[string]any `json:"-"`
}
BankRecord is the institution behind a SWIFT/BIC code.
func (*BankRecord) UnmarshalJSON ¶
func (b *BankRecord) UnmarshalJSON(data []byte) error
type BatchResult ¶
type BatchResult struct {
Count int `json:"count"`
ValidCount int `json:"valid_count"`
InvalidCount int `json:"invalid_count"`
Results []ValidationResult `json:"results"`
// Raw is the untouched response body.
Raw map[string]any `json:"-"`
}
BatchResult is the result of a bulk validation or a text extraction. Results come back in the same order as the input.
func (*BatchResult) UnmarshalJSON ¶
func (b *BatchResult) UnmarshalJSON(data []byte) error
type BbanField ¶
type BbanField struct {
Label string `json:"label"`
Length int `json:"length"`
Type string `json:"type"`
Description string `json:"description"`
// Raw is the untouched field object.
Raw map[string]any `json:"-"`
}
BbanField is one segment of a country's BBAN, in the order it appears in the IBAN.
func (*BbanField) UnmarshalJSON ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the ibanchecker.cash API. The zero value is not usable; call New. A Client is safe for concurrent use by multiple goroutines.
func New ¶
New returns a Client. Every method except CountryFormat needs an API key. An empty apiKey is accepted, but then only CountryFormat succeeds, limited to 100 requests an hour per IP.
func (*Client) CountryFormat ¶
CountryFormat returns the IBAN format specification for an ISO 3166-1 alpha-2 country code, for example "DE".
It is the only method that works without a key, limited to 100 requests an hour per IP; beyond that the API answers HTTP 429 with the code "RATE_LIMIT_EXCEEDED", returned as ErrRateLimit.
func (*Client) Extract ¶
Extract scans free text (emails, invoices) for IBAN-shaped strings and validates each candidate. Up to 50,000 characters per request.
It needs a key on the Growth plan or above; a key with a verified account can try it with up to 5,000 characters per call, and over that the API answers HTTP 400 with the code "TEXT_TOO_LONG". Each IBAN found counts one request, and a call counts at least one.
func (*Client) LookupBIC ¶
LookupBIC resolves an 8 or 11 character ISO 9362 BIC to a bank record.
It needs an API key: without one the API answers HTTP 401, returned as ErrAuthentication. The key needs the Basic plan or above, or a verified account for the trial; otherwise the API answers HTTP 403 with the code "PLAN_REQUIRED", returned as an *Error that unwraps to ErrAPI. Each call counts one request.
func (*Client) Validate ¶
Validate validates a single IBAN. Any key can call it, the free one included, and each call counts one request.
A malformed IBAN is not an error: the result comes back with Valid false and an Error plus ErrorCode explaining why.
func (*Client) ValidateBulk ¶
ValidateBulk validates up to 100 IBANs in one request. Results come back in the same order as the input.
It needs a key on the Basic plan or above; a key with a verified account can try it with up to 10 IBANs per call, and over that the API answers HTTP 400 with the code "TOO_MANY_IBANS". Each IBAN in the call counts one request.
type Error ¶
type Error struct {
// Status is the HTTP status, or 0 when the request never completed.
Status int
// Code is the machine-readable code from the API body, for example
// "BIC_NOT_FOUND". Empty when the API sent none.
Code string
// Message is the human-readable reason.
Message string
// Response is the decoded response body, when the API sent one.
Response map[string]any
// contains filtered or unexported fields
}
Error carries everything the API said about a failure.
A malformed IBAN is not an error: Validate returns a ValidationResult with Valid false. These are returned for transport, authentication, plan, quota and server-side problems only.
type FormatSpec ¶
type FormatSpec struct {
CountryCode string `json:"country_code"`
CountryName string `json:"country_name"`
Length int `json:"length"`
Currency string `json:"currency"`
CurrencyName string `json:"currency_name"`
SEPA *bool `json:"sepa"`
SWIFT *bool `json:"swift"`
FormatString string `json:"format_string"`
Example string `json:"example"`
BbanFields []BbanField `json:"bban_fields"`
// Raw is the untouched response body.
Raw map[string]any `json:"-"`
}
FormatSpec is the IBAN format specification for one country.
func (*FormatSpec) UnmarshalJSON ¶
func (s *FormatSpec) UnmarshalJSON(data []byte) error
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithBaseURL ¶
WithBaseURL points the client at a different host. Any trailing slash is trimmed.
func WithHTTPClient ¶
WithHTTPClient replaces the HTTP client, which is how an application routes these calls through its own stack, and how the tests run against an httptest server. It also overrides WithTimeout and the redirect policy below, so set both on the client you pass in.
func WithTimeout ¶
WithTimeout sets the timeout on the default HTTP client.
type ValidationResult ¶
type ValidationResult struct {
Valid bool `json:"valid"`
IBAN string `json:"iban"`
Formatted string `json:"formatted"`
CheckDigits string `json:"check_digits"`
BBAN string `json:"bban"`
Country string `json:"country"`
CountryName string `json:"country_name"`
BankName string `json:"bank_name"`
BankType string `json:"bank_type"`
BIC string `json:"bic"`
BankCity string `json:"bank_city"`
BankCode string `json:"bank_code"`
BranchCode string `json:"branch_code"`
AccountNumber string `json:"account_number"`
// NationalCheckValid reports a domestic account check digit run on top of
// the ISO 13616 checksum, such as Germany's per-bank Pruefziffer or the UK
// sort-code and account modulus check. It is advisory: an IBAN with Valid
// true is a valid IBAN whatever this says. False usually means a
// transcription error in the account number. Nil where the country has no
// such scheme.
NationalCheckValid *bool `json:"national_check_valid"`
Currency string `json:"currency"`
CurrencyName string `json:"currency_name"`
TransferType string `json:"transfer_type"`
// SEPA reports whether the IBAN's country is in the SEPA zone. Nil when
// the API did not say.
SEPA *bool `json:"sepa"`
Flag string `json:"flag"`
// Error and ErrorCode explain why Valid is false.
Error string `json:"error"`
ErrorCode string `json:"error_code"`
// Raw is the untouched response body, so a field added to the API later is
// reachable without waiting for a client release.
Raw map[string]any `json:"-"`
}
ValidationResult is the result of validating one IBAN.
Valid is the primary flag. When it is false only IBAN, Formatted, Country, CountryName, Error and ErrorCode are populated.
func (*ValidationResult) UnmarshalJSON ¶
func (r *ValidationResult) UnmarshalJSON(data []byte) error