vat

package module
v0.0.0-...-2a46385 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: Unlicense Imports: 9 Imported by: 4

README

Golang VAT number validation

Build Status GoDoc

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/mattes/vat

Usage with Go

import "github.com/mattes/vat"

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

// or ...
valid, err := vat.IsValidVAT("IE6388047V")

// increase timeout (default 10 seconds)
vat.Timeout = 10

// get VAT rates for EU countries
rate, ok := vat.StandardRate("DE")

// get applicable tax and if reverse charge is allowed,
// depending on VAT number and country
// (use at own risk!)
rate, reverseCharge, err := GetApplicableTax("DE", "")
rate, reverseCharge, err := GetApplicableTax("IE", "IE6388047V")
rate, reverseCharge, err := GetApplicableTax("CH", "")

Usage via Console

There is a small cli included in this package.

Install with go get -u github.com/mattes/vat/vat-check

$ vat-check IE6388047V

Request date: 2015-03-06 00:00:00 +0100 CET
  VAT number: 6388047V
     Country: IE
        Name: GOOGLE IRELAND LIMITED
     Address: 3RD FLOOR ,GORDON HOUSE ,BARROW STREET ,DUBLIN 4

Success: The VAT number is valid!

Exit code is 0 if VAT number is valid.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrVATnumberNotValid     = errors.New("VAT number is not valid.")
	ErrVATserviceUnreachable = errors.New("VAT number validation service is offline.")
	ErrVATserviceError       = "VAT number validation service returns an error : "
)
View Source
var Timeout = 10 // seconds

Functions

func Countries

func Countries() []string

Countries returns a list of all EU countries

func GetApplicableTax

func GetApplicableTax(countryCode, vatNumber string) (taxRate float64, reverseCharge bool, err error)

GetApplicableTax is a convenience func for GetApplicableTaxAtDate(...)

func GetApplicableTaxAtDate

func GetApplicableTaxAtDate(countryCode, vatNumber string, date time.Time) (taxRate float64, reverseCharge bool, err error)

GetApplicableTaxAtDate returns taxRate and if reverseCharge is applicable You should check the vatNumber with IsValidVAT(vatNumber) before passing a vatNumber to this function.

func IsEUCountry

func IsEUCountry(countryCode string) bool

IsEUCountry returns true if countryCode is EU country

func IsValidVAT

func IsValidVAT(vatNumber string) (bool, error)

IsValid returns true if vat number is correct

func StandardRate

func StandardRate(countryCode string) (rate float64, ok bool)

StandardRate returns VAT rate in EU country at time.Now()

func StandardRateAtDate

func StandardRateAtDate(countryCode string, date time.Time) (rate float64, ok bool)

StandardRateAtDate returns VAT rate in EU country at given date

Types

type Rates

type Rates struct {
	Since     time.Time
	Countries map[string]float64
}

type VATresponse

type VATresponse struct {
	CountryCode string
	VATnumber   string
	RequestDate time.Time
	Valid       bool
	Name        string
	Address     string
}

func CheckVAT

func CheckVAT(vatNumber string) (*VATresponse, error)

Check returns *VATresponse for vat number

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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