-
Notifications
You must be signed in to change notification settings - Fork 1
/
account.go
497 lines (443 loc) · 18.8 KB
/
account.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package lithic
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"time"
"github.com/lithic-com/lithic-go/internal/apijson"
"github.com/lithic-com/lithic-go/internal/apiquery"
"github.com/lithic-com/lithic-go/internal/param"
"github.com/lithic-com/lithic-go/internal/requestconfig"
"github.com/lithic-com/lithic-go/option"
"github.com/lithic-com/lithic-go/packages/pagination"
)
// AccountService contains methods and other services that help with interacting
// with the lithic 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 [NewAccountService] method instead.
type AccountService struct {
Options []option.RequestOption
}
// NewAccountService 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 NewAccountService(opts ...option.RequestOption) (r *AccountService) {
r = &AccountService{}
r.Options = opts
return
}
// Get account configuration such as spend limits.
func (r *AccountService) Get(ctx context.Context, accountToken string, opts ...option.RequestOption) (res *Account, err error) {
opts = append(r.Options[:], opts...)
if accountToken == "" {
err = errors.New("missing required account_token parameter")
return
}
path := fmt.Sprintf("v1/accounts/%s", accountToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Update account configuration such as state or spend limits. Can only be run on
// accounts that are part of the program managed by this API key. Accounts that are
// in the `PAUSED` state will not be able to transact or create new cards.
func (r *AccountService) Update(ctx context.Context, accountToken string, body AccountUpdateParams, opts ...option.RequestOption) (res *Account, err error) {
opts = append(r.Options[:], opts...)
if accountToken == "" {
err = errors.New("missing required account_token parameter")
return
}
path := fmt.Sprintf("v1/accounts/%s", accountToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
return
}
// List account configurations.
func (r *AccountService) List(ctx context.Context, query AccountListParams, opts ...option.RequestOption) (res *pagination.CursorPage[Account], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "v1/accounts"
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 account configurations.
func (r *AccountService) ListAutoPaging(ctx context.Context, query AccountListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[Account] {
return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
}
// Get an Account's available spend limits, which is based on the spend limit
// configured on the Account and the amount already spent over the spend limit's
// duration. For example, if the Account has a daily spend limit of $1000
// configured, and has spent $600 in the last 24 hours, the available spend limit
// returned would be $400.
func (r *AccountService) GetSpendLimits(ctx context.Context, accountToken string, opts ...option.RequestOption) (res *AccountSpendLimits, err error) {
opts = append(r.Options[:], opts...)
if accountToken == "" {
err = errors.New("missing required account_token parameter")
return
}
path := fmt.Sprintf("v1/accounts/%s/spend_limits", accountToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
type Account struct {
// Globally unique identifier for the account. This is the same as the
// account_token returned by the enroll endpoint. If using this parameter, do not
// include pagination.
Token string `json:"token,required" format:"uuid"`
// Timestamp of when the account was created. For accounts created before
// 2023-05-11, this field will be null.
Created time.Time `json:"created,required,nullable" format:"date-time"`
// Spend limit information for the user containing the daily, monthly, and lifetime
// spend limit of the account. Any charges to a card owned by this account will be
// declined once their transaction volume has surpassed the value in the applicable
// time limit (rolling). A lifetime limit of 0 indicates that the lifetime limit
// feature is disabled.
SpendLimit AccountSpendLimit `json:"spend_limit,required"`
// Account state:
//
// - `ACTIVE` - Account is able to transact and create new cards.
// - `PAUSED` - Account will not be able to transact or create new cards. It can be
// set back to `ACTIVE`.
// - `CLOSED` - Account will not be able to transact or create new cards. `CLOSED`
// accounts are also unable to be transitioned to `ACTIVE` or `PAUSED` states.
// `CLOSED` accounts result from failing to pass KYB/KYC or Lithic closing for
// risk/compliance reasons. Please contact
// [[email protected]](mailto:[email protected]) if you believe this was in
// error.
State AccountState `json:"state,required"`
AccountHolder AccountAccountHolder `json:"account_holder"`
// List of identifiers for the Auth Rule(s) that are applied on the account. This
// field is deprecated and will no longer be populated in the `account_holder`
// object. The key will be removed from the schema in a future release. Use the
// `/auth_rules` endpoints to fetch Auth Rule information instead.
AuthRuleTokens []string `json:"auth_rule_tokens"`
// 3-digit alphabetic ISO 4217 code for the currency of the cardholder.
CardholderCurrency string `json:"cardholder_currency"`
VerificationAddress AccountVerificationAddress `json:"verification_address"`
JSON accountJSON `json:"-"`
}
// accountJSON contains the JSON metadata for the struct [Account]
type accountJSON struct {
Token apijson.Field
Created apijson.Field
SpendLimit apijson.Field
State apijson.Field
AccountHolder apijson.Field
AuthRuleTokens apijson.Field
CardholderCurrency apijson.Field
VerificationAddress apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Account) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accountJSON) RawJSON() string {
return r.raw
}
// Spend limit information for the user containing the daily, monthly, and lifetime
// spend limit of the account. Any charges to a card owned by this account will be
// declined once their transaction volume has surpassed the value in the applicable
// time limit (rolling). A lifetime limit of 0 indicates that the lifetime limit
// feature is disabled.
type AccountSpendLimit struct {
// Daily spend limit (in cents).
Daily int64 `json:"daily,required"`
// Total spend limit over account lifetime (in cents).
Lifetime int64 `json:"lifetime,required"`
// Monthly spend limit (in cents).
Monthly int64 `json:"monthly,required"`
JSON accountSpendLimitJSON `json:"-"`
}
// accountSpendLimitJSON contains the JSON metadata for the struct
// [AccountSpendLimit]
type accountSpendLimitJSON struct {
Daily apijson.Field
Lifetime apijson.Field
Monthly apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccountSpendLimit) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accountSpendLimitJSON) RawJSON() string {
return r.raw
}
// Account state:
//
// - `ACTIVE` - Account is able to transact and create new cards.
// - `PAUSED` - Account will not be able to transact or create new cards. It can be
// set back to `ACTIVE`.
// - `CLOSED` - Account will not be able to transact or create new cards. `CLOSED`
// accounts are also unable to be transitioned to `ACTIVE` or `PAUSED` states.
// `CLOSED` accounts result from failing to pass KYB/KYC or Lithic closing for
// risk/compliance reasons. Please contact
// [[email protected]](mailto:[email protected]) if you believe this was in
// error.
type AccountState string
const (
AccountStateActive AccountState = "ACTIVE"
AccountStatePaused AccountState = "PAUSED"
AccountStateClosed AccountState = "CLOSED"
)
func (r AccountState) IsKnown() bool {
switch r {
case AccountStateActive, AccountStatePaused, AccountStateClosed:
return true
}
return false
}
type AccountAccountHolder struct {
// Globally unique identifier for the account holder.
Token string `json:"token,required"`
// Only applicable for customers using the KYC-Exempt workflow to enroll authorized
// users of businesses. Account_token of the enrolled business associated with an
// enrolled AUTHORIZED_USER individual.
BusinessAccountToken string `json:"business_account_token,required"`
// Email address.
Email string `json:"email,required"`
// Phone number of the individual.
PhoneNumber string `json:"phone_number,required"`
JSON accountAccountHolderJSON `json:"-"`
}
// accountAccountHolderJSON contains the JSON metadata for the struct
// [AccountAccountHolder]
type accountAccountHolderJSON struct {
Token apijson.Field
BusinessAccountToken apijson.Field
Email apijson.Field
PhoneNumber apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccountAccountHolder) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accountAccountHolderJSON) RawJSON() string {
return r.raw
}
type AccountVerificationAddress struct {
// Valid deliverable address (no PO boxes).
Address1 string `json:"address1,required"`
// City name.
City string `json:"city,required"`
// Country name. Only USA is currently supported.
Country string `json:"country,required"`
// Valid postal code. Only USA postal codes (ZIP codes) are currently supported,
// entered as a five-digit postal code or nine-digit postal code (ZIP+4) using the
// format 12345-1234.
PostalCode string `json:"postal_code,required"`
// Valid state code. Only USA state codes are currently supported, entered in
// uppercase ISO 3166-2 two-character format.
State string `json:"state,required"`
// Unit or apartment number (if applicable).
Address2 string `json:"address2"`
JSON accountVerificationAddressJSON `json:"-"`
}
// accountVerificationAddressJSON contains the JSON metadata for the struct
// [AccountVerificationAddress]
type accountVerificationAddressJSON struct {
Address1 apijson.Field
City apijson.Field
Country apijson.Field
PostalCode apijson.Field
State apijson.Field
Address2 apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccountVerificationAddress) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accountVerificationAddressJSON) RawJSON() string {
return r.raw
}
type AccountSpendLimits struct {
AvailableSpendLimit AccountSpendLimitsAvailableSpendLimit `json:"available_spend_limit,required"`
SpendLimit AccountSpendLimitsSpendLimit `json:"spend_limit"`
SpendVelocity AccountSpendLimitsSpendVelocity `json:"spend_velocity"`
JSON accountSpendLimitsJSON `json:"-"`
}
// accountSpendLimitsJSON contains the JSON metadata for the struct
// [AccountSpendLimits]
type accountSpendLimitsJSON struct {
AvailableSpendLimit apijson.Field
SpendLimit apijson.Field
SpendVelocity apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccountSpendLimits) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accountSpendLimitsJSON) RawJSON() string {
return r.raw
}
type AccountSpendLimitsAvailableSpendLimit struct {
// The available spend limit (in cents) relative to the daily limit configured on
// the Account.
Daily int64 `json:"daily"`
// The available spend limit (in cents) relative to the lifetime limit configured
// on the Account.
Lifetime int64 `json:"lifetime"`
// The available spend limit (in cents) relative to the monthly limit configured on
// the Account.
Monthly int64 `json:"monthly"`
JSON accountSpendLimitsAvailableSpendLimitJSON `json:"-"`
}
// accountSpendLimitsAvailableSpendLimitJSON contains the JSON metadata for the
// struct [AccountSpendLimitsAvailableSpendLimit]
type accountSpendLimitsAvailableSpendLimitJSON struct {
Daily apijson.Field
Lifetime apijson.Field
Monthly apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccountSpendLimitsAvailableSpendLimit) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accountSpendLimitsAvailableSpendLimitJSON) RawJSON() string {
return r.raw
}
type AccountSpendLimitsSpendLimit struct {
// The configured daily spend limit (in cents) on the Account.
Daily int64 `json:"daily"`
// The configured lifetime spend limit (in cents) on the Account.
Lifetime int64 `json:"lifetime"`
// The configured monthly spend limit (in cents) on the Account.
Monthly int64 `json:"monthly"`
JSON accountSpendLimitsSpendLimitJSON `json:"-"`
}
// accountSpendLimitsSpendLimitJSON contains the JSON metadata for the struct
// [AccountSpendLimitsSpendLimit]
type accountSpendLimitsSpendLimitJSON struct {
Daily apijson.Field
Lifetime apijson.Field
Monthly apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccountSpendLimitsSpendLimit) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accountSpendLimitsSpendLimitJSON) RawJSON() string {
return r.raw
}
type AccountSpendLimitsSpendVelocity struct {
// Current daily spend velocity (in cents) on the Account. Present if daily spend
// limit is set.
Daily int64 `json:"daily"`
// Current lifetime spend velocity (in cents) on the Account. Present if lifetime
// spend limit is set.
Lifetime int64 `json:"lifetime"`
// Current monthly spend velocity (in cents) on the Account. Present if monthly
// spend limit is set.
Monthly int64 `json:"monthly"`
JSON accountSpendLimitsSpendVelocityJSON `json:"-"`
}
// accountSpendLimitsSpendVelocityJSON contains the JSON metadata for the struct
// [AccountSpendLimitsSpendVelocity]
type accountSpendLimitsSpendVelocityJSON struct {
Daily apijson.Field
Lifetime apijson.Field
Monthly apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccountSpendLimitsSpendVelocity) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accountSpendLimitsSpendVelocityJSON) RawJSON() string {
return r.raw
}
type AccountUpdateParams struct {
// Amount (in cents) for the account's daily spend limit. By default the daily
// spend limit is set to $1,250.
DailySpendLimit param.Field[int64] `json:"daily_spend_limit"`
// Amount (in cents) for the account's lifetime spend limit. Once this limit is
// reached, no transactions will be accepted on any card created for this account
// until the limit is updated. Note that a spend limit of 0 is effectively no
// limit, and should only be used to reset or remove a prior limit. Only a limit of
// 1 or above will result in declined transactions due to checks against the
// account limit. This behavior differs from the daily spend limit and the monthly
// spend limit.
LifetimeSpendLimit param.Field[int64] `json:"lifetime_spend_limit"`
// Amount (in cents) for the account's monthly spend limit. By default the monthly
// spend limit is set to $5,000.
MonthlySpendLimit param.Field[int64] `json:"monthly_spend_limit"`
// Account states.
State param.Field[AccountUpdateParamsState] `json:"state"`
// Address used during Address Verification Service (AVS) checks during
// transactions if enabled via Auth Rules. This field is deprecated as AVS checks
// are no longer supported by Authorization Rules. The field will be removed from
// the schema in a future release.
VerificationAddress param.Field[AccountUpdateParamsVerificationAddress] `json:"verification_address"`
}
func (r AccountUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Account states.
type AccountUpdateParamsState string
const (
AccountUpdateParamsStateActive AccountUpdateParamsState = "ACTIVE"
AccountUpdateParamsStatePaused AccountUpdateParamsState = "PAUSED"
)
func (r AccountUpdateParamsState) IsKnown() bool {
switch r {
case AccountUpdateParamsStateActive, AccountUpdateParamsStatePaused:
return true
}
return false
}
// Address used during Address Verification Service (AVS) checks during
// transactions if enabled via Auth Rules. This field is deprecated as AVS checks
// are no longer supported by Authorization Rules. The field will be removed from
// the schema in a future release.
type AccountUpdateParamsVerificationAddress struct {
Address1 param.Field[string] `json:"address1"`
Address2 param.Field[string] `json:"address2"`
City param.Field[string] `json:"city"`
Country param.Field[string] `json:"country"`
PostalCode param.Field[string] `json:"postal_code"`
State param.Field[string] `json:"state"`
}
func (r AccountUpdateParamsVerificationAddress) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type AccountListParams struct {
// Date string in RFC 3339 format. Only entries created after the specified time
// will be included. UTC time zone.
Begin param.Field[time.Time] `query:"begin" format:"date-time"`
// Date string in RFC 3339 format. Only entries created before the specified time
// will be included. UTC time zone.
End param.Field[time.Time] `query:"end" format:"date-time"`
// A cursor representing an item's token before which a page of results should end.
// Used to retrieve the previous page of results before this item.
EndingBefore param.Field[string] `query:"ending_before"`
// Page size (for pagination).
PageSize param.Field[int64] `query:"page_size"`
// A cursor representing an item's token after which a page of results should
// begin. Used to retrieve the next page of results after this item.
StartingAfter param.Field[string] `query:"starting_after"`
}
// URLQuery serializes [AccountListParams]'s query parameters as `url.Values`.
func (r AccountListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}