-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigitalwallettoken.go
342 lines (299 loc) · 13.2 KB
/
digitalwallettoken.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package increase
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"time"
"github.com/Increase/increase-go/internal/apijson"
"github.com/Increase/increase-go/internal/apiquery"
"github.com/Increase/increase-go/internal/param"
"github.com/Increase/increase-go/internal/requestconfig"
"github.com/Increase/increase-go/option"
"github.com/Increase/increase-go/packages/pagination"
)
// DigitalWalletTokenService contains methods and other services that help with
// interacting with the increase 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 [NewDigitalWalletTokenService] method instead.
type DigitalWalletTokenService struct {
Options []option.RequestOption
}
// NewDigitalWalletTokenService 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 NewDigitalWalletTokenService(opts ...option.RequestOption) (r *DigitalWalletTokenService) {
r = &DigitalWalletTokenService{}
r.Options = opts
return
}
// Retrieve a Digital Wallet Token
func (r *DigitalWalletTokenService) Get(ctx context.Context, digitalWalletTokenID string, opts ...option.RequestOption) (res *DigitalWalletToken, err error) {
opts = append(r.Options[:], opts...)
if digitalWalletTokenID == "" {
err = errors.New("missing required digital_wallet_token_id parameter")
return
}
path := fmt.Sprintf("digital_wallet_tokens/%s", digitalWalletTokenID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// List Digital Wallet Tokens
func (r *DigitalWalletTokenService) List(ctx context.Context, query DigitalWalletTokenListParams, opts ...option.RequestOption) (res *pagination.Page[DigitalWalletToken], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "digital_wallet_tokens"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List Digital Wallet Tokens
func (r *DigitalWalletTokenService) ListAutoPaging(ctx context.Context, query DigitalWalletTokenListParams, opts ...option.RequestOption) *pagination.PageAutoPager[DigitalWalletToken] {
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
// A Digital Wallet Token is created when a user adds a Card to their Apple Pay or
// Google Pay app. The Digital Wallet Token can be used for purchases just like a
// Card.
type DigitalWalletToken struct {
// The Digital Wallet Token identifier.
ID string `json:"id,required"`
// The identifier for the Card this Digital Wallet Token belongs to.
CardID string `json:"card_id,required"`
// The cardholder information given when the Digital Wallet Token was created.
Cardholder DigitalWalletTokenCardholder `json:"cardholder,required"`
// The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time at which
// the Digital Wallet Token was created.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// The device that was used to create the Digital Wallet Token.
Device DigitalWalletTokenDevice `json:"device,required"`
// This indicates if payments can be made with the Digital Wallet Token.
Status DigitalWalletTokenStatus `json:"status,required"`
// The digital wallet app being used.
TokenRequestor DigitalWalletTokenTokenRequestor `json:"token_requestor,required"`
// A constant representing the object's type. For this resource it will always be
// `digital_wallet_token`.
Type DigitalWalletTokenType `json:"type,required"`
// Updates to the Digital Wallet Token.
Updates []DigitalWalletTokenUpdate `json:"updates,required"`
JSON digitalWalletTokenJSON `json:"-"`
}
// digitalWalletTokenJSON contains the JSON metadata for the struct
// [DigitalWalletToken]
type digitalWalletTokenJSON struct {
ID apijson.Field
CardID apijson.Field
Cardholder apijson.Field
CreatedAt apijson.Field
Device apijson.Field
Status apijson.Field
TokenRequestor apijson.Field
Type apijson.Field
Updates apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DigitalWalletToken) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r digitalWalletTokenJSON) RawJSON() string {
return r.raw
}
// The cardholder information given when the Digital Wallet Token was created.
type DigitalWalletTokenCardholder struct {
// Name of the cardholder, for example "John Smith".
Name string `json:"name,required,nullable"`
JSON digitalWalletTokenCardholderJSON `json:"-"`
}
// digitalWalletTokenCardholderJSON contains the JSON metadata for the struct
// [DigitalWalletTokenCardholder]
type digitalWalletTokenCardholderJSON struct {
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DigitalWalletTokenCardholder) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r digitalWalletTokenCardholderJSON) RawJSON() string {
return r.raw
}
// The device that was used to create the Digital Wallet Token.
type DigitalWalletTokenDevice struct {
// Device type.
DeviceType DigitalWalletTokenDeviceDeviceType `json:"device_type,required,nullable"`
// ID assigned to the device by the digital wallet provider.
Identifier string `json:"identifier,required,nullable"`
// IP address of the device.
IPAddress string `json:"ip_address,required,nullable"`
// Name of the device, for example "My Work Phone".
Name string `json:"name,required,nullable"`
JSON digitalWalletTokenDeviceJSON `json:"-"`
}
// digitalWalletTokenDeviceJSON contains the JSON metadata for the struct
// [DigitalWalletTokenDevice]
type digitalWalletTokenDeviceJSON struct {
DeviceType apijson.Field
Identifier apijson.Field
IPAddress apijson.Field
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DigitalWalletTokenDevice) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r digitalWalletTokenDeviceJSON) RawJSON() string {
return r.raw
}
// Device type.
type DigitalWalletTokenDeviceDeviceType string
const (
DigitalWalletTokenDeviceDeviceTypeUnknown DigitalWalletTokenDeviceDeviceType = "unknown"
DigitalWalletTokenDeviceDeviceTypeMobilePhone DigitalWalletTokenDeviceDeviceType = "mobile_phone"
DigitalWalletTokenDeviceDeviceTypeTablet DigitalWalletTokenDeviceDeviceType = "tablet"
DigitalWalletTokenDeviceDeviceTypeWatch DigitalWalletTokenDeviceDeviceType = "watch"
DigitalWalletTokenDeviceDeviceTypeMobilephoneOrTablet DigitalWalletTokenDeviceDeviceType = "mobilephone_or_tablet"
DigitalWalletTokenDeviceDeviceTypePc DigitalWalletTokenDeviceDeviceType = "pc"
DigitalWalletTokenDeviceDeviceTypeHouseholdDevice DigitalWalletTokenDeviceDeviceType = "household_device"
DigitalWalletTokenDeviceDeviceTypeWearableDevice DigitalWalletTokenDeviceDeviceType = "wearable_device"
DigitalWalletTokenDeviceDeviceTypeAutomobileDevice DigitalWalletTokenDeviceDeviceType = "automobile_device"
)
func (r DigitalWalletTokenDeviceDeviceType) IsKnown() bool {
switch r {
case DigitalWalletTokenDeviceDeviceTypeUnknown, DigitalWalletTokenDeviceDeviceTypeMobilePhone, DigitalWalletTokenDeviceDeviceTypeTablet, DigitalWalletTokenDeviceDeviceTypeWatch, DigitalWalletTokenDeviceDeviceTypeMobilephoneOrTablet, DigitalWalletTokenDeviceDeviceTypePc, DigitalWalletTokenDeviceDeviceTypeHouseholdDevice, DigitalWalletTokenDeviceDeviceTypeWearableDevice, DigitalWalletTokenDeviceDeviceTypeAutomobileDevice:
return true
}
return false
}
// This indicates if payments can be made with the Digital Wallet Token.
type DigitalWalletTokenStatus string
const (
DigitalWalletTokenStatusActive DigitalWalletTokenStatus = "active"
DigitalWalletTokenStatusInactive DigitalWalletTokenStatus = "inactive"
DigitalWalletTokenStatusSuspended DigitalWalletTokenStatus = "suspended"
DigitalWalletTokenStatusDeactivated DigitalWalletTokenStatus = "deactivated"
)
func (r DigitalWalletTokenStatus) IsKnown() bool {
switch r {
case DigitalWalletTokenStatusActive, DigitalWalletTokenStatusInactive, DigitalWalletTokenStatusSuspended, DigitalWalletTokenStatusDeactivated:
return true
}
return false
}
// The digital wallet app being used.
type DigitalWalletTokenTokenRequestor string
const (
DigitalWalletTokenTokenRequestorApplePay DigitalWalletTokenTokenRequestor = "apple_pay"
DigitalWalletTokenTokenRequestorGooglePay DigitalWalletTokenTokenRequestor = "google_pay"
DigitalWalletTokenTokenRequestorSamsungPay DigitalWalletTokenTokenRequestor = "samsung_pay"
DigitalWalletTokenTokenRequestorUnknown DigitalWalletTokenTokenRequestor = "unknown"
)
func (r DigitalWalletTokenTokenRequestor) IsKnown() bool {
switch r {
case DigitalWalletTokenTokenRequestorApplePay, DigitalWalletTokenTokenRequestorGooglePay, DigitalWalletTokenTokenRequestorSamsungPay, DigitalWalletTokenTokenRequestorUnknown:
return true
}
return false
}
// A constant representing the object's type. For this resource it will always be
// `digital_wallet_token`.
type DigitalWalletTokenType string
const (
DigitalWalletTokenTypeDigitalWalletToken DigitalWalletTokenType = "digital_wallet_token"
)
func (r DigitalWalletTokenType) IsKnown() bool {
switch r {
case DigitalWalletTokenTypeDigitalWalletToken:
return true
}
return false
}
type DigitalWalletTokenUpdate struct {
// The status the update changed this Digital Wallet Token to.
Status DigitalWalletTokenUpdatesStatus `json:"status,required"`
// The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time at which
// the update happened.
Timestamp time.Time `json:"timestamp,required" format:"date-time"`
JSON digitalWalletTokenUpdateJSON `json:"-"`
}
// digitalWalletTokenUpdateJSON contains the JSON metadata for the struct
// [DigitalWalletTokenUpdate]
type digitalWalletTokenUpdateJSON struct {
Status apijson.Field
Timestamp apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DigitalWalletTokenUpdate) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r digitalWalletTokenUpdateJSON) RawJSON() string {
return r.raw
}
// The status the update changed this Digital Wallet Token to.
type DigitalWalletTokenUpdatesStatus string
const (
DigitalWalletTokenUpdatesStatusActive DigitalWalletTokenUpdatesStatus = "active"
DigitalWalletTokenUpdatesStatusInactive DigitalWalletTokenUpdatesStatus = "inactive"
DigitalWalletTokenUpdatesStatusSuspended DigitalWalletTokenUpdatesStatus = "suspended"
DigitalWalletTokenUpdatesStatusDeactivated DigitalWalletTokenUpdatesStatus = "deactivated"
)
func (r DigitalWalletTokenUpdatesStatus) IsKnown() bool {
switch r {
case DigitalWalletTokenUpdatesStatusActive, DigitalWalletTokenUpdatesStatusInactive, DigitalWalletTokenUpdatesStatusSuspended, DigitalWalletTokenUpdatesStatusDeactivated:
return true
}
return false
}
type DigitalWalletTokenListParams struct {
// Filter Digital Wallet Tokens to ones belonging to the specified Card.
CardID param.Field[string] `query:"card_id"`
CreatedAt param.Field[DigitalWalletTokenListParamsCreatedAt] `query:"created_at"`
// Return the page of entries after this one.
Cursor param.Field[string] `query:"cursor"`
// Limit the size of the list that is returned. The default (and maximum) is 100
// objects.
Limit param.Field[int64] `query:"limit"`
}
// URLQuery serializes [DigitalWalletTokenListParams]'s query parameters as
// `url.Values`.
func (r DigitalWalletTokenListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type DigitalWalletTokenListParamsCreatedAt struct {
// Return results after this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
After param.Field[time.Time] `query:"after" format:"date-time"`
// Return results before this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
Before param.Field[time.Time] `query:"before" format:"date-time"`
// Return results on or after this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrAfter param.Field[time.Time] `query:"on_or_after" format:"date-time"`
// Return results on or before this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrBefore param.Field[time.Time] `query:"on_or_before" format:"date-time"`
}
// URLQuery serializes [DigitalWalletTokenListParamsCreatedAt]'s query parameters
// as `url.Values`.
func (r DigitalWalletTokenListParamsCreatedAt) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}