-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathledgertransactionversion.go
442 lines (400 loc) · 21.5 KB
/
ledgertransactionversion.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package moderntreasury
import (
"context"
"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"
)
// LedgerTransactionVersionService 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 [NewLedgerTransactionVersionService] method instead.
type LedgerTransactionVersionService struct {
Options []option.RequestOption
}
// NewLedgerTransactionVersionService 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 NewLedgerTransactionVersionService(opts ...option.RequestOption) (r *LedgerTransactionVersionService) {
r = &LedgerTransactionVersionService{}
r.Options = opts
return
}
// Get a list of ledger transaction versions.
func (r *LedgerTransactionVersionService) List(ctx context.Context, query LedgerTransactionVersionListParams, opts ...option.RequestOption) (res *pagination.Page[LedgerTransactionVersion], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "api/ledger_transaction_versions"
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
}
// Get a list of ledger transaction versions.
func (r *LedgerTransactionVersionService) ListAutoPaging(ctx context.Context, query LedgerTransactionVersionListParams, opts ...option.RequestOption) *pagination.PageAutoPager[LedgerTransactionVersion] {
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
type LedgerTransactionVersion struct {
ID string `json:"id,required" format:"uuid"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// An optional description for internal use.
Description string `json:"description,required,nullable"`
// The timestamp (ISO8601 format) at which the ledger transaction happened for
// reporting purposes.
EffectiveAt time.Time `json:"effective_at,required" format:"date-time"`
// The date (YYYY-MM-DD) on which the ledger transaction happened for reporting
// purposes.
EffectiveDate time.Time `json:"effective_date,required" format:"date"`
// A unique string to represent the ledger transaction. Only one pending or posted
// ledger transaction may have this ID in the ledger.
ExternalID string `json:"external_id,required,nullable"`
// An array of ledger entry objects.
LedgerEntries []LedgerTransactionVersionLedgerEntry `json:"ledger_entries,required"`
// The ID of the ledger this ledger transaction belongs to.
LedgerID string `json:"ledger_id,required" format:"uuid"`
// The ID of the ledger transaction
LedgerTransactionID string `json:"ledger_transaction_id,required" format:"uuid"`
// If the ledger transaction can be reconciled to another object in Modern
// Treasury, the id will be populated here, otherwise null.
LedgerableID string `json:"ledgerable_id,required,nullable" format:"uuid"`
// If the ledger transaction can be reconciled to another object in Modern
// Treasury, the type will be populated here, otherwise null. This can be one of
// payment_order, incoming_payment_detail, expected_payment, return, or reversal.
LedgerableType LedgerTransactionVersionLedgerableType `json:"ledgerable_type,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"`
// Additional data represented as key-value pairs. Both the key and value must be
// strings.
Metadata map[string]string `json:"metadata,required"`
Object string `json:"object,required"`
// The time on which the ledger transaction posted. This is null if the ledger
// transaction is pending.
PostedAt time.Time `json:"posted_at,required,nullable" format:"date-time"`
// The ID of the ledger transaction that reversed this ledger transaction.
ReversedByLedgerTransactionID string `json:"reversed_by_ledger_transaction_id,required,nullable"`
// The ID of the original ledger transaction. that this ledger transaction
// reverses.
ReversesLedgerTransactionID string `json:"reverses_ledger_transaction_id,required,nullable"`
// One of `pending`, `posted`, or `archived`.
Status LedgerTransactionVersionStatus `json:"status,required"`
// Version number of the ledger transaction.
Version int64 `json:"version,required"`
JSON ledgerTransactionVersionJSON `json:"-"`
}
// ledgerTransactionVersionJSON contains the JSON metadata for the struct
// [LedgerTransactionVersion]
type ledgerTransactionVersionJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Description apijson.Field
EffectiveAt apijson.Field
EffectiveDate apijson.Field
ExternalID apijson.Field
LedgerEntries apijson.Field
LedgerID apijson.Field
LedgerTransactionID apijson.Field
LedgerableID apijson.Field
LedgerableType apijson.Field
LiveMode apijson.Field
Metadata apijson.Field
Object apijson.Field
PostedAt apijson.Field
ReversedByLedgerTransactionID apijson.Field
ReversesLedgerTransactionID apijson.Field
Status apijson.Field
Version apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LedgerTransactionVersion) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r ledgerTransactionVersionJSON) RawJSON() string {
return r.raw
}
type LedgerTransactionVersionLedgerEntry struct {
ID string `json:"id,required" format:"uuid"`
// Value in specified currency's smallest unit. e.g. $10 would be represented
// as 1000. Can be any integer up to 36 digits.
Amount int64 `json:"amount,required"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// One of `credit`, `debit`. Describes the direction money is flowing in the
// transaction. A `credit` moves money from your account to someone else's. A
// `debit` pulls money from someone else's account to your own. Note that wire,
// rtp, and check payments will always be `credit`.
Direction shared.TransactionDirection `json:"direction,required"`
// The currency of the ledger account.
LedgerAccountCurrency string `json:"ledger_account_currency,required"`
// The currency exponent of the ledger account.
LedgerAccountCurrencyExponent int64 `json:"ledger_account_currency_exponent,required"`
// The ledger account that this ledger entry is associated with.
LedgerAccountID string `json:"ledger_account_id,required" format:"uuid"`
// Lock version of the ledger account. This can be passed when creating a ledger
// transaction to only succeed if no ledger transactions have posted since the
// given version. See our post about Designing the Ledgers API with Optimistic
// Locking for more details.
LedgerAccountLockVersion int64 `json:"ledger_account_lock_version,required,nullable"`
// The ledger transaction that this ledger entry is associated with.
LedgerTransactionID string `json:"ledger_transaction_id,required"`
// 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"`
Object string `json:"object,required"`
// The pending, posted, and available balances for this ledger entry's ledger
// account. The posted balance is the sum of all posted entries on the account. The
// pending balance is the sum of all pending and posted entries on the account. The
// available balance is the posted incoming entries minus the sum of the pending
// and posted outgoing amounts. Please see
// https://docs.moderntreasury.com/docs/transaction-status-and-balances for more
// details.
ResultingLedgerAccountBalances LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalances `json:"resulting_ledger_account_balances,required,nullable"`
// Equal to the state of the ledger transaction when the ledger entry was created.
// One of `pending`, `posted`, or `archived`.
Status LedgerTransactionVersionLedgerEntriesStatus `json:"status,required"`
JSON ledgerTransactionVersionLedgerEntryJSON `json:"-"`
}
// ledgerTransactionVersionLedgerEntryJSON contains the JSON metadata for the
// struct [LedgerTransactionVersionLedgerEntry]
type ledgerTransactionVersionLedgerEntryJSON struct {
ID apijson.Field
Amount apijson.Field
CreatedAt apijson.Field
Direction apijson.Field
LedgerAccountCurrency apijson.Field
LedgerAccountCurrencyExponent apijson.Field
LedgerAccountID apijson.Field
LedgerAccountLockVersion apijson.Field
LedgerTransactionID apijson.Field
LiveMode apijson.Field
Metadata apijson.Field
Object apijson.Field
ResultingLedgerAccountBalances apijson.Field
Status apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LedgerTransactionVersionLedgerEntry) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r ledgerTransactionVersionLedgerEntryJSON) RawJSON() string {
return r.raw
}
// The pending, posted, and available balances for this ledger entry's ledger
// account. The posted balance is the sum of all posted entries on the account. The
// pending balance is the sum of all pending and posted entries on the account. The
// available balance is the posted incoming entries minus the sum of the pending
// and posted outgoing amounts. Please see
// https://docs.moderntreasury.com/docs/transaction-status-and-balances for more
// details.
type LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalances struct {
// The available_balance is the sum of all posted inbound entries and pending
// outbound entries. For credit normal, available_amount = posted_credits -
// pending_debits; for debit normal, available_amount = posted_debits -
// pending_credits.
AvailableBalance LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesAvailableBalance `json:"available_balance,required"`
// The pending_balance is the sum of all pending and posted entries.
PendingBalance LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPendingBalance `json:"pending_balance,required"`
// The posted_balance is the sum of all posted entries.
PostedBalance LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPostedBalance `json:"posted_balance,required"`
JSON ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesJSON `json:"-"`
}
// ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesJSON contains
// the JSON metadata for the struct
// [LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalances]
type ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesJSON struct {
AvailableBalance apijson.Field
PendingBalance apijson.Field
PostedBalance apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalances) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesJSON) RawJSON() string {
return r.raw
}
// The available_balance is the sum of all posted inbound entries and pending
// outbound entries. For credit normal, available_amount = posted_credits -
// pending_debits; for debit normal, available_amount = posted_debits -
// pending_credits.
type LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesAvailableBalance struct {
Amount int64 `json:"amount,required"`
Credits int64 `json:"credits,required"`
// The currency of the ledger account.
Currency string `json:"currency,required"`
// The currency exponent of the ledger account.
CurrencyExponent int64 `json:"currency_exponent,required"`
Debits int64 `json:"debits,required"`
JSON ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesAvailableBalanceJSON `json:"-"`
}
// ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesAvailableBalanceJSON
// contains the JSON metadata for the struct
// [LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesAvailableBalance]
type ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesAvailableBalanceJSON struct {
Amount apijson.Field
Credits apijson.Field
Currency apijson.Field
CurrencyExponent apijson.Field
Debits apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesAvailableBalance) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesAvailableBalanceJSON) RawJSON() string {
return r.raw
}
// The pending_balance is the sum of all pending and posted entries.
type LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPendingBalance struct {
Amount int64 `json:"amount,required"`
Credits int64 `json:"credits,required"`
// The currency of the ledger account.
Currency string `json:"currency,required"`
// The currency exponent of the ledger account.
CurrencyExponent int64 `json:"currency_exponent,required"`
Debits int64 `json:"debits,required"`
JSON ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPendingBalanceJSON `json:"-"`
}
// ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPendingBalanceJSON
// contains the JSON metadata for the struct
// [LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPendingBalance]
type ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPendingBalanceJSON struct {
Amount apijson.Field
Credits apijson.Field
Currency apijson.Field
CurrencyExponent apijson.Field
Debits apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPendingBalance) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPendingBalanceJSON) RawJSON() string {
return r.raw
}
// The posted_balance is the sum of all posted entries.
type LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPostedBalance struct {
Amount int64 `json:"amount,required"`
Credits int64 `json:"credits,required"`
// The currency of the ledger account.
Currency string `json:"currency,required"`
// The currency exponent of the ledger account.
CurrencyExponent int64 `json:"currency_exponent,required"`
Debits int64 `json:"debits,required"`
JSON ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPostedBalanceJSON `json:"-"`
}
// ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPostedBalanceJSON
// contains the JSON metadata for the struct
// [LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPostedBalance]
type ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPostedBalanceJSON struct {
Amount apijson.Field
Credits apijson.Field
Currency apijson.Field
CurrencyExponent apijson.Field
Debits apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LedgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPostedBalance) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r ledgerTransactionVersionLedgerEntriesResultingLedgerAccountBalancesPostedBalanceJSON) RawJSON() string {
return r.raw
}
// Equal to the state of the ledger transaction when the ledger entry was created.
// One of `pending`, `posted`, or `archived`.
type LedgerTransactionVersionLedgerEntriesStatus string
const (
LedgerTransactionVersionLedgerEntriesStatusArchived LedgerTransactionVersionLedgerEntriesStatus = "archived"
LedgerTransactionVersionLedgerEntriesStatusPending LedgerTransactionVersionLedgerEntriesStatus = "pending"
LedgerTransactionVersionLedgerEntriesStatusPosted LedgerTransactionVersionLedgerEntriesStatus = "posted"
)
func (r LedgerTransactionVersionLedgerEntriesStatus) IsKnown() bool {
switch r {
case LedgerTransactionVersionLedgerEntriesStatusArchived, LedgerTransactionVersionLedgerEntriesStatusPending, LedgerTransactionVersionLedgerEntriesStatusPosted:
return true
}
return false
}
// If the ledger transaction can be reconciled to another object in Modern
// Treasury, the type will be populated here, otherwise null. This can be one of
// payment_order, incoming_payment_detail, expected_payment, return, or reversal.
type LedgerTransactionVersionLedgerableType string
const (
LedgerTransactionVersionLedgerableTypeExpectedPayment LedgerTransactionVersionLedgerableType = "expected_payment"
LedgerTransactionVersionLedgerableTypeIncomingPaymentDetail LedgerTransactionVersionLedgerableType = "incoming_payment_detail"
LedgerTransactionVersionLedgerableTypePaperItem LedgerTransactionVersionLedgerableType = "paper_item"
LedgerTransactionVersionLedgerableTypePaymentOrder LedgerTransactionVersionLedgerableType = "payment_order"
LedgerTransactionVersionLedgerableTypeReturn LedgerTransactionVersionLedgerableType = "return"
LedgerTransactionVersionLedgerableTypeReversal LedgerTransactionVersionLedgerableType = "reversal"
)
func (r LedgerTransactionVersionLedgerableType) IsKnown() bool {
switch r {
case LedgerTransactionVersionLedgerableTypeExpectedPayment, LedgerTransactionVersionLedgerableTypeIncomingPaymentDetail, LedgerTransactionVersionLedgerableTypePaperItem, LedgerTransactionVersionLedgerableTypePaymentOrder, LedgerTransactionVersionLedgerableTypeReturn, LedgerTransactionVersionLedgerableTypeReversal:
return true
}
return false
}
// One of `pending`, `posted`, or `archived`.
type LedgerTransactionVersionStatus string
const (
LedgerTransactionVersionStatusArchived LedgerTransactionVersionStatus = "archived"
LedgerTransactionVersionStatusPending LedgerTransactionVersionStatus = "pending"
LedgerTransactionVersionStatusPosted LedgerTransactionVersionStatus = "posted"
)
func (r LedgerTransactionVersionStatus) IsKnown() bool {
switch r {
case LedgerTransactionVersionStatusArchived, LedgerTransactionVersionStatusPending, LedgerTransactionVersionStatusPosted:
return true
}
return false
}
type LedgerTransactionVersionListParams struct {
AfterCursor param.Field[string] `query:"after_cursor"`
// Use `gt` (>), `gte` (>=), `lt` (<), `lte` (<=), or `eq` (=) to filter by the
// created_at timestamp. For example, for all dates after Jan 1 2000 12:00 UTC, use
// created_at%5Bgt%5D=2000-01-01T12:00:00Z.
CreatedAt param.Field[map[string]time.Time] `query:"created_at" format:"date-time"`
// Get all ledger transaction versions that are included in the ledger account
// statement.
LedgerAccountStatementID param.Field[string] `query:"ledger_account_statement_id"`
// Get all the ledger transaction versions corresponding to the ID of a ledger
// transaction.
LedgerTransactionID param.Field[string] `query:"ledger_transaction_id"`
PerPage param.Field[int64] `query:"per_page"`
// Use `gt` (>), `gte` (>=), `lt` (<), `lte` (<=), or `eq` (=) to filter by the
// version. For example, for all versions after 2, use version%5Bgt%5D=2.
Version param.Field[map[string]int64] `query:"version"`
}
// URLQuery serializes [LedgerTransactionVersionListParams]'s query parameters as
// `url.Values`.
func (r LedgerTransactionVersionListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}