Skip to content
Go package for dealing with EU VAT. Does VAT number validation & rates retrieval.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Added CH & fixed vats Jun 11, 2018
LICENSE first commit Jun 18, 2016
README.md add 2nd return value to README example Apr 22, 2017
numbers.go Added CH & fixed vats Jun 11, 2018
numbers_test.go Added CH & fixed vats Jun 11, 2018
rates.go fix date format for when vat rates change halfway through the year Sep 10, 2018
rates_test.go Fixed vat rate Jun 11, 2018
vat.go

README.md

Package vat

Go Report Card GoDoc MIT licensed

Package for validating VAT numbers & retrieving VAT rates in Go.

Installation

Use go get.

go get github.com/dannyvankooten/vat

Then import the package into your own code.

import "github.com/dannyvankooten/vat"

Usage

Validating VAT numbers

VAT numbers can be validated by format, existence or both. VAT numbers are looked up using the VIES VAT validation API.

package main

import "github.com/dannyvankooten/vat"

func main() {
  // Validate number by format + existence
  validity, err := vat.ValidateNumber("NL123456789B01")

  // Validate number format
  validity, err := vat.ValidateNumberFormat("NL123456789B01")

  // Validate number existence
  validity, err := vat.ValidateNumberExistence("NL123456789B01")
}

Retrieving VAT rates

To get VAT rate periods for a country, first get a CountryRates struct using the country's ISO-3166-1-alpha2 code.

You can get the rate that is currently in effect using the GetRate function.

package main

import (
  "fmt"
  "github.com/dannyvankooten/vat"
)

func main() {
  c, err := vat.GetCountryRates("NL")
  r, err := c.GetRate("standard")

  fmt.Printf("Standard VAT rate for NL is %.2f", r)
  // Output: Standard VAT rate for NL is 21.00
}

License

MIT licensed. See the LICENSE file for details.

You can’t perform that action at this time.