vat

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: MIT Imports: 4 Imported by: 0

README

Build Status

vat

VAT matching and validation in Go

Usage

See http://godoc.org/github.com/Teamwork/vat for usage and examples

Documentation

Overview

Package vat validates and sanitizes VAT numbers.

It accepts the current formats listed here: https://en.wikipedia.org/wiki/VAT_identification_number

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustValidate

func MustValidate(vat string) (*vatapi.VATresponse, error)

MustValidate provides a real-time lookup of the europa API to ensure that the VAT number provided is currently active. Unfortunately the API is not entirely reliable so a retry should be issued on error. The default timeout for the API call is 10 seconds. Unlike stdlib functions prefixed with `Must`, this function does not panic on error, but more signifies the importance of a true real-time lookup.

func Sanitize

func Sanitize(vat string) (string, error)

Sanitize removes whitespace and invalid characters from a VAT number (often provided by end users to "enhance readabilty"). After replacement the VAT number is validated. If the VAT validation fails ErrInvalidVat will be returned. All (and only) spaces, dashes and underscores will be removed.

func Valid

func Valid(vat string) bool

Valid checks a VAT number against all known EU regions formats. Only exact matches (start to end of string) will be matched, though the VAT will have space trimmed from each end before attempting a match. Note: Valid provides a loose match as exact algoritms for each country are technically not published and even if they were you cannot guarantee that the number has actually been issued. If a guarantee is needed, use MustValidate

func ValidInRegion

func ValidInRegion(vat, region string) (bool, error)

ValidInRegion is like Valid except it checks only validates against a (case insensitive) specific EU region. Providing a blank EU region will run a check against the default EU VAT format. If the requested region is invalid then the validation will fail and ErrInvalidVATRegion will be returned. See https://en.wikipedia.org/wiki/VAT_identification_number for more information on formats and region prefixes.

Types

type ErrInvalidVAT

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

ErrInvalidVAT implements the error interface and is returned when Sanitize fails to clean and validate a VAT number

func (ErrInvalidVAT) Error

func (e ErrInvalidVAT) Error() string

type ErrInvalidVATRegion

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

ErrInvalidVATRegion implements the error interface and is returned when ValidInRegion fails to find the requested region. Blank "" regions will not fail the region lookup

func (ErrInvalidVATRegion) Error

func (e ErrInvalidVATRegion) Error() string

Jump to

Keyboard shortcuts

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