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

Related tags

Financial vat
Overview

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.

Issues
  • 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
    opened by Fank 2
  • 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

    opened by brutella 1
  • 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?

    opened by marotpam 1
  • 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

    enhancement 
    opened by dannyvankooten 1
  • 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
    }
    
    opened by ChielTimmermans 0
Owner
Danny van Kooten
Independent developer, writing open-source code for a living.
Danny van Kooten
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

bitebait 1 Apr 11, 2022
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

Nikita Shamaev 0 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

LTNs35 4 Apr 4, 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

null 0 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

Ozzo Framework 2.8k Jul 1, 2022
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

Ozzo Framework 551 Jun 3, 2022
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

Liang Yaopei 70 Jun 29, 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

Stretchr, Inc. 523 Jun 21, 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.

Gustavo H. M. Silva 6 Aug 3, 2021
Simple module for validation inn control number

simple module for validation inn control number

Pavel 0 Nov 18, 2021
Go client for the Foreign exchange rates and currency conversion API πŸ’°

fixer Go client for Fixer.io (Foreign exchange rates and currency conversion API) You need to register for a free access key if using the default Fixe

Peter Hellberg 18 Jul 3, 2022
INCC calculator based on monthly rates.

inccCalc INCC calculator based on monthly rates. inccCalc version 1.0. Type 'help' for help, 'stop' to end the program. -help -stop -version -calc 'ca

ooshowa_ 0 Oct 29, 2021
Go client for the Foreign exchange rates and currency conversion API moneybag

fixer Go client for Fixer.io (Foreign exchange rates and currency conversion API) You need to register for a free access key if using the default Fixe

Shingirai Chanakira 0 Nov 25, 2021
Simple & efficient Go library for getting daily foreign exchange rates. Built-in support for 50+ currencies.

go-forex Simple and efficient Go library for getting daily foreign exchange rates. Built-in support for ca. 50 currencies. Also includes a simple comm

wowsignal.io 6 Apr 4, 2022
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

Eduard 15 Apr 28, 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.

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

Narasimha Prasanna HN 692 Jun 30, 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

TECHCRAFT TECHNOLOGIES LIMITED 8 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

Marten Seemann 1 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

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

Narasimha Prasanna HN 687 Jun 22, 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.

null 0 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

Mohammad Abbasi 1 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

Jobin Jose 0 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

fossabot 0 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

A. M. Cajal 0 Feb 12, 2022
Vat ID Validator for Germany

German Vat Validator service This project has been developed using Hexagonal architecture and repository pattern. How to run? docker-compose up -d Cal

Omid Tavakoli 0 Nov 4, 2021
Utilities around dealing with images inside of game dev. Inspired by my hate for TGA.

Image Conversion Utilities around dealing with images inside of game dev. Inspired by my hate for TGA. Install go install ./cmd/imgconv Examples TGA

Recolude 2 Oct 28, 2021
Makes dealing with AWS SSO Logins an ease

go-aws-sso Make working with AWS SSO on local machines an ease. What is it about? Choose and retrieve short-living role credentials from all of your S

Tim Heurich 45 Jun 22, 2022
Optional-go - Library for conveniently and safely dealing with optional (nullable) values

Optional Go Library for conveniently and safely dealing with optional (nullable)

Adolfo Martinelli 2 Jun 3, 2022
Go library for dealing with Ademco and Contact-ID messages

Ademco For Go A lightweight golang library for dealing with Contact-ID and Ademco messaging formats. Installation install via go get $ go get github.c

Josh Burns 0 Jan 11, 2022