-
Notifications
You must be signed in to change notification settings - Fork 2
/
paperitem.go
182 lines (165 loc) · 6.93 KB
/
paperitem.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
// 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"
)
// PaperItemService 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 [NewPaperItemService] method instead.
type PaperItemService struct {
Options []option.RequestOption
}
// NewPaperItemService 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 NewPaperItemService(opts ...option.RequestOption) (r *PaperItemService) {
r = &PaperItemService{}
r.Options = opts
return
}
// Get details on a single paper item.
func (r *PaperItemService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *PaperItem, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("api/paper_items/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Get a list of all paper items.
func (r *PaperItemService) List(ctx context.Context, query PaperItemListParams, opts ...option.RequestOption) (res *pagination.Page[PaperItem], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "api/paper_items"
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 all paper items.
func (r *PaperItemService) ListAutoPaging(ctx context.Context, query PaperItemListParams, opts ...option.RequestOption) *pagination.PageAutoPager[PaperItem] {
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
type PaperItem struct {
ID string `json:"id,required" format:"uuid"`
// The account number on the paper item.
AccountNumber string `json:"account_number,required,nullable"`
// The last 4 digits of the account_number.
AccountNumberSafe string `json:"account_number_safe,required,nullable"`
// The amount of the paper item.
Amount int64 `json:"amount,required"`
// The check number on the paper item.
CheckNumber string `json:"check_number,required,nullable"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// The currency of the paper item.
Currency shared.Currency `json:"currency,required"`
// The date the paper item was deposited into your organization's bank account.
DepositDate time.Time `json:"deposit_date,required" format:"date"`
// 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"`
// The identifier for the lockbox assigned by the bank.
LockboxNumber string `json:"lockbox_number,required"`
// The memo field on the paper item.
MemoField string `json:"memo_field,required,nullable"`
Object string `json:"object,required"`
// The name of the remitter on the paper item.
RemitterName string `json:"remitter_name,required,nullable"`
// The routing number on the paper item.
RoutingNumber string `json:"routing_number,required,nullable"`
// The current status of the paper item. One of `pending`, `completed`, or
// `returned`.
Status PaperItemStatus `json:"status,required"`
// The ID of the reconciled Transaction or `null`.
TransactionID string `json:"transaction_id,required,nullable" format:"uuid"`
// The ID of the reconciled Transaction Line Item or `null`.
TransactionLineItemID string `json:"transaction_line_item_id,required,nullable" format:"uuid"`
UpdatedAt time.Time `json:"updated_at,required" format:"date-time"`
JSON paperItemJSON `json:"-"`
}
// paperItemJSON contains the JSON metadata for the struct [PaperItem]
type paperItemJSON struct {
ID apijson.Field
AccountNumber apijson.Field
AccountNumberSafe apijson.Field
Amount apijson.Field
CheckNumber apijson.Field
CreatedAt apijson.Field
Currency apijson.Field
DepositDate apijson.Field
LiveMode apijson.Field
LockboxNumber apijson.Field
MemoField apijson.Field
Object apijson.Field
RemitterName apijson.Field
RoutingNumber apijson.Field
Status apijson.Field
TransactionID apijson.Field
TransactionLineItemID apijson.Field
UpdatedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PaperItem) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r paperItemJSON) RawJSON() string {
return r.raw
}
// The current status of the paper item. One of `pending`, `completed`, or
// `returned`.
type PaperItemStatus string
const (
PaperItemStatusCompleted PaperItemStatus = "completed"
PaperItemStatusPending PaperItemStatus = "pending"
PaperItemStatusReturned PaperItemStatus = "returned"
)
func (r PaperItemStatus) IsKnown() bool {
switch r {
case PaperItemStatusCompleted, PaperItemStatusPending, PaperItemStatusReturned:
return true
}
return false
}
type PaperItemListParams struct {
AfterCursor param.Field[string] `query:"after_cursor"`
// Specify an inclusive end date (YYYY-MM-DD) when filtering by deposit_date
DepositDateEnd param.Field[time.Time] `query:"deposit_date_end" format:"date"`
// Specify an inclusive start date (YYYY-MM-DD) when filtering by deposit_date
DepositDateStart param.Field[time.Time] `query:"deposit_date_start" format:"date"`
// Specify `lockbox_number` if you wish to see paper items that are associated with
// a specific lockbox number.
LockboxNumber param.Field[string] `query:"lockbox_number"`
PerPage param.Field[int64] `query:"per_page"`
}
// URLQuery serializes [PaperItemListParams]'s query parameters as `url.Values`.
func (r PaperItemListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}