forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
65 lines (51 loc) · 1.67 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Package sourcetransaction provides the /source/transactions APIs.
package sourcetransaction
import (
"errors"
"net/http"
stripe "github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/form"
)
// Client is used to invoke /sources/:source_id/transactions APIs.
type Client struct {
B stripe.Backend
Key string
}
// List returns a list of source transactions.
func List(params *stripe.SourceTransactionListParams) *Iter {
return getC().List(params)
}
// List returns a list of source transactions.
func (c Client) List(listParams *stripe.SourceTransactionListParams) *Iter {
var outerErr error
var path string
if listParams == nil || listParams.Source == nil {
outerErr = errors.New("Invalid source transaction params: Source needs to be set")
} else {
path = stripe.FormatURLPath("/v1/sources/%s/source_transactions",
stripe.StringValue(listParams.Source))
}
return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) {
list := &stripe.SourceTransactionList{}
if outerErr != nil {
return nil, list.ListMeta, outerErr
}
err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list)
ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
ret[i] = v
}
return ret, list.ListMeta, err
})}
}
// Iter is an iterator for source transactions.
type Iter struct {
*stripe.Iter
}
// SourceTransaction returns the source transaction which the iterator is currently pointing to.
func (i *Iter) SourceTransaction() *stripe.SourceTransaction {
return i.Current().(*stripe.SourceTransaction)
}
func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
}