-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexternalaccount.go
More file actions
390 lines (338 loc) · 14.6 KB
/
externalaccount.go
File metadata and controls
390 lines (338 loc) · 14.6 KB
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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package increase
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"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"
)
// ExternalAccountService 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 [NewExternalAccountService] method instead.
type ExternalAccountService struct {
Options []option.RequestOption
}
// NewExternalAccountService 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 NewExternalAccountService(opts ...option.RequestOption) (r *ExternalAccountService) {
r = &ExternalAccountService{}
r.Options = opts
return
}
// Create an External Account
func (r *ExternalAccountService) New(ctx context.Context, body ExternalAccountNewParams, opts ...option.RequestOption) (res *ExternalAccount, err error) {
opts = slices.Concat(r.Options, opts)
path := "external_accounts"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Retrieve an External Account
func (r *ExternalAccountService) Get(ctx context.Context, externalAccountID string, opts ...option.RequestOption) (res *ExternalAccount, err error) {
opts = slices.Concat(r.Options, opts)
if externalAccountID == "" {
err = errors.New("missing required external_account_id parameter")
return nil, err
}
path := fmt.Sprintf("external_accounts/%s", externalAccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// Update an External Account
func (r *ExternalAccountService) Update(ctx context.Context, externalAccountID string, body ExternalAccountUpdateParams, opts ...option.RequestOption) (res *ExternalAccount, err error) {
opts = slices.Concat(r.Options, opts)
if externalAccountID == "" {
err = errors.New("missing required external_account_id parameter")
return nil, err
}
path := fmt.Sprintf("external_accounts/%s", externalAccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
return res, err
}
// List External Accounts
func (r *ExternalAccountService) List(ctx context.Context, query ExternalAccountListParams, opts ...option.RequestOption) (res *pagination.Page[ExternalAccount], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "external_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 External Accounts
func (r *ExternalAccountService) ListAutoPaging(ctx context.Context, query ExternalAccountListParams, opts ...option.RequestOption) *pagination.PageAutoPager[ExternalAccount] {
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
// External Accounts represent accounts at financial institutions other than
// Increase. You can use this API to store their details for reuse.
type ExternalAccount struct {
// The External Account's identifier.
ID string `json:"id" api:"required"`
// The type of entity that owns the External Account.
AccountHolder ExternalAccountAccountHolder `json:"account_holder" api:"required"`
// The destination account number.
AccountNumber string `json:"account_number" api:"required"`
// The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time at which
// the External Account was created.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
// The External Account's description for display purposes.
Description string `json:"description" api:"required"`
// The type of the account to which the transfer will be sent.
Funding ExternalAccountFunding `json:"funding" api:"required"`
// The idempotency key you chose for this object. This value is unique across
// Increase and is used to ensure that a request is only processed once. Learn more
// about [idempotency](https://increase.com/documentation/idempotency-keys).
IdempotencyKey string `json:"idempotency_key" api:"required,nullable"`
// The American Bankers' Association (ABA) Routing Transit Number (RTN).
RoutingNumber string `json:"routing_number" api:"required"`
// The External Account's status.
Status ExternalAccountStatus `json:"status" api:"required"`
// A constant representing the object's type. For this resource it will always be
// `external_account`.
Type ExternalAccountType `json:"type" api:"required"`
ExtraFields map[string]interface{} `json:"-" api:"extrafields"`
JSON externalAccountJSON `json:"-"`
}
// externalAccountJSON contains the JSON metadata for the struct [ExternalAccount]
type externalAccountJSON struct {
ID apijson.Field
AccountHolder apijson.Field
AccountNumber apijson.Field
CreatedAt apijson.Field
Description apijson.Field
Funding apijson.Field
IdempotencyKey apijson.Field
RoutingNumber apijson.Field
Status apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ExternalAccount) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r externalAccountJSON) RawJSON() string {
return r.raw
}
// The type of entity that owns the External Account.
type ExternalAccountAccountHolder string
const (
ExternalAccountAccountHolderBusiness ExternalAccountAccountHolder = "business"
ExternalAccountAccountHolderIndividual ExternalAccountAccountHolder = "individual"
ExternalAccountAccountHolderUnknown ExternalAccountAccountHolder = "unknown"
)
func (r ExternalAccountAccountHolder) IsKnown() bool {
switch r {
case ExternalAccountAccountHolderBusiness, ExternalAccountAccountHolderIndividual, ExternalAccountAccountHolderUnknown:
return true
}
return false
}
// The type of the account to which the transfer will be sent.
type ExternalAccountFunding string
const (
ExternalAccountFundingChecking ExternalAccountFunding = "checking"
ExternalAccountFundingSavings ExternalAccountFunding = "savings"
ExternalAccountFundingGeneralLedger ExternalAccountFunding = "general_ledger"
ExternalAccountFundingOther ExternalAccountFunding = "other"
)
func (r ExternalAccountFunding) IsKnown() bool {
switch r {
case ExternalAccountFundingChecking, ExternalAccountFundingSavings, ExternalAccountFundingGeneralLedger, ExternalAccountFundingOther:
return true
}
return false
}
// The External Account's status.
type ExternalAccountStatus string
const (
ExternalAccountStatusActive ExternalAccountStatus = "active"
ExternalAccountStatusArchived ExternalAccountStatus = "archived"
)
func (r ExternalAccountStatus) IsKnown() bool {
switch r {
case ExternalAccountStatusActive, ExternalAccountStatusArchived:
return true
}
return false
}
// A constant representing the object's type. For this resource it will always be
// `external_account`.
type ExternalAccountType string
const (
ExternalAccountTypeExternalAccount ExternalAccountType = "external_account"
)
func (r ExternalAccountType) IsKnown() bool {
switch r {
case ExternalAccountTypeExternalAccount:
return true
}
return false
}
type ExternalAccountNewParams struct {
// The account number for the destination account.
AccountNumber param.Field[string] `json:"account_number" api:"required"`
// The name you choose for the Account.
Description param.Field[string] `json:"description" api:"required"`
// The American Bankers' Association (ABA) Routing Transit Number (RTN) for the
// destination account.
RoutingNumber param.Field[string] `json:"routing_number" api:"required"`
// The type of entity that owns the External Account.
AccountHolder param.Field[ExternalAccountNewParamsAccountHolder] `json:"account_holder"`
// The type of the destination account. Defaults to `checking`.
Funding param.Field[ExternalAccountNewParamsFunding] `json:"funding"`
}
func (r ExternalAccountNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// The type of entity that owns the External Account.
type ExternalAccountNewParamsAccountHolder string
const (
ExternalAccountNewParamsAccountHolderBusiness ExternalAccountNewParamsAccountHolder = "business"
ExternalAccountNewParamsAccountHolderIndividual ExternalAccountNewParamsAccountHolder = "individual"
ExternalAccountNewParamsAccountHolderUnknown ExternalAccountNewParamsAccountHolder = "unknown"
)
func (r ExternalAccountNewParamsAccountHolder) IsKnown() bool {
switch r {
case ExternalAccountNewParamsAccountHolderBusiness, ExternalAccountNewParamsAccountHolderIndividual, ExternalAccountNewParamsAccountHolderUnknown:
return true
}
return false
}
// The type of the destination account. Defaults to `checking`.
type ExternalAccountNewParamsFunding string
const (
ExternalAccountNewParamsFundingChecking ExternalAccountNewParamsFunding = "checking"
ExternalAccountNewParamsFundingSavings ExternalAccountNewParamsFunding = "savings"
ExternalAccountNewParamsFundingGeneralLedger ExternalAccountNewParamsFunding = "general_ledger"
ExternalAccountNewParamsFundingOther ExternalAccountNewParamsFunding = "other"
)
func (r ExternalAccountNewParamsFunding) IsKnown() bool {
switch r {
case ExternalAccountNewParamsFundingChecking, ExternalAccountNewParamsFundingSavings, ExternalAccountNewParamsFundingGeneralLedger, ExternalAccountNewParamsFundingOther:
return true
}
return false
}
type ExternalAccountUpdateParams struct {
// The type of entity that owns the External Account.
AccountHolder param.Field[ExternalAccountUpdateParamsAccountHolder] `json:"account_holder"`
// The description you choose to give the external account.
Description param.Field[string] `json:"description"`
// The funding type of the External Account.
Funding param.Field[ExternalAccountUpdateParamsFunding] `json:"funding"`
// The status of the External Account.
Status param.Field[ExternalAccountUpdateParamsStatus] `json:"status"`
}
func (r ExternalAccountUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// The type of entity that owns the External Account.
type ExternalAccountUpdateParamsAccountHolder string
const (
ExternalAccountUpdateParamsAccountHolderBusiness ExternalAccountUpdateParamsAccountHolder = "business"
ExternalAccountUpdateParamsAccountHolderIndividual ExternalAccountUpdateParamsAccountHolder = "individual"
)
func (r ExternalAccountUpdateParamsAccountHolder) IsKnown() bool {
switch r {
case ExternalAccountUpdateParamsAccountHolderBusiness, ExternalAccountUpdateParamsAccountHolderIndividual:
return true
}
return false
}
// The funding type of the External Account.
type ExternalAccountUpdateParamsFunding string
const (
ExternalAccountUpdateParamsFundingChecking ExternalAccountUpdateParamsFunding = "checking"
ExternalAccountUpdateParamsFundingSavings ExternalAccountUpdateParamsFunding = "savings"
ExternalAccountUpdateParamsFundingGeneralLedger ExternalAccountUpdateParamsFunding = "general_ledger"
ExternalAccountUpdateParamsFundingOther ExternalAccountUpdateParamsFunding = "other"
)
func (r ExternalAccountUpdateParamsFunding) IsKnown() bool {
switch r {
case ExternalAccountUpdateParamsFundingChecking, ExternalAccountUpdateParamsFundingSavings, ExternalAccountUpdateParamsFundingGeneralLedger, ExternalAccountUpdateParamsFundingOther:
return true
}
return false
}
// The status of the External Account.
type ExternalAccountUpdateParamsStatus string
const (
ExternalAccountUpdateParamsStatusActive ExternalAccountUpdateParamsStatus = "active"
ExternalAccountUpdateParamsStatusArchived ExternalAccountUpdateParamsStatus = "archived"
)
func (r ExternalAccountUpdateParamsStatus) IsKnown() bool {
switch r {
case ExternalAccountUpdateParamsStatusActive, ExternalAccountUpdateParamsStatusArchived:
return true
}
return false
}
type ExternalAccountListParams struct {
// Return the page of entries after this one.
Cursor param.Field[string] `query:"cursor"`
// Filter records to the one with the specified `idempotency_key` you chose for
// that object. This value is unique across Increase and is used to ensure that a
// request is only processed once. Learn more about
// [idempotency](https://increase.com/documentation/idempotency-keys).
IdempotencyKey param.Field[string] `query:"idempotency_key"`
// Limit the size of the list that is returned. The default (and maximum) is 100
// objects.
Limit param.Field[int64] `query:"limit"`
// Filter External Accounts to those with the specified Routing Number.
RoutingNumber param.Field[string] `query:"routing_number"`
Status param.Field[ExternalAccountListParamsStatus] `query:"status"`
}
// URLQuery serializes [ExternalAccountListParams]'s query parameters as
// `url.Values`.
func (r ExternalAccountListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type ExternalAccountListParamsStatus struct {
// Filter External Accounts for those with the specified status or statuses. For
// GET requests, this should be encoded as a comma-delimited string, such as
// `?in=one,two,three`.
In param.Field[[]ExternalAccountListParamsStatusIn] `query:"in"`
}
// URLQuery serializes [ExternalAccountListParamsStatus]'s query parameters as
// `url.Values`.
func (r ExternalAccountListParamsStatus) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type ExternalAccountListParamsStatusIn string
const (
ExternalAccountListParamsStatusInActive ExternalAccountListParamsStatusIn = "active"
ExternalAccountListParamsStatusInArchived ExternalAccountListParamsStatusIn = "archived"
)
func (r ExternalAccountListParamsStatusIn) IsKnown() bool {
switch r {
case ExternalAccountListParamsStatusInActive, ExternalAccountListParamsStatusInArchived:
return true
}
return false
}