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 ErrCountryNotFound = errors.New("vat: country not found")
ErrCountryNotFound indicates that this package could not find a country matching the VAT number prefix.
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 { 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 ibericode/vat-rates 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.
type RatePeriod ¶
RatePeriod represents a time and the various activate rates at that time.