-
Notifications
You must be signed in to change notification settings - Fork 5
/
Validate.go
50 lines (42 loc) · 1.7 KB
/
Validate.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
40
41
42
43
44
45
46
47
48
49
50
package taxjar
import "encoding/json"
// ValidateParams should be passed to `Validate` to validate a VAT identification number with VIES (http://ec.europa.eu/taxation_customs/vies/)․
type ValidateParams struct {
VAT string `url:"vat,omitempty"`
}
// VIESResponse is the structure for a response from VIES (http://ec.europa.eu/taxation_customs/vies/) returned as `ValidateResponse.Validation.ViesResponse`․
type VIESResponse struct {
CountryCode string `json:"country_code"`
VATNumber string `json:"vat_number"`
RequestDate string `json:"request_date"`
Valid bool `json:"valid"`
Name string `json:"name"`
Address string `json:"address"`
}
// Validation is the structure for a VAT identification number validation returned within `ValidateResponse`․
type Validation struct {
Valid bool `json:"valid"`
Exists bool `json:"exists"`
VIESAvailable bool `json:"vies_available"`
VIESResponse VIESResponse `json:"vies_response"`
}
// ValidateResponse is the structure returned from `Validate`․
//
// Access the validation with `ValidateResponse.Validation`․
type ValidateResponse struct {
Validation Validation `json:"validation"`
}
// Validate validates a VAT identification number with VIES (http://ec.europa.eu/taxation_customs/vies/)․
//
// See https://developers.taxjar.com/api/reference/?go#get-validate-a-vat-number for more details․
func (client *Config) Validate(params ValidateParams) (*ValidateResponse, error) {
res, err := client.get("validation", params)
if err != nil {
return nil, err
}
validation := new(ValidateResponse)
if err := json.Unmarshal(res.([]byte), &validation); err != nil {
return nil, err
}
return validation, nil
}