github.com/stripe/stripe-go/v76@v76.25.0/taxid/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package taxid provides the /tax_ids APIs 8 package taxid 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_ids APIs. 18 type Client struct { 19 B stripe.Backend 20 Key string 21 } 22 23 // New creates a new tax id. 24 func New(params *stripe.TaxIDParams) (*stripe.TaxID, error) { 25 return getC().New(params) 26 } 27 28 // New creates a new tax id. 29 func (c Client) New(params *stripe.TaxIDParams) (*stripe.TaxID, error) { 30 path := "/v1/tax_ids" 31 if params.Customer != nil { 32 path = stripe.FormatURLPath( 33 "/v1/customers/%s/tax_ids", 34 stripe.StringValue(params.Customer), 35 ) 36 } 37 taxid := &stripe.TaxID{} 38 err := c.B.Call(http.MethodPost, path, c.Key, params, taxid) 39 return taxid, err 40 } 41 42 // Get returns the details of a tax id. 43 func Get(id string, params *stripe.TaxIDParams) (*stripe.TaxID, error) { 44 return getC().Get(id, params) 45 } 46 47 // Get returns the details of a tax id. 48 func (c Client) Get(id string, params *stripe.TaxIDParams) (*stripe.TaxID, error) { 49 path := stripe.FormatURLPath( 50 "/v1/tax_ids/%s", 51 id, 52 ) 53 if params.Customer != nil { 54 path = stripe.FormatURLPath( 55 "/v1/customers/%s/tax_ids/%s", 56 stripe.StringValue(params.Customer), 57 id, 58 ) 59 } 60 taxid := &stripe.TaxID{} 61 err := c.B.Call(http.MethodGet, path, c.Key, params, taxid) 62 return taxid, err 63 } 64 65 // Del removes a tax id. 66 func Del(id string, params *stripe.TaxIDParams) (*stripe.TaxID, error) { 67 return getC().Del(id, params) 68 } 69 70 // Del removes a tax id. 71 func (c Client) Del(id string, params *stripe.TaxIDParams) (*stripe.TaxID, error) { 72 path := stripe.FormatURLPath( 73 "/v1/tax_ids/%s", 74 id, 75 ) 76 if params.Customer != nil { 77 path = stripe.FormatURLPath( 78 "/v1/customers/%s/tax_ids/%s", 79 stripe.StringValue(params.Customer), 80 id, 81 ) 82 } 83 taxid := &stripe.TaxID{} 84 err := c.B.Call(http.MethodDelete, path, c.Key, params, taxid) 85 return taxid, err 86 } 87 88 // List returns a list of tax ids. 89 func List(params *stripe.TaxIDListParams) *Iter { 90 return getC().List(params) 91 } 92 93 // List returns a list of tax ids. 94 func (c Client) List(listParams *stripe.TaxIDListParams) *Iter { 95 path := "/v1/tax_ids" 96 if listParams != nil && listParams.Customer != nil { 97 path = stripe.FormatURLPath( 98 "/v1/customers/%s/tax_ids", 99 stripe.StringValue(listParams.Customer), 100 ) 101 } 102 return &Iter{ 103 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 104 list := &stripe.TaxIDList{} 105 err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list) 106 107 ret := make([]interface{}, len(list.Data)) 108 for i, v := range list.Data { 109 ret[i] = v 110 } 111 112 return ret, list, err 113 }), 114 } 115 } 116 117 // Iter is an iterator for tax ids. 118 type Iter struct { 119 *stripe.Iter 120 } 121 122 // TaxID returns the tax id which the iterator is currently pointing to. 123 func (i *Iter) TaxID() *stripe.TaxID { 124 return i.Current().(*stripe.TaxID) 125 } 126 127 // TaxIDList returns the current list object which the iterator is 128 // currently using. List objects will change as new API calls are made to 129 // continue pagination. 130 func (i *Iter) TaxIDList() *stripe.TaxIDList { 131 return i.List().(*stripe.TaxIDList) 132 } 133 134 func getC() Client { 135 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 136 }