github.com/stripe/stripe-go/v76@v76.25.0/taxrate/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package taxrate provides the /tax_rates APIs 8 package taxrate 9 10 import ( 11 "net/http" 12 13 stripe "github.com/stripe/stripe-go/v76" 14 "github.com/stripe/stripe-go/v76/form" 15 ) 16 17 // Client is used to invoke /tax_rates APIs. 18 type Client struct { 19 B stripe.Backend 20 Key string 21 } 22 23 // New creates a new tax rate. 24 func New(params *stripe.TaxRateParams) (*stripe.TaxRate, error) { 25 return getC().New(params) 26 } 27 28 // New creates a new tax rate. 29 func (c Client) New(params *stripe.TaxRateParams) (*stripe.TaxRate, error) { 30 taxrate := &stripe.TaxRate{} 31 err := c.B.Call(http.MethodPost, "/v1/tax_rates", c.Key, params, taxrate) 32 return taxrate, err 33 } 34 35 // Get returns the details of a tax rate. 36 func Get(id string, params *stripe.TaxRateParams) (*stripe.TaxRate, error) { 37 return getC().Get(id, params) 38 } 39 40 // Get returns the details of a tax rate. 41 func (c Client) Get(id string, params *stripe.TaxRateParams) (*stripe.TaxRate, error) { 42 path := stripe.FormatURLPath("/v1/tax_rates/%s", id) 43 taxrate := &stripe.TaxRate{} 44 err := c.B.Call(http.MethodGet, path, c.Key, params, taxrate) 45 return taxrate, err 46 } 47 48 // Update updates a tax rate's properties. 49 func Update(id string, params *stripe.TaxRateParams) (*stripe.TaxRate, error) { 50 return getC().Update(id, params) 51 } 52 53 // Update updates a tax rate's properties. 54 func (c Client) Update(id string, params *stripe.TaxRateParams) (*stripe.TaxRate, error) { 55 path := stripe.FormatURLPath("/v1/tax_rates/%s", id) 56 taxrate := &stripe.TaxRate{} 57 err := c.B.Call(http.MethodPost, path, c.Key, params, taxrate) 58 return taxrate, err 59 } 60 61 // List returns a list of tax rates. 62 func List(params *stripe.TaxRateListParams) *Iter { 63 return getC().List(params) 64 } 65 66 // List returns a list of tax rates. 67 func (c Client) List(listParams *stripe.TaxRateListParams) *Iter { 68 return &Iter{ 69 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 70 list := &stripe.TaxRateList{} 71 err := c.B.CallRaw(http.MethodGet, "/v1/tax_rates", c.Key, b, p, list) 72 73 ret := make([]interface{}, len(list.Data)) 74 for i, v := range list.Data { 75 ret[i] = v 76 } 77 78 return ret, list, err 79 }), 80 } 81 } 82 83 // Iter is an iterator for tax rates. 84 type Iter struct { 85 *stripe.Iter 86 } 87 88 // TaxRate returns the tax rate which the iterator is currently pointing to. 89 func (i *Iter) TaxRate() *stripe.TaxRate { 90 return i.Current().(*stripe.TaxRate) 91 } 92 93 // TaxRateList returns the current list object which the iterator is 94 // currently using. List objects will change as new API calls are made to 95 // continue pagination. 96 func (i *Iter) TaxRateList() *stripe.TaxRateList { 97 return i.List().(*stripe.TaxRateList) 98 } 99 100 func getC() Client { 101 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 102 }