-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinternalaccount.go
410 lines (371 loc) · 19 KB
/
internalaccount.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package moderntreasury
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"time"
"github.com/Modern-Treasury/modern-treasury-go/v2/internal/apijson"
"github.com/Modern-Treasury/modern-treasury-go/v2/internal/apiquery"
"github.com/Modern-Treasury/modern-treasury-go/v2/internal/param"
"github.com/Modern-Treasury/modern-treasury-go/v2/internal/requestconfig"
"github.com/Modern-Treasury/modern-treasury-go/v2/option"
"github.com/Modern-Treasury/modern-treasury-go/v2/packages/pagination"
"github.com/Modern-Treasury/modern-treasury-go/v2/shared"
)
// InternalAccountService contains methods and other services that help with
// interacting with the Modern Treasury 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 [NewInternalAccountService] method instead.
type InternalAccountService struct {
Options []option.RequestOption
BalanceReports *InternalAccountBalanceReportService
}
// NewInternalAccountService 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 NewInternalAccountService(opts ...option.RequestOption) (r *InternalAccountService) {
r = &InternalAccountService{}
r.Options = opts
r.BalanceReports = NewInternalAccountBalanceReportService(opts...)
return
}
// create internal account
func (r *InternalAccountService) New(ctx context.Context, body InternalAccountNewParams, opts ...option.RequestOption) (res *InternalAccount, err error) {
opts = append(r.Options[:], opts...)
path := "api/internal_accounts"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// get internal account
func (r *InternalAccountService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *InternalAccount, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("api/internal_accounts/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// update internal account
func (r *InternalAccountService) Update(ctx context.Context, id string, body InternalAccountUpdateParams, opts ...option.RequestOption) (res *InternalAccount, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("api/internal_accounts/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
return
}
// list internal accounts
func (r *InternalAccountService) List(ctx context.Context, query InternalAccountListParams, opts ...option.RequestOption) (res *pagination.Page[InternalAccount], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "api/internal_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 internal accounts
func (r *InternalAccountService) ListAutoPaging(ctx context.Context, query InternalAccountListParams, opts ...option.RequestOption) *pagination.PageAutoPager[InternalAccount] {
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
type InternalAccount struct {
ID string `json:"id,required" format:"uuid"`
// An array of account detail objects.
AccountDetails []AccountDetail `json:"account_details,required"`
// Can be checking, savings or other.
AccountType InternalAccountAccountType `json:"account_type,required,nullable"`
// Specifies which financial institution the accounts belong to.
Connection Connection `json:"connection,required"`
// The Counterparty associated to this account.
CounterpartyID string `json:"counterparty_id,required,nullable" format:"uuid"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// The currency of the account.
Currency shared.Currency `json:"currency,required"`
// If the internal account links to a ledger account in Modern Treasury, the id of
// the ledger account will be populated here.
LedgerAccountID string `json:"ledger_account_id,required,nullable" format:"uuid"`
// The Legal Entity associated to this account
LegalEntityID string `json:"legal_entity_id,required,nullable" format:"uuid"`
// This field will be true if this object exists in the live environment or false
// if it exists in the test environment.
LiveMode bool `json:"live_mode,required"`
// Additional data represented as key-value pairs. Both the key and value must be
// strings.
Metadata map[string]string `json:"metadata,required"`
// A nickname for the account.
Name string `json:"name,required,nullable"`
Object string `json:"object,required"`
// The parent InternalAccount of this account.
ParentAccountID string `json:"parent_account_id,required,nullable" format:"uuid"`
// The address associated with the owner or null.
PartyAddress InternalAccountPartyAddress `json:"party_address,required,nullable"`
// The legal name of the entity which owns the account.
PartyName string `json:"party_name,required"`
// Either individual or business.
PartyType InternalAccountPartyType `json:"party_type,required,nullable"`
// An array of routing detail objects.
RoutingDetails []RoutingDetail `json:"routing_details,required"`
UpdatedAt time.Time `json:"updated_at,required" format:"date-time"`
JSON internalAccountJSON `json:"-"`
}
// internalAccountJSON contains the JSON metadata for the struct [InternalAccount]
type internalAccountJSON struct {
ID apijson.Field
AccountDetails apijson.Field
AccountType apijson.Field
Connection apijson.Field
CounterpartyID apijson.Field
CreatedAt apijson.Field
Currency apijson.Field
LedgerAccountID apijson.Field
LegalEntityID apijson.Field
LiveMode apijson.Field
Metadata apijson.Field
Name apijson.Field
Object apijson.Field
ParentAccountID apijson.Field
PartyAddress apijson.Field
PartyName apijson.Field
PartyType apijson.Field
RoutingDetails apijson.Field
UpdatedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *InternalAccount) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r internalAccountJSON) RawJSON() string {
return r.raw
}
func (r InternalAccount) implementsPaymentOrderUltimateOriginatingAccount() {}
// Can be checking, savings or other.
type InternalAccountAccountType string
const (
InternalAccountAccountTypeCash InternalAccountAccountType = "cash"
InternalAccountAccountTypeChecking InternalAccountAccountType = "checking"
InternalAccountAccountTypeGeneralLedger InternalAccountAccountType = "general_ledger"
InternalAccountAccountTypeLoan InternalAccountAccountType = "loan"
InternalAccountAccountTypeNonResident InternalAccountAccountType = "non_resident"
InternalAccountAccountTypeOther InternalAccountAccountType = "other"
InternalAccountAccountTypeOverdraft InternalAccountAccountType = "overdraft"
InternalAccountAccountTypeSavings InternalAccountAccountType = "savings"
)
func (r InternalAccountAccountType) IsKnown() bool {
switch r {
case InternalAccountAccountTypeCash, InternalAccountAccountTypeChecking, InternalAccountAccountTypeGeneralLedger, InternalAccountAccountTypeLoan, InternalAccountAccountTypeNonResident, InternalAccountAccountTypeOther, InternalAccountAccountTypeOverdraft, InternalAccountAccountTypeSavings:
return true
}
return false
}
// The address associated with the owner or null.
type InternalAccountPartyAddress struct {
ID string `json:"id,required" format:"uuid"`
// Country code conforms to [ISO 3166-1 alpha-2]
Country string `json:"country,required,nullable"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
Line1 string `json:"line1,required,nullable"`
Line2 string `json:"line2,required,nullable"`
// This field will be true if this object exists in the live environment or false
// if it exists in the test environment.
LiveMode bool `json:"live_mode,required"`
// Locality or City.
Locality string `json:"locality,required,nullable"`
Object string `json:"object,required"`
// The postal code of the address.
PostalCode string `json:"postal_code,required,nullable"`
// Region or State.
Region string `json:"region,required,nullable"`
UpdatedAt time.Time `json:"updated_at,required" format:"date-time"`
JSON internalAccountPartyAddressJSON `json:"-"`
}
// internalAccountPartyAddressJSON contains the JSON metadata for the struct
// [InternalAccountPartyAddress]
type internalAccountPartyAddressJSON struct {
ID apijson.Field
Country apijson.Field
CreatedAt apijson.Field
Line1 apijson.Field
Line2 apijson.Field
LiveMode apijson.Field
Locality apijson.Field
Object apijson.Field
PostalCode apijson.Field
Region apijson.Field
UpdatedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *InternalAccountPartyAddress) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r internalAccountPartyAddressJSON) RawJSON() string {
return r.raw
}
// Either individual or business.
type InternalAccountPartyType string
const (
InternalAccountPartyTypeBusiness InternalAccountPartyType = "business"
InternalAccountPartyTypeIndividual InternalAccountPartyType = "individual"
)
func (r InternalAccountPartyType) IsKnown() bool {
switch r {
case InternalAccountPartyTypeBusiness, InternalAccountPartyTypeIndividual:
return true
}
return false
}
type InternalAccountNewParams struct {
// The identifier of the financial institution the account belongs to.
ConnectionID param.Field[string] `json:"connection_id,required"`
// Either "USD" or "CAD". Internal accounts created at Increase only supports
// "USD".
Currency param.Field[InternalAccountNewParamsCurrency] `json:"currency,required"`
// The nickname of the account.
Name param.Field[string] `json:"name,required"`
// The legal name of the entity which owns the account.
PartyName param.Field[string] `json:"party_name,required"`
// The Counterparty associated to this account.
CounterpartyID param.Field[string] `json:"counterparty_id"`
// The LegalEntity associated to this account.
LegalEntityID param.Field[string] `json:"legal_entity_id"`
// The parent internal account of this new account.
ParentAccountID param.Field[string] `json:"parent_account_id"`
// The address associated with the owner or null.
PartyAddress param.Field[InternalAccountNewParamsPartyAddress] `json:"party_address"`
// A hash of vendor specific attributes that will be used when creating the account
// at the vendor specified by the given connection.
VendorAttributes param.Field[map[string]string] `json:"vendor_attributes"`
}
func (r InternalAccountNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Either "USD" or "CAD". Internal accounts created at Increase only supports
// "USD".
type InternalAccountNewParamsCurrency string
const (
InternalAccountNewParamsCurrencyUsd InternalAccountNewParamsCurrency = "USD"
InternalAccountNewParamsCurrencyCad InternalAccountNewParamsCurrency = "CAD"
)
func (r InternalAccountNewParamsCurrency) IsKnown() bool {
switch r {
case InternalAccountNewParamsCurrencyUsd, InternalAccountNewParamsCurrencyCad:
return true
}
return false
}
// The address associated with the owner or null.
type InternalAccountNewParamsPartyAddress struct {
// Country code conforms to [ISO 3166-1 alpha-2]
Country param.Field[string] `json:"country,required"`
Line1 param.Field[string] `json:"line1,required"`
// Locality or City.
Locality param.Field[string] `json:"locality,required"`
// The postal code of the address.
PostalCode param.Field[string] `json:"postal_code,required"`
// Region or State.
Region param.Field[string] `json:"region,required"`
Line2 param.Field[string] `json:"line2"`
}
func (r InternalAccountNewParamsPartyAddress) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type InternalAccountUpdateParams struct {
// The Counterparty associated to this account.
CounterpartyID param.Field[string] `json:"counterparty_id"`
// The Ledger Account associated to this account.
LedgerAccountID param.Field[string] `json:"ledger_account_id"`
// Additional data in the form of key-value pairs. Pairs can be removed by passing
// an empty string or `null` as the value.
Metadata param.Field[map[string]string] `json:"metadata"`
// The nickname for the internal account.
Name param.Field[string] `json:"name"`
// The parent internal account for this account.
ParentAccountID param.Field[string] `json:"parent_account_id"`
}
func (r InternalAccountUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type InternalAccountListParams struct {
AfterCursor param.Field[string] `query:"after_cursor"`
// Only return internal accounts associated with this counterparty.
CounterpartyID param.Field[string] `query:"counterparty_id"`
// Only return internal accounts with this currency.
Currency param.Field[shared.Currency] `query:"currency"`
// Only return internal accounts associated with this legal entity.
LegalEntityID param.Field[string] `query:"legal_entity_id"`
// For example, if you want to query for records with metadata key `Type` and value
// `Loan`, the query would be `metadata%5BType%5D=Loan`. This encodes the query
// parameters.
Metadata param.Field[map[string]string] `query:"metadata"`
// Only return internal accounts that can originate payments with this direction.
PaymentDirection param.Field[shared.TransactionDirection] `query:"payment_direction"`
// Only return internal accounts that can make this type of payment.
PaymentType param.Field[InternalAccountListParamsPaymentType] `query:"payment_type"`
PerPage param.Field[int64] `query:"per_page"`
}
// URLQuery serializes [InternalAccountListParams]'s query parameters as
// `url.Values`.
func (r InternalAccountListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Only return internal accounts that can make this type of payment.
type InternalAccountListParamsPaymentType string
const (
InternalAccountListParamsPaymentTypeACH InternalAccountListParamsPaymentType = "ach"
InternalAccountListParamsPaymentTypeAuBecs InternalAccountListParamsPaymentType = "au_becs"
InternalAccountListParamsPaymentTypeBacs InternalAccountListParamsPaymentType = "bacs"
InternalAccountListParamsPaymentTypeBook InternalAccountListParamsPaymentType = "book"
InternalAccountListParamsPaymentTypeCard InternalAccountListParamsPaymentType = "card"
InternalAccountListParamsPaymentTypeChats InternalAccountListParamsPaymentType = "chats"
InternalAccountListParamsPaymentTypeCheck InternalAccountListParamsPaymentType = "check"
InternalAccountListParamsPaymentTypeCrossBorder InternalAccountListParamsPaymentType = "cross_border"
InternalAccountListParamsPaymentTypeDkNets InternalAccountListParamsPaymentType = "dk_nets"
InternalAccountListParamsPaymentTypeEft InternalAccountListParamsPaymentType = "eft"
InternalAccountListParamsPaymentTypeHuIcs InternalAccountListParamsPaymentType = "hu_ics"
InternalAccountListParamsPaymentTypeInterac InternalAccountListParamsPaymentType = "interac"
InternalAccountListParamsPaymentTypeMasav InternalAccountListParamsPaymentType = "masav"
InternalAccountListParamsPaymentTypeMxCcen InternalAccountListParamsPaymentType = "mx_ccen"
InternalAccountListParamsPaymentTypeNeft InternalAccountListParamsPaymentType = "neft"
InternalAccountListParamsPaymentTypeNics InternalAccountListParamsPaymentType = "nics"
InternalAccountListParamsPaymentTypeNzBecs InternalAccountListParamsPaymentType = "nz_becs"
InternalAccountListParamsPaymentTypePlElixir InternalAccountListParamsPaymentType = "pl_elixir"
InternalAccountListParamsPaymentTypeProvxchange InternalAccountListParamsPaymentType = "provxchange"
InternalAccountListParamsPaymentTypeRoSent InternalAccountListParamsPaymentType = "ro_sent"
InternalAccountListParamsPaymentTypeRtp InternalAccountListParamsPaymentType = "rtp"
InternalAccountListParamsPaymentTypeSeBankgirot InternalAccountListParamsPaymentType = "se_bankgirot"
InternalAccountListParamsPaymentTypeSen InternalAccountListParamsPaymentType = "sen"
InternalAccountListParamsPaymentTypeSepa InternalAccountListParamsPaymentType = "sepa"
InternalAccountListParamsPaymentTypeSgGiro InternalAccountListParamsPaymentType = "sg_giro"
InternalAccountListParamsPaymentTypeSic InternalAccountListParamsPaymentType = "sic"
InternalAccountListParamsPaymentTypeSignet InternalAccountListParamsPaymentType = "signet"
InternalAccountListParamsPaymentTypeSknbi InternalAccountListParamsPaymentType = "sknbi"
InternalAccountListParamsPaymentTypeWire InternalAccountListParamsPaymentType = "wire"
InternalAccountListParamsPaymentTypeZengin InternalAccountListParamsPaymentType = "zengin"
)
func (r InternalAccountListParamsPaymentType) IsKnown() bool {
switch r {
case InternalAccountListParamsPaymentTypeACH, InternalAccountListParamsPaymentTypeAuBecs, InternalAccountListParamsPaymentTypeBacs, InternalAccountListParamsPaymentTypeBook, InternalAccountListParamsPaymentTypeCard, InternalAccountListParamsPaymentTypeChats, InternalAccountListParamsPaymentTypeCheck, InternalAccountListParamsPaymentTypeCrossBorder, InternalAccountListParamsPaymentTypeDkNets, InternalAccountListParamsPaymentTypeEft, InternalAccountListParamsPaymentTypeHuIcs, InternalAccountListParamsPaymentTypeInterac, InternalAccountListParamsPaymentTypeMasav, InternalAccountListParamsPaymentTypeMxCcen, InternalAccountListParamsPaymentTypeNeft, InternalAccountListParamsPaymentTypeNics, InternalAccountListParamsPaymentTypeNzBecs, InternalAccountListParamsPaymentTypePlElixir, InternalAccountListParamsPaymentTypeProvxchange, InternalAccountListParamsPaymentTypeRoSent, InternalAccountListParamsPaymentTypeRtp, InternalAccountListParamsPaymentTypeSeBankgirot, InternalAccountListParamsPaymentTypeSen, InternalAccountListParamsPaymentTypeSepa, InternalAccountListParamsPaymentTypeSgGiro, InternalAccountListParamsPaymentTypeSic, InternalAccountListParamsPaymentTypeSignet, InternalAccountListParamsPaymentTypeSknbi, InternalAccountListParamsPaymentTypeWire, InternalAccountListParamsPaymentTypeZengin:
return true
}
return false
}