Documentation ¶
Overview ¶
Package vat helps you deal with European VAT in Go.
It offers VAT number validation using the VIES VAT validation API & VAT rates retrieval using jsonvat.com
Validate a VAT number
validity := vat.ValidateNumber("NL123456789B01")
Get VAT rate that is currently in effect for a given country
c, _ := vat.GetCountryRates("NL") r, _ := c.GetRate("standard")
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidCountryCode = errors.New("vat: unknown country code")
ErrInvalidCountryCode will be returned when calling GetCountryRates with an invalid country code
var ErrInvalidRateLevel = errors.New("vat: unknown rate level")
ErrInvalidRateLevel will be returned when getting wrong rate level
var ErrInvalidVATNumber = errors.New("vat: vat number is invalid")
ErrInvalidVATNumber will be returned when an invalid VAT number is passed to a function that validates existence.
ErrServiceUnavailable will be returned when VIES VAT validation API or jsonvat.com is unreachable.
var ServiceTimeout = 10
ServiceTimeout indicates the number of seconds before a service request times out.
Functions ¶
func ValidateNumber ¶
ValidateNumber validates a VAT number by both format and existence. The existence check uses the VIES VAT validation SOAP API and will only run when format validation passes.
Example ¶
vatNumber := "IE6388047V" valid, _ := ValidateNumber(vatNumber) fmt.Printf("Is %s valid: %t", vatNumber, valid)
Output: Is IE6388047V valid: true
func ValidateNumberExistence ¶
ValidateNumberExistence validates a VAT number by its existence using the VIES VAT API (using SOAP)
func ValidateNumberFormat ¶
ValidateNumberFormat validates a VAT number by its format.
Types ¶
type CountryRates ¶
type CountryRates struct { Name string `json:"name"` Code string `json:"code"` CountryCode string `json:"country_code"` Periods []RatePeriod }
CountryRates holds the various differing VAT rate periods for a given country
func FetchRates ¶
func FetchRates() ([]CountryRates, error)
FetchRates fetches the latest VAT rates from jsonvat.com and updates the in-memory rates
func GetCountryRates ¶
func GetCountryRates(countryCode string) (CountryRates, error)
GetCountryRates gets the CountryRates struct for a country by its ISO-3166-1-alpha2 country code.
func (*CountryRates) GetRate ¶
func (cr *CountryRates) GetRate(level string) (float32, error)
GetRate returns the currently active rate
Example ¶
c, _ := GetCountryRates("NL") r, _ := c.GetRate("standard") fmt.Printf("Standard VAT rate for %s is %.2f", c.Name, r)
Output: Standard VAT rate for Netherlands is 21.00