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