github.com/stripe/stripe-go/v76@v76.25.0/invoice/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package invoice provides the /invoices APIs 8 package invoice 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 /invoices APIs. 18 type Client struct { 19 B stripe.Backend 20 Key string 21 } 22 23 // New creates a new invoice. 24 func New(params *stripe.InvoiceParams) (*stripe.Invoice, error) { 25 return getC().New(params) 26 } 27 28 // New creates a new invoice. 29 func (c Client) New(params *stripe.InvoiceParams) (*stripe.Invoice, error) { 30 invoice := &stripe.Invoice{} 31 err := c.B.Call(http.MethodPost, "/v1/invoices", c.Key, params, invoice) 32 return invoice, err 33 } 34 35 // Get returns the details of an invoice. 36 func Get(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error) { 37 return getC().Get(id, params) 38 } 39 40 // Get returns the details of an invoice. 41 func (c Client) Get(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error) { 42 path := stripe.FormatURLPath("/v1/invoices/%s", id) 43 invoice := &stripe.Invoice{} 44 err := c.B.Call(http.MethodGet, path, c.Key, params, invoice) 45 return invoice, err 46 } 47 48 // Update updates an invoice's properties. 49 func Update(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error) { 50 return getC().Update(id, params) 51 } 52 53 // Update updates an invoice's properties. 54 func (c Client) Update(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error) { 55 path := stripe.FormatURLPath("/v1/invoices/%s", id) 56 invoice := &stripe.Invoice{} 57 err := c.B.Call(http.MethodPost, path, c.Key, params, invoice) 58 return invoice, err 59 } 60 61 // Del removes an invoice. 62 func Del(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error) { 63 return getC().Del(id, params) 64 } 65 66 // Del removes an invoice. 67 func (c Client) Del(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error) { 68 path := stripe.FormatURLPath("/v1/invoices/%s", id) 69 invoice := &stripe.Invoice{} 70 err := c.B.Call(http.MethodDelete, path, c.Key, params, invoice) 71 return invoice, err 72 } 73 74 // FinalizeInvoice is the method for the `POST /v1/invoices/{invoice}/finalize` API. 75 func FinalizeInvoice(id string, params *stripe.InvoiceFinalizeInvoiceParams) (*stripe.Invoice, error) { 76 return getC().FinalizeInvoice(id, params) 77 } 78 79 // FinalizeInvoice is the method for the `POST /v1/invoices/{invoice}/finalize` API. 80 func (c Client) FinalizeInvoice(id string, params *stripe.InvoiceFinalizeInvoiceParams) (*stripe.Invoice, error) { 81 path := stripe.FormatURLPath("/v1/invoices/%s/finalize", id) 82 invoice := &stripe.Invoice{} 83 err := c.B.Call(http.MethodPost, path, c.Key, params, invoice) 84 return invoice, err 85 } 86 87 // MarkUncollectible is the method for the `POST /v1/invoices/{invoice}/mark_uncollectible` API. 88 func MarkUncollectible(id string, params *stripe.InvoiceMarkUncollectibleParams) (*stripe.Invoice, error) { 89 return getC().MarkUncollectible(id, params) 90 } 91 92 // MarkUncollectible is the method for the `POST /v1/invoices/{invoice}/mark_uncollectible` API. 93 func (c Client) MarkUncollectible(id string, params *stripe.InvoiceMarkUncollectibleParams) (*stripe.Invoice, error) { 94 path := stripe.FormatURLPath("/v1/invoices/%s/mark_uncollectible", id) 95 invoice := &stripe.Invoice{} 96 err := c.B.Call(http.MethodPost, path, c.Key, params, invoice) 97 return invoice, err 98 } 99 100 // Pay is the method for the `POST /v1/invoices/{invoice}/pay` API. 101 func Pay(id string, params *stripe.InvoicePayParams) (*stripe.Invoice, error) { 102 return getC().Pay(id, params) 103 } 104 105 // Pay is the method for the `POST /v1/invoices/{invoice}/pay` API. 106 func (c Client) Pay(id string, params *stripe.InvoicePayParams) (*stripe.Invoice, error) { 107 path := stripe.FormatURLPath("/v1/invoices/%s/pay", id) 108 invoice := &stripe.Invoice{} 109 err := c.B.Call(http.MethodPost, path, c.Key, params, invoice) 110 return invoice, err 111 } 112 113 // SendInvoice is the method for the `POST /v1/invoices/{invoice}/send` API. 114 func SendInvoice(id string, params *stripe.InvoiceSendInvoiceParams) (*stripe.Invoice, error) { 115 return getC().SendInvoice(id, params) 116 } 117 118 // SendInvoice is the method for the `POST /v1/invoices/{invoice}/send` API. 119 func (c Client) SendInvoice(id string, params *stripe.InvoiceSendInvoiceParams) (*stripe.Invoice, error) { 120 path := stripe.FormatURLPath("/v1/invoices/%s/send", id) 121 invoice := &stripe.Invoice{} 122 err := c.B.Call(http.MethodPost, path, c.Key, params, invoice) 123 return invoice, err 124 } 125 126 // Upcoming is the method for the `GET /v1/invoices/upcoming` API. 127 func Upcoming(params *stripe.InvoiceUpcomingParams) (*stripe.Invoice, error) { 128 return getC().Upcoming(params) 129 } 130 131 // Upcoming is the method for the `GET /v1/invoices/upcoming` API. 132 func (c Client) Upcoming(params *stripe.InvoiceUpcomingParams) (*stripe.Invoice, error) { 133 invoice := &stripe.Invoice{} 134 err := c.B.Call( 135 http.MethodGet, 136 "/v1/invoices/upcoming", 137 c.Key, 138 params, 139 invoice, 140 ) 141 return invoice, err 142 } 143 144 // VoidInvoice is the method for the `POST /v1/invoices/{invoice}/void` API. 145 func VoidInvoice(id string, params *stripe.InvoiceVoidInvoiceParams) (*stripe.Invoice, error) { 146 return getC().VoidInvoice(id, params) 147 } 148 149 // VoidInvoice is the method for the `POST /v1/invoices/{invoice}/void` API. 150 func (c Client) VoidInvoice(id string, params *stripe.InvoiceVoidInvoiceParams) (*stripe.Invoice, error) { 151 path := stripe.FormatURLPath("/v1/invoices/%s/void", id) 152 invoice := &stripe.Invoice{} 153 err := c.B.Call(http.MethodPost, path, c.Key, params, invoice) 154 return invoice, err 155 } 156 157 // List returns a list of invoices. 158 func List(params *stripe.InvoiceListParams) *Iter { 159 return getC().List(params) 160 } 161 162 // List returns a list of invoices. 163 func (c Client) List(listParams *stripe.InvoiceListParams) *Iter { 164 return &Iter{ 165 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 166 list := &stripe.InvoiceList{} 167 err := c.B.CallRaw(http.MethodGet, "/v1/invoices", c.Key, b, p, list) 168 169 ret := make([]interface{}, len(list.Data)) 170 for i, v := range list.Data { 171 ret[i] = v 172 } 173 174 return ret, list, err 175 }), 176 } 177 } 178 179 // Iter is an iterator for invoices. 180 type Iter struct { 181 *stripe.Iter 182 } 183 184 // Invoice returns the invoice which the iterator is currently pointing to. 185 func (i *Iter) Invoice() *stripe.Invoice { 186 return i.Current().(*stripe.Invoice) 187 } 188 189 // InvoiceList returns the current list object which the iterator is 190 // currently using. List objects will change as new API calls are made to 191 // continue pagination. 192 func (i *Iter) InvoiceList() *stripe.InvoiceList { 193 return i.List().(*stripe.InvoiceList) 194 } 195 196 // ListLines is the method for the `GET /v1/invoices/{invoice}/lines` API. 197 func ListLines(params *stripe.InvoiceListLinesParams) *LineItemIter { 198 return getC().ListLines(params) 199 } 200 201 // ListLines is the method for the `GET /v1/invoices/{invoice}/lines` API. 202 func (c Client) ListLines(listParams *stripe.InvoiceListLinesParams) *LineItemIter { 203 path := stripe.FormatURLPath( 204 "/v1/invoices/%s/lines", 205 stripe.StringValue(listParams.Invoice), 206 ) 207 return &LineItemIter{ 208 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 209 list := &stripe.InvoiceLineItemList{} 210 err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list) 211 212 ret := make([]interface{}, len(list.Data)) 213 for i, v := range list.Data { 214 ret[i] = v 215 } 216 217 return ret, list, err 218 }), 219 } 220 } 221 222 // UpcomingLines is the method for the `GET /v1/invoices/upcoming/lines` API. 223 func UpcomingLines(params *stripe.InvoiceUpcomingLinesParams) *LineItemIter { 224 return getC().UpcomingLines(params) 225 } 226 227 // UpcomingLines is the method for the `GET /v1/invoices/upcoming/lines` API. 228 func (c Client) UpcomingLines(listParams *stripe.InvoiceUpcomingLinesParams) *LineItemIter { 229 return &LineItemIter{ 230 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 231 list := &stripe.InvoiceLineItemList{} 232 err := c.B.CallRaw(http.MethodGet, "/v1/invoices/upcoming/lines", c.Key, b, p, list) 233 234 ret := make([]interface{}, len(list.Data)) 235 for i, v := range list.Data { 236 ret[i] = v 237 } 238 239 return ret, list, err 240 }), 241 } 242 } 243 244 // LineItemIter is an iterator for invoice line items. 245 type LineItemIter struct { 246 *stripe.Iter 247 } 248 249 // InvoiceLineItem returns the invoice line item which the iterator is currently pointing to. 250 func (i *LineItemIter) InvoiceLineItem() *stripe.InvoiceLineItem { 251 return i.Current().(*stripe.InvoiceLineItem) 252 } 253 254 // InvoiceLineItemList returns the current list object which the iterator is 255 // currently using. List objects will change as new API calls are made to 256 // continue pagination. 257 func (i *LineItemIter) InvoiceLineItemList() *stripe.InvoiceLineItemList { 258 return i.List().(*stripe.InvoiceLineItemList) 259 } 260 261 // Search returns a search result containing invoices. 262 func Search(params *stripe.InvoiceSearchParams) *SearchIter { 263 return getC().Search(params) 264 } 265 266 // Search returns a search result containing invoices. 267 func (c Client) Search(params *stripe.InvoiceSearchParams) *SearchIter { 268 return &SearchIter{ 269 SearchIter: stripe.GetSearchIter(params, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.SearchContainer, error) { 270 list := &stripe.InvoiceSearchResult{} 271 err := c.B.CallRaw(http.MethodGet, "/v1/invoices/search", c.Key, b, p, list) 272 273 ret := make([]interface{}, len(list.Data)) 274 for i, v := range list.Data { 275 ret[i] = v 276 } 277 278 return ret, list, err 279 }), 280 } 281 } 282 283 // SearchIter is an iterator for invoices. 284 type SearchIter struct { 285 *stripe.SearchIter 286 } 287 288 // Invoice returns the invoice which the iterator is currently pointing to. 289 func (i *SearchIter) Invoice() *stripe.Invoice { 290 return i.Current().(*stripe.Invoice) 291 } 292 293 // InvoiceSearchResult returns the current list object which the iterator is 294 // currently using. List objects will change as new API calls are made to 295 // continue pagination. 296 func (i *SearchIter) InvoiceSearchResult() *stripe.InvoiceSearchResult { 297 return i.SearchResult().(*stripe.InvoiceSearchResult) 298 } 299 300 func getC() Client { 301 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 302 }