-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcard.go
206 lines (173 loc) · 5.7 KB
/
card.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package terminal
import (
"context"
"errors"
"fmt"
"net/http"
"github.com/terminaldotshop/terminal-sdk-go/internal/apijson"
"github.com/terminaldotshop/terminal-sdk-go/internal/param"
"github.com/terminaldotshop/terminal-sdk-go/internal/requestconfig"
"github.com/terminaldotshop/terminal-sdk-go/option"
)
// CardService contains methods and other services that help with interacting with
// the terminal API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewCardService] method instead.
type CardService struct {
Options []option.RequestOption
}
// NewCardService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewCardService(opts ...option.RequestOption) (r *CardService) {
r = &CardService{}
r.Options = opts
return
}
// Attach a credit card (tokenized via Stripe) to the current user.
func (r *CardService) New(ctx context.Context, body CardNewParams, opts ...option.RequestOption) (res *CardNewResponse, err error) {
opts = append(r.Options[:], opts...)
path := "card"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// List the credit cards associated with the current user.
func (r *CardService) List(ctx context.Context, opts ...option.RequestOption) (res *CardListResponse, err error) {
opts = append(r.Options[:], opts...)
path := "card"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Delete a credit card associated with the current user.
func (r *CardService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (res *CardDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("card/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
// Credit card used for payments in the Terminal shop.
type Card struct {
// Unique object identifier. The format and length of IDs may change over time.
ID string `json:"id,required"`
// Brand of the card.
Brand string `json:"brand,required"`
// Expiration of the card.
Expiration CardExpiration `json:"expiration,required"`
// Last four digits of the card.
Last4 string `json:"last4,required"`
JSON cardJSON `json:"-"`
}
// cardJSON contains the JSON metadata for the struct [Card]
type cardJSON struct {
ID apijson.Field
Brand apijson.Field
Expiration apijson.Field
Last4 apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Card) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r cardJSON) RawJSON() string {
return r.raw
}
// Expiration of the card.
type CardExpiration struct {
// Expiration month of the card.
Month int64 `json:"month,required"`
// Expiration year of the card.
Year int64 `json:"year,required"`
JSON cardExpirationJSON `json:"-"`
}
// cardExpirationJSON contains the JSON metadata for the struct [CardExpiration]
type cardExpirationJSON struct {
Month apijson.Field
Year apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CardExpiration) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r cardExpirationJSON) RawJSON() string {
return r.raw
}
type CardNewResponse struct {
// ID of the card.
Data string `json:"data,required"`
JSON cardNewResponseJSON `json:"-"`
}
// cardNewResponseJSON contains the JSON metadata for the struct [CardNewResponse]
type cardNewResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CardNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r cardNewResponseJSON) RawJSON() string {
return r.raw
}
type CardListResponse struct {
// List of cards associated with the user.
Data []Card `json:"data,required"`
JSON cardListResponseJSON `json:"-"`
}
// cardListResponseJSON contains the JSON metadata for the struct
// [CardListResponse]
type cardListResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CardListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r cardListResponseJSON) RawJSON() string {
return r.raw
}
type CardDeleteResponse struct {
Data CardDeleteResponseData `json:"data,required"`
JSON cardDeleteResponseJSON `json:"-"`
}
// cardDeleteResponseJSON contains the JSON metadata for the struct
// [CardDeleteResponse]
type cardDeleteResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CardDeleteResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r cardDeleteResponseJSON) RawJSON() string {
return r.raw
}
type CardDeleteResponseData string
const (
CardDeleteResponseDataOk CardDeleteResponseData = "ok"
)
func (r CardDeleteResponseData) IsKnown() bool {
switch r {
case CardDeleteResponseDataOk:
return true
}
return false
}
type CardNewParams struct {
// Stripe card token. Learn how to
// [create one here](https://docs.stripe.com/api/tokens/create_card).
Token param.Field[string] `json:"token,required"`
}
func (r CardNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}