This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
forked from MDrollette/taxjar-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rate.go
62 lines (54 loc) · 1.77 KB
/
rate.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
57
58
59
60
61
62
package taxjar
type Rate struct {
Zip string `json:"zip"`
State string `json:"state`
StateRate float64 `json:"state_rate,string"`
County string `json:"county"`
CountyRate float64 `json:"county_rate,string"`
City string `json:"city"`
CityRate float64 `json:"city_rate,string"`
CombinedDistrictRate float64 `json:"combined_district_rate,string"`
CombinedRate float64 `json:"combined_rate,string"`
Country string `json:"country"`
Name string `json:"name"`
StandardRate float64 `json:"standard_rate,string"`
ReducedRate float64 `json:"reduced_rate,string"`
SuperReducedRate float64 `json:"super_reduced_rate,string"`
ParkingRate float64 `json:"parking_rate,string"`
DistanceSaleThreshold float64 `json:"distance_sale_threshold,string"`
FreightTaxable *bool `json:"freight_taxable"`
}
type RateList struct {
Rate Rate `json:"rate"`
}
type rateParams struct {
Country string `url:"country,omitempty"`
Zip string `url:"-"`
City string `url:"city,omitempty"`
Street string `url:"street,omitempty"`
}
func RateCountry(country string) func(*rateParams) error {
return func(rp *rateParams) error {
rp.Country = country
return nil
}
}
func RateCity(city string) func(*rateParams) error {
return func(rp *rateParams) error {
rp.City = city
return nil
}
}
type RateService struct {
Repository RateRepository
}
// Get a Rate
func (s *RateService) Get(zip string, options ...func(*rateParams) error) (Rate, error) {
params := rateParams{Zip: zip}
for _, option := range options {
if err := option(¶ms); nil != err {
return Rate{}, err
}
}
return s.Repository.get(params)
}