github.com/stripe/stripe-go/v76@v76.25.0/tax/calculation/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package calculation provides the /tax/calculations APIs 8 package calculation 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/calculations APIs. 18 type Client struct { 19 B stripe.Backend 20 Key string 21 } 22 23 // New creates a new tax calculation. 24 func New(params *stripe.TaxCalculationParams) (*stripe.TaxCalculation, error) { 25 return getC().New(params) 26 } 27 28 // New creates a new tax calculation. 29 func (c Client) New(params *stripe.TaxCalculationParams) (*stripe.TaxCalculation, error) { 30 calculation := &stripe.TaxCalculation{} 31 err := c.B.Call( 32 http.MethodPost, 33 "/v1/tax/calculations", 34 c.Key, 35 params, 36 calculation, 37 ) 38 return calculation, err 39 } 40 41 // ListLineItems is the method for the `GET /v1/tax/calculations/{calculation}/line_items` API. 42 func ListLineItems(params *stripe.TaxCalculationListLineItemsParams) *LineItemIter { 43 return getC().ListLineItems(params) 44 } 45 46 // ListLineItems is the method for the `GET /v1/tax/calculations/{calculation}/line_items` API. 47 func (c Client) ListLineItems(listParams *stripe.TaxCalculationListLineItemsParams) *LineItemIter { 48 path := stripe.FormatURLPath( 49 "/v1/tax/calculations/%s/line_items", 50 stripe.StringValue(listParams.Calculation), 51 ) 52 return &LineItemIter{ 53 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 54 list := &stripe.TaxCalculationLineItemList{} 55 err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list) 56 57 ret := make([]interface{}, len(list.Data)) 58 for i, v := range list.Data { 59 ret[i] = v 60 } 61 62 return ret, list, err 63 }), 64 } 65 } 66 67 // LineItemIter is an iterator for tax calculation line items. 68 type LineItemIter struct { 69 *stripe.Iter 70 } 71 72 // TaxCalculationLineItem returns the tax calculation line item which the iterator is currently pointing to. 73 func (i *LineItemIter) TaxCalculationLineItem() *stripe.TaxCalculationLineItem { 74 return i.Current().(*stripe.TaxCalculationLineItem) 75 } 76 77 // TaxCalculationLineItemList returns the current list object which the iterator is 78 // currently using. List objects will change as new API calls are made to 79 // continue pagination. 80 func (i *LineItemIter) TaxCalculationLineItemList() *stripe.TaxCalculationLineItemList { 81 return i.List().(*stripe.TaxCalculationLineItemList) 82 } 83 84 func getC() Client { 85 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 86 }