-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.go
56 lines (50 loc) · 1.72 KB
/
default.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
51
52
53
54
55
56
package vies
import "sync"
var (
once sync.Once
defaultService *service
)
// CheckVAT given a VAT number.
// This will infer the country based on the two initial digits from the VAT number.
//
// This is a default implementation and uses the default singleton client and production endpoint.
// The client is only created and allocated if you use these default implementations.
//
// It will not necessarily return a non-nil error if the VAT is not valid.
//
// Example:
// vat, err := vies.CheckVAT("NL123456789B01")
// if err != nil {
// return
// }
// fmt.Println("Valid?:", vat.Valid)
func CheckVAT(fullVatNumber string) (*vatData, error) {
once.Do(func() {
defaultService = NewService(ProductionEndpoint)
})
return defaultService.CheckVAT(fullVatNumber)
}
// CheckVAT given a VAT number and a country.
//
// The VAT number can either contain the country code or not, as long as it matches with
// the countryCode provided.
// If you want to use the country inside the VAT number, consider using CheckVAT instead.
//
// This is a default implementation and uses the default singleton client and production endpoint.
// The client is only created and allocated if you use these default implementations.
//
// It will not necessarily return a non-nil error if the VAT is not valid.
//
// Example:
// svc := vies.NewService(vies.TestEndpoint)
// vat, err := svc.CheckVATWithCountry("NL", "123456789B01")
// if err != nil {
// return
// }
// fmt.Println("Valid?:", vat.Valid)
func CheckVATWithCountry(countryCode, vatNumber string) (*vatData, error) {
once.Do(func() {
defaultService = NewService(ProductionEndpoint)
})
return defaultService.CheckVATWithCountry(countryCode, vatNumber)
}