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