Code Monkey home page Code Monkey logo

vat's Introduction

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.

vat's People

Contributors

mattes avatar ntea avatar schmittjoh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vat's Issues

False error when VIES return an error message

When the VIES return an error message, this library return the error "service returned invalid request date".
That is not correct. It should return the error message returned by VIES.

You can correct it by changing the response structure by :
var rd struct {
XMLName xml.Name xml:"Envelope"
Soap struct {
XMLName xml.Name xml:"Body"
Soap struct {
XMLName xml.Name xml:"checkVatResponse"
CountryCode string xml:"countryCode"
VATnumber string xml:"vatNumber"
RequestDate string xml:"requestDate" // 2015-03-06+01:00
Valid bool xml:"valid"
Name string xml:"name"
Address string xml:"address"
}

		SoapFault struct {
			XMLName string `xml:"Fault"`
			Code    string `xml:"faultcode"`
			Message string `xml:"faultstring"`
		}
	}
}

And check the error after the unmarshal :
if rd.Soap.SoapFault.Message != "" {
return nil, errors.New("service returned an error : " + rd.Soap.SoapFault.Message)
}

go.mod etc.

Hey, would you take contributions? As in go.mod and maybe GitHub Actions setup?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.