forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
177 lines (145 loc) · 5.8 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Package creditnote provides the /credit_notes APIs
package creditnote
import (
"net/http"
stripe "github.com/stripe/stripe-go/v72"
"github.com/stripe/stripe-go/v72/form"
)
// Client is the client used to invoke /credit_notes APIs.
type Client struct {
B stripe.Backend
Key string
}
// New creates a new credit note.
func New(params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
return getC().New(params)
}
// New creates a new credit note.
func (c Client) New(params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
cn := &stripe.CreditNote{}
err := c.B.Call(http.MethodPost, "/v1/credit_notes", c.Key, params, cn)
return cn, err
}
// Get returns the details of a credit note.
func Get(id string, params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
return getC().Get(id, params)
}
// Get returns the details of a credit note.
func (c Client) Get(id string, params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
path := stripe.FormatURLPath("/v1/credit_notes/%s", id)
cn := &stripe.CreditNote{}
err := c.B.Call(http.MethodGet, path, c.Key, params, cn)
return cn, err
}
// Update updates a credit note.
func Update(id string, params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
return getC().Update(id, params)
}
// Update updates a credit note.
func (c Client) Update(id string, params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
path := stripe.FormatURLPath("/v1/credit_notes/%s", id)
cn := &stripe.CreditNote{}
err := c.B.Call(http.MethodPost, path, c.Key, params, cn)
return cn, err
}
// List returns a list of credit notes.
func List(params *stripe.CreditNoteListParams) *Iter {
return getC().List(params)
}
// List returns a list of credit notes.
func (c Client) List(listParams *stripe.CreditNoteListParams) *Iter {
return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
list := &stripe.CreditNoteList{}
err := c.B.CallRaw(http.MethodGet, "/v1/credit_notes", c.Key, b, p, list)
ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
ret[i] = v
}
return ret, list, err
})}
}
// ListLines returns a list of credit note line items on a credit note.
func ListLines(params *stripe.CreditNoteLineItemListParams) *LineItemIter {
return getC().ListLines(params)
}
// ListLines returns a list of credit note line items on a credit note.
func (c Client) ListLines(listParams *stripe.CreditNoteLineItemListParams) *LineItemIter {
path := stripe.FormatURLPath("/v1/credit_notes/%s/lines", stripe.StringValue(listParams.ID))
return &LineItemIter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
list := &stripe.CreditNoteLineItemList{}
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, err
})}
}
// ListPreviewLines returns a list of lines on a previewed credit note.
func ListPreviewLines(params *stripe.CreditNoteLineItemListPreviewParams) *LineItemIter {
return getC().ListPreviewLines(params)
}
// ListPreviewLines returns a list of lines on a previewed credit note.
func (c Client) ListPreviewLines(listParams *stripe.CreditNoteLineItemListPreviewParams) *LineItemIter {
return &LineItemIter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
list := &stripe.CreditNoteLineItemList{}
err := c.B.CallRaw(http.MethodGet, "/v1/credit_notes/preview/lines", c.Key, b, p, list)
ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
ret[i] = v
}
return ret, list, err
})}
}
// Preview previews a credit note.
func Preview(params *stripe.CreditNotePreviewParams) (*stripe.CreditNote, error) {
return getC().Preview(params)
}
// Preview previews a credit note.
func (c Client) Preview(params *stripe.CreditNotePreviewParams) (*stripe.CreditNote, error) {
cn := &stripe.CreditNote{}
err := c.B.Call(http.MethodGet, "/v1/credit_notes/preview", c.Key, params, cn)
return cn, err
}
// VoidCreditNote voids a credit note.
func VoidCreditNote(id string, params *stripe.CreditNoteVoidParams) (*stripe.CreditNote, error) {
return getC().VoidCreditNote(id, params)
}
// VoidCreditNote voids a credit note.
func (c Client) VoidCreditNote(id string, params *stripe.CreditNoteVoidParams) (*stripe.CreditNote, error) {
path := stripe.FormatURLPath("/v1/credit_notes/%s/void", id)
cn := &stripe.CreditNote{}
err := c.B.Call(http.MethodPost, path, c.Key, params, cn)
return cn, err
}
// Iter is an iterator for credit notes.
type Iter struct {
*stripe.Iter
}
// CreditNote returns the cn which the iterator is currently pointing to.
func (i *Iter) CreditNote() *stripe.CreditNote {
return i.Current().(*stripe.CreditNote)
}
// CreditNoteList returns the current list object which the iterator is
// currently using. List objects will change as new API calls are made to
// continue pagination.
func (i *Iter) CreditNoteList() *stripe.CreditNoteList {
return i.List().(*stripe.CreditNoteList)
}
// LineItemIter is an iterator for credit note line items on a credit note.
type LineItemIter struct {
*stripe.Iter
}
// CreditNoteLineItem returns the credit note line item which the iterator is currently pointing to.
func (i *LineItemIter) CreditNoteLineItem() *stripe.CreditNoteLineItem {
return i.Current().(*stripe.CreditNoteLineItem)
}
// CreditNoteLineItemList returns the current list object which the iterator is
// currently using. List objects will change as new API calls are made to
// continue pagination.
func (i *LineItemIter) CreditNoteLineItemList() *stripe.CreditNoteLineItemList {
return i.List().(*stripe.CreditNoteLineItemList)
}
func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
}