-
Notifications
You must be signed in to change notification settings - Fork 0
/
vat.go
39 lines (32 loc) · 1.03 KB
/
vat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Package vat provides an API Client for working with the Open Service by European Commission.
//
// See https://ec.europa.eu/info/index_en for full documentation of the API which this
// package makes requests to.
package vat
import (
"github.com/miguelbemartin/vat/models"
"github.com/miguelbemartin/vat/services"
)
// Client holds a connection to the service
type Client struct {
// Services used for communicating with the external service.
validator *services.ValidatorService
rates *services.RatesService
}
// NewClient will create http client to create http request
func NewClient() *Client {
// Create a new instance
c := &Client{}
// Init services
c.validator = services.NewValidatorService()
c.rates = services.NewRatesService()
return c
}
// Validate will validate the vat number
func (c Client) Validate(vat string) (bool, error) {
return c.validator.Validate(vat)
}
// GetRate will return the rate by the country given
func (c Client) GetRate(countryCode string) (*models.Rate, error) {
return c.rates.Get(countryCode)
}