github.com/stripe/stripe-go/v76@v76.25.0/sourcetransaction/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package sourcetransaction provides the sourcetransaction related APIs 8 package sourcetransaction 9 10 import ( 11 "fmt" 12 "net/http" 13 14 stripe "github.com/stripe/stripe-go/v76" 15 "github.com/stripe/stripe-go/v76/form" 16 ) 17 18 // Client is used to invoke /sources/:source_id/transactions APIs. 19 type Client struct { 20 B stripe.Backend 21 Key string 22 } 23 24 // List returns a list of source transactions. 25 func List(params *stripe.SourceTransactionListParams) *Iter { 26 return getC().List(params) 27 } 28 29 // List returns a list of source transactions. 30 func (c Client) List(listParams *stripe.SourceTransactionListParams) *Iter { 31 if listParams == nil || listParams.Source == nil { 32 return &Iter{ 33 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 34 list := &stripe.SourceTransactionList{} 35 return nil, list, fmt.Errorf("Invalid source transaction params: Source needs to be set") 36 }), 37 } 38 } 39 path := stripe.FormatURLPath( 40 "/v1/sources/%s/source_transactions", 41 stripe.StringValue(listParams.Source), 42 ) 43 return &Iter{ 44 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 45 list := &stripe.SourceTransactionList{} 46 err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list) 47 48 ret := make([]interface{}, len(list.Data)) 49 for i, v := range list.Data { 50 ret[i] = v 51 } 52 53 return ret, list, err 54 }), 55 } 56 } 57 58 // Iter is an iterator for source transactions. 59 type Iter struct { 60 *stripe.Iter 61 } 62 63 // SourceTransaction returns the source transaction which the iterator is currently pointing to. 64 func (i *Iter) SourceTransaction() *stripe.SourceTransaction { 65 return i.Current().(*stripe.SourceTransaction) 66 } 67 68 // SourceTransactionList returns the current list object which the iterator is 69 // currently using. List objects will change as new API calls are made to 70 // continue pagination. 71 func (i *Iter) SourceTransactionList() *stripe.SourceTransactionList { 72 return i.List().(*stripe.SourceTransactionList) 73 } 74 75 func getC() Client { 76 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 77 }