-
Notifications
You must be signed in to change notification settings - Fork 5
/
RatesForLocation.go
66 lines (58 loc) · 2.57 KB
/
RatesForLocation.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
63
64
65
66
package taxjar
import "encoding/json"
// RatesForLocationParams should be passed to `RatesForLocation` to show the sales tax rates for a given location․
type RatesForLocationParams struct {
Country string `url:"country,omitempty"`
State string `url:"state,omitempty"`
City string `url:"city,omitempty"`
Street string `url:"street,omitempty"`
}
// Rate is the structure for a given location's sales tax rates․
type Rate struct {
Zip string `json:"zip"`
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"`
CountryRate float64 `json:"country_rate,string"`
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"`
FreightTaxable bool `json:"freight_taxable"`
}
// RatesForLocationResponse is the structure returned from `RatesForLocation`․
//
// Access the location's rates with `RatesForLocationResponse.Rate`․
type RatesForLocationResponse struct {
Rate Rate `json:"rate"`
}
// RatesForLocation shows the sales tax rates for a given location․
//
// Please note `RatesForLocation` only returns the full combined rate for a given location․ It does not support nexus determination, sourcing based on a ship from and ship to address, shipping taxability, product exemptions, customer exemptions, or sales tax holidays․
//
// We recommend using `TaxForOrder` to accurately calculate sales tax for an order․
//
// See https://developers.taxjar.com/api/reference/?go#get-show-tax-rates-for-a-location for more details.
func (client *Config) RatesForLocation(zip string, params ...RatesForLocationParams) (*RatesForLocationResponse, error) {
var p interface{}
if len(params) > 0 {
p = params[0]
}
res, err := client.get("rates/"+zip, p)
if err != nil {
return nil, err
}
rate := new(RatesForLocationResponse)
if err := json.Unmarshal(res.([]byte), &rate); err != nil {
return nil, err
}
return rate, nil
}