vat

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: MIT Imports: 11 Imported by: 15

README

Golang VAT number validation

Uses the official VIES VAT number validation SOAP web service to validate european VAT numbers.

Unfortunately their service is super unreliable.

Install

go get -u github.com/goenning/vat

Usage with Go

import "github.com/goenning/vat"

response, err := vat.Query("IE6388047V")
if err != nil {
  // do sth with err
}
if response.IsValid {
    fmt.Println(response.Name)
}

Retry

Because VIES service is very unreliable, this package will retry every failed request for a maximum of 4 times using an exponential backoff strategy.

Greece and United Kingdom

This package always assume that country code is on ISO 3166 list.

Greece's ISO 3166 country code is GR, but EU uses EL. This package does the conversion so that you don't need to care about EU's country code. Same applies to UK, both ISO and EU uses GB, but this package will always convert UK to GB for safety reasons.

This conversion only happens for the CountryCode field and not VAT Number. So a EL094160738 is a valid VAT number for the GR country.

Fork

This package is a merge of mattes/vat and dannyvankooten/vat, with some refactoring and other features. Thanks!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidVATNumberFormat is returned when given VAT Number is in a invalid format
	ErrInvalidVATNumberFormat = errors.New("vat: invalid VAT number format")
	// ErrServiceUnreachable is returned when we cannot connect to VIES VAT Service
	ErrServiceUnreachable = errors.New("vat: VIES service is unreachable")
	// ErrVIESInvalidInput is returned based on VIES response
	ErrVIESInvalidInput = errors.New("vat: VAT number is invalid")
	// ErrVIESGlobalMaxConcurrentRequest is returned based on VIES response
	ErrVIESGlobalMaxConcurrentRequest = errors.New("vat: the maximum number of global concurrent requests has been reached, try again later")
	// ErrVIESMSMaxConcurrentRequest is returned based on VIES response
	ErrVIESMSMaxConcurrentRequest = errors.New("vat: the maximum number of concurrent requests for this member state has been reached, try again later")
	// ErrVIESServiceUnavailable is returned based on VIES response
	ErrVIESServiceUnavailable = errors.New("vat: an error was encountered either at the network level or the web application level, try again later")
	// ErrVIESMSUnavailable is returned based on VIES response
	ErrVIESMSUnavailable = errors.New("vat: the application at the member state is not replying or not available, try again later")
	// ErrVIESTimeout is returned based on VIES response
	ErrVIESTimeout = errors.New("vat: the application did not receive a reply within the allocated time period, try again later")
)
View Source
var DefaultClient = &http.Client{
	Timeout: 10 * time.Second,
	Transport: &http.Transport{
		DisableKeepAlives: true,
	},
}

DefaultClient is the HTTP Client used to communicate with VIES

Functions

func IsEU

func IsEU(countryCode string) bool

IsEU returns true if given country code is within EU

func ValidateNumberFormat

func ValidateNumberFormat(vatNumber string) (bool, string)

ValidateNumberFormat returns true if given

Types

type Response

type Response struct {
	IsValid     bool
	VATNumber   string
	CountryCode string
	RequestDate time.Time
	Name        string
	Address     string
}

Response is the model returned from VIES query

func Query

func Query(vatNumber string) (*Response, error)

Query VIES service to check if VAT is valid

Jump to

Keyboard shortcuts

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