-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.go
340 lines (300 loc) · 12.4 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
// File generated from our OpenAPI spec by Stainless.
package acme
import (
"context"
"fmt"
"net/http"
"net/url"
"time"
"github.com/acme/acme-go/internal/apijson"
"github.com/acme/acme-go/internal/apiquery"
"github.com/acme/acme-go/internal/param"
"github.com/acme/acme-go/internal/requestconfig"
"github.com/acme/acme-go/internal/shared"
"github.com/acme/acme-go/option"
)
// AccountService contains methods and other services that help with interacting
// with the acme 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
}
// Create an Account
func (r *AccountService) New(ctx context.Context, body AccountNewParams, opts ...option.RequestOption) (res *Account, err error) {
opts = append(r.Options[:], opts...)
path := "accounts"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Retrieve an Account
func (r *AccountService) Get(ctx context.Context, accountID string, opts ...option.RequestOption) (res *Account, err error) {
opts = append(r.Options[:], opts...)
path := fmt.Sprintf("accounts/%s", accountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Update an Account
func (r *AccountService) Update(ctx context.Context, accountID string, body AccountUpdateParams, opts ...option.RequestOption) (res *Account, err error) {
opts = append(r.Options[:], opts...)
path := fmt.Sprintf("accounts/%s", accountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
return
}
// List Accounts
func (r *AccountService) List(ctx context.Context, query AccountListParams, opts ...option.RequestOption) (res *shared.Page[Account], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "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 Accounts
func (r *AccountService) ListAutoPaging(ctx context.Context, query AccountListParams, opts ...option.RequestOption) *shared.PageAutoPager[Account] {
return shared.NewPageAutoPager(r.List(ctx, query, opts...))
}
// Retrieve an Account Balance
func (r *AccountService) Balance(ctx context.Context, accountID string, query AccountBalanceParams, opts ...option.RequestOption) (res *BalanceLookup, err error) {
opts = append(r.Options[:], opts...)
path := fmt.Sprintf("accounts/%s/balance", accountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return
}
// Close an Account
func (r *AccountService) Close(ctx context.Context, accountID string, opts ...option.RequestOption) (res *Account, err error) {
opts = append(r.Options[:], opts...)
path := fmt.Sprintf("accounts/%s/close", accountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
}
// Accounts are your bank accounts with Acme. They store money, receive
// transfers, and send payments. They earn interest and have depository insurance.
type Account struct {
// The Account identifier.
ID string `json:"id,required"`
// The bank the Account is with.
Bank AccountBank `json:"bank,required"`
// The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) time at which the Account
// was created.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) code for the Account
// currency.
Currency AccountCurrency `json:"currency,required"`
// The identifier for the Entity the Account belongs to.
EntityID string `json:"entity_id,required,nullable"`
// The identifier of an Entity that, while not owning the Account, is associated
// with its activity.
InformationalEntityID string `json:"informational_entity_id,required,nullable"`
// The interest accrued but not yet paid, expressed as a string containing a
// floating-point value.
InterestAccrued string `json:"interest_accrued,required"`
// The latest [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date on which
// interest was accrued.
InterestAccruedAt time.Time `json:"interest_accrued_at,required,nullable" format:"date"`
// The Interest Rate currently being earned on the account, as a string containing
// a decimal number. For example, a 1% interest rate would be represented as
// "0.01".
InterestRate string `json:"interest_rate,required"`
// The name you choose for the Account.
Name string `json:"name,required"`
// The status of the Account.
Status AccountStatus `json:"status,required"`
// A constant representing the object's type. For this resource it will always be
// `account`.
Type AccountType `json:"type,required"`
JSON accountJSON `json:"-"`
}
// accountJSON contains the JSON metadata for the struct [Account]
type accountJSON struct {
ID apijson.Field
Bank apijson.Field
CreatedAt apijson.Field
Currency apijson.Field
EntityID apijson.Field
InformationalEntityID apijson.Field
InterestAccrued apijson.Field
InterestAccruedAt apijson.Field
InterestRate apijson.Field
Name apijson.Field
Status apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Account) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
// The bank the Account is with.
type AccountBank string
const (
// Blue Ridge Bank, N.A.
AccountBankBlueRidgeBank AccountBank = "blue_ridge_bank"
// First Internet Bank of Indiana
AccountBankFirstInternetBank AccountBank = "first_internet_bank"
)
// The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) code for the Account
// currency.
type AccountCurrency string
const (
// Canadian Dollar (CAD)
AccountCurrencyCad AccountCurrency = "CAD"
// Swiss Franc (CHF)
AccountCurrencyChf AccountCurrency = "CHF"
// Euro (EUR)
AccountCurrencyEur AccountCurrency = "EUR"
// British Pound (GBP)
AccountCurrencyGbp AccountCurrency = "GBP"
// Japanese Yen (JPY)
AccountCurrencyJpy AccountCurrency = "JPY"
// US Dollar (USD)
AccountCurrencyUsd AccountCurrency = "USD"
)
// The status of the Account.
type AccountStatus string
const (
// Open Accounts that are ready to use.
AccountStatusOpen AccountStatus = "open"
// Closed Accounts on which no new activity can occur.
AccountStatusClosed AccountStatus = "closed"
)
// A constant representing the object's type. For this resource it will always be
// `account`.
type AccountType string
const (
AccountTypeAccount AccountType = "account"
)
// Represents a request to lookup the balance of an Account at a given point in
// time.
type BalanceLookup struct {
// The identifier for the account for which the balance was queried.
AccountID string `json:"account_id,required"`
// The Account's available balance, representing the current balance less any open
// Pending Transactions on the Account.
AvailableBalance int64 `json:"available_balance,required"`
// The Account's current balance, representing the sum of all posted Transactions
// on the Account.
CurrentBalance int64 `json:"current_balance,required"`
// A constant representing the object's type. For this resource it will always be
// `balance_lookup`.
Type BalanceLookupType `json:"type,required"`
JSON balanceLookupJSON `json:"-"`
}
// balanceLookupJSON contains the JSON metadata for the struct [BalanceLookup]
type balanceLookupJSON struct {
AccountID apijson.Field
AvailableBalance apijson.Field
CurrentBalance apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BalanceLookup) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
// A constant representing the object's type. For this resource it will always be
// `balance_lookup`.
type BalanceLookupType string
const (
BalanceLookupTypeBalanceLookup BalanceLookupType = "balance_lookup"
)
type AccountNewParams struct {
// The name you choose for the Account.
Name param.Field[string] `json:"name,required"`
// The identifier for the Entity that will own the Account.
EntityID param.Field[string] `json:"entity_id"`
// The identifier of an Entity that, while not owning the Account, is associated
// with its activity. Its relationship to your group must be `informational`.
InformationalEntityID param.Field[string] `json:"informational_entity_id"`
// The identifier for the Program that this Account falls under. Required if you
// operate more than one Program.
ProgramID param.Field[string] `json:"program_id"`
}
func (r AccountNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type AccountUpdateParams struct {
// The new name of the Account.
Name param.Field[string] `json:"name"`
}
func (r AccountUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type AccountListParams struct {
CreatedAt param.Field[AccountListParamsCreatedAt] `query:"created_at"`
// Return the page of entries after this one.
Cursor param.Field[string] `query:"cursor"`
// Filter Accounts for those belonging to the specified Entity.
EntityID param.Field[string] `query:"entity_id"`
// Filter Accounts for those belonging to the specified Entity as informational.
InformationalEntityID param.Field[string] `query:"informational_entity_id"`
// Limit the size of the list that is returned. The default (and maximum) is 100
// objects.
Limit param.Field[int64] `query:"limit"`
// Filter Accounts for those with the specified status.
Status param.Field[AccountListParamsStatus] `query:"status"`
}
// 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.NestedQueryFormatDots,
})
}
type AccountListParamsCreatedAt 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 [AccountListParamsCreatedAt]'s query parameters as
// `url.Values`.
func (r AccountListParamsCreatedAt) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
// Filter Accounts for those with the specified status.
type AccountListParamsStatus string
const (
// Open Accounts that are ready to use.
AccountListParamsStatusOpen AccountListParamsStatus = "open"
// Closed Accounts on which no new activity can occur.
AccountListParamsStatusClosed AccountListParamsStatus = "closed"
)
type AccountBalanceParams struct {
// The moment to query the balance at. If not set, returns the current balances.
AtTime param.Field[time.Time] `query:"at_time" format:"date-time"`
}
// URLQuery serializes [AccountBalanceParams]'s query parameters as `url.Values`.
func (r AccountBalanceParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}