Go package for dealing with EU VAT. Does VAT number validation & rates retrieval.

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.

Owner
Danny van Kooten
Independent developer, writing open-source code for a living.
Danny van Kooten
Comments
  • Fixes & added CH vat

    Fixes & added CH vat

    • Code style fixes
    • Replaced "" with `` to remove unnecessary escaping
    • Replaced with \d with [0-9] because \d matches "." and makes it easier to read
    • Added CH weird vat no, not supported by ValidateNumberExistence.
    • Sorted test map
    • Fixed RO vat rate, was changed 2017-01-01
  • Fetch vat rates from github.com/ibericode/vat-rates

    Fetch vat rates from github.com/ibericode/vat-rates

    In this pull request the vat rates from https://github.com/ibericode/vat-rates are downloaded because https://github.com/adamcooke/vat-rates is discontinued.

    Some struct fields are removed because there are not present in the API response from ibericode/vat-rates.

    Fixes #9

  • Fix panic when vat validation service (VIES) is down

    Fix panic when vat validation service (VIES) is down

    Hi @dannyvankooten, I was using this library to validate around 5k VAT numbers, when I noticed that VIES was not available during some of those requests, causing the library to throw a panicas follows:

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x1219f94]
    
    goroutine 1 [running]:
    github.com/dannyvankooten/vat.ValidateNumberExistence(0xc42011b3f2, 0xd, 0xc420281d01, 0x0, 0x0)
    	/Users/marceloton/go/src/github.com/dannyvankooten/vat/numbers.go:91 +0x44
    github.com/dannyvankooten/vat.ValidateNumber(0xc42011b3f2, 0xd, 0x2, 0x2, 0x2)
    	/Users/marceloton/go/src/github.com/dannyvankooten/vat/numbers.go:35 +0x84
    main.isValid(0xc42011b3f2, 0xd, 0x2)
    

    The main issue here is that ValidateNumberExistence is always returning r.Valid, but r is the result of checkVAT method, which can be nil in multiple scenarios.

    I didn't add any tests for covering this scenario because the way it is structured it's not super easy to mock that behaviour, but I guess that can be left as a future improvement. What do you think?

  • Add support for getting country specific VAT rates

    Add support for getting country specific VAT rates

    Something like this, spec needs work tho:

    import vat/rates
    
    c := rates.Country("NL")
    c.Rate.Standard // 21
    c.Rate.Reduced // 6
    

    Also see: https://github.com/adamcooke/json-vat

  • let validateNumberFormat return if vatnumer is not EU

    let validateNumberFormat return if vatnumer is not EU

    Is it possible that validateNumberFormat will return err when it cannot find the landcode in patterns? So change:

    pattern, ok := patterns[n[0:2]]
    if !ok {
    	return false, nil
    }
    

    to

    var CountryNotFound = errors.New("countryNotFound")
    
    pattern, ok := patterns[n[0:2]]
    if !ok {
    	return false, CountryNotFound
    }
    
Related tags
Package to easily consume the Dolarpy API in golang.

dolarpy-go Package to easily consume the Dolarpy API in golang. https://github.com/melizeche/dolarPy - by melizeche Install import "github.com/bitebai

Apr 11, 2022
Guess-number-game - Computer thoughts of some integer number, you must guess it with limited number of attempts
Guess-number-game - Computer thoughts of some integer number, you must guess it with limited number of attempts

Guess number game Rules Computer has thought of some integer number. You must guess it, you have numberOfAttempts attempts. How to run Just type in co

Dec 31, 2021
Check the validity of a VAT number

Go VAT Check the validity of a VAT number without any HTTP request. This go library is based on the original jsVAT for JS/TS. The intention of this li

Aug 21, 2022
fuzzer for a single http parameter which checks if the response does/does not contain a certain given string

single http parameter fuzzer DISCLAIMER: ONLY USE THIS PROGRAM ON TARGETS YOU HAVE PERMISSION TO FUZZ! Initially used as a "poor man's" http fuzzer fo

Dec 19, 2021
An idiomatic Go (golang) validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags.

ozzo-validation Description ozzo-validation is a Go package that provides configurable and extensible data validation capabilities. It has the followi

Jan 7, 2023
A Go (golang) package that enhances the standard database/sql package by providing powerful data retrieval methods as well as DB-agnostic query building capabilities.

ozzo-dbx Summary Description Requirements Installation Supported Databases Getting Started Connecting to Database Executing Queries Binding Parameters

Dec 31, 2022
Golang parameter validation, which can replace go-playground/validator, includes ncluding Cross Field, Map, Slice and Array diving, provides readable,flexible, configurable validation.
Golang parameter validation, which can replace go-playground/validator, includes ncluding Cross Field, Map, Slice and Array diving, provides readable,flexible, configurable validation.

Checker 中文版本 Checker is a parameter validation package, can be use in struct/non-struct validation, including cross field validation in struct, elemen

Dec 16, 2022
Simple module for validation inn control number

simple module for validation inn control number

Sep 4, 2022
Go package for dealing with maps, slices, JSON and other data.

Objx Objx - Go package for dealing with maps, slices, JSON and other data. Get started: Install Objx with one line of code, or update it with another

Dec 27, 2022
Go package for dealing with Mantis Bug Tracking tool

BlueMantis is a Go package in development that aim to make the process of sending issues and bugs in Go applications to the Open Source Bug Tracking software MantisBT.

Aug 3, 2021
PiHex Library, written in Go, generates a hexadecimal number sequence in the number Pi in the range from 0 to 10,000,000.

PiHex PiHex Library generates a hexadecimal number sequence in the number Pi in the range from 0 to 1.0e10000000. To calculate using "Bailey-Borwein-P

Nov 18, 2022
A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a proxy.
A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a proxy.

Fake-SMS A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a pr

Dec 31, 2022
MNA - stands for mobile number assignment - a small zero external dependency golang library that is used to identify mobile number assignment in tanzania

MNA - stands for mobile number assignment - a small zero external dependency golang library that is used to identify mobile number assignment in tanzania

Nov 29, 2021
A tool to determine the highest version number that's smaller than a target version number

semver-highest A tool to determine the highest version number that's smaller than a target version number. Installation go install github.com/marten-s

Oct 13, 2021
A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a proxy
A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a proxy

Fake-SMS A simple command line tool using which you can skip phone number based SMS verification by using a temporary phone number that acts like a pr

Dec 31, 2022
Converts a number to its English counterpart. Uses arbitrary precision; so a number of any size can be converted.

Converts a number to its English counterpart. Uses arbitrary precision; so a number of any size can be converted.

Dec 14, 2021
Iran National Id, Bank Card Number, Mobile Number Validator for golang

Iran IDValidator Iran National Id, Bank Card Number, Mobile Number Validator for golang Installation go get -u github.com/mohammadv184/idvalidator Us

Dec 20, 2021
Divide (distribute) the given number (n) into number (p) of parts randomly,

Number Split Randomly The sample code written in Go lang Executables This repo already have executables for Linux and windows, after clone the repo ju

Feb 4, 2022
Using NFP (Number Format Parser) you can get an Abstract Syntax Tree (AST) from Excel number format expression

NFP (Number Format Parser) Using NFP (Number Format Parser) you can get an Abstract Syntax Tree (AST) from Excel number format expression. Installatio

Feb 4, 2022
Toy project to test golang toolset, using as pretext the "cyclic number" problem (famous 142857 number)

go-cyclic-number Toy project to test golang toolset, using as pretext the "cyclic number" problem (famous 142857 number) First version: https://github

Feb 12, 2022