神刀安全网

Code: vat – VAT number validation & country specific rates retrieval.

Package vat

Code: vat - VAT number validation & country specific rates retrieval.

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 := vat.ValidateNumber("NL123456789B01")    // Validate number format   validity := vat.ValidateNumberFormat("NL123456789B01")    // Validate number existence   validity := 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, _ := vat.GetCountryRates("NL")   r, _ := 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.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Code: vat – VAT number validation & country specific rates retrieval.

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址