-
Notifications
You must be signed in to change notification settings - Fork 2
/
document.go
323 lines (289 loc) · 15.2 KB
/
document.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package moderntreasury
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/url"
"time"
"github.com/Modern-Treasury/modern-treasury-go/v2/internal/apiform"
"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"
)
// DocumentService 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 [NewDocumentService] method instead.
type DocumentService struct {
Options []option.RequestOption
}
// NewDocumentService 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 NewDocumentService(opts ...option.RequestOption) (r *DocumentService) {
r = &DocumentService{}
r.Options = opts
return
}
// Create a document.
func (r *DocumentService) New(ctx context.Context, body DocumentNewParams, opts ...option.RequestOption) (res *Document, err error) {
opts = append(r.Options[:], opts...)
path := "api/documents"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Get an existing document.
func (r *DocumentService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *Document, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("api/documents/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Get a list of documents.
func (r *DocumentService) List(ctx context.Context, query DocumentListParams, opts ...option.RequestOption) (res *pagination.Page[Document], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "api/documents"
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 documents.
func (r *DocumentService) ListAutoPaging(ctx context.Context, query DocumentListParams, opts ...option.RequestOption) *pagination.PageAutoPager[Document] {
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
type Document struct {
ID string `json:"id,required" format:"uuid"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
DiscardedAt time.Time `json:"discarded_at,required,nullable" format:"date-time"`
DocumentDetails []DocumentDocumentDetail `json:"document_details,required"`
// A category given to the document, can be `null`.
DocumentType string `json:"document_type,required,nullable"`
// The unique identifier for the associated object.
DocumentableID string `json:"documentable_id,required" format:"uuid"`
// The type of the associated object. Currently can be one of `payment_order`,
// `transaction`, `paper_item`, `expected_payment`, `counterparty`, `organization`,
// `case`, `internal_account`, `decision`, or `external_account`.
DocumentableType DocumentDocumentableType `json:"documentable_type,required"`
File DocumentFile `json:"file,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"`
Object string `json:"object,required"`
// The source of the document. Can be `vendor`, `customer`, or `modern_treasury`.
Source string `json:"source,required"`
UpdatedAt time.Time `json:"updated_at,required" format:"date-time"`
JSON documentJSON `json:"-"`
}
// documentJSON contains the JSON metadata for the struct [Document]
type documentJSON struct {
ID apijson.Field
CreatedAt apijson.Field
DiscardedAt apijson.Field
DocumentDetails apijson.Field
DocumentType apijson.Field
DocumentableID apijson.Field
DocumentableType apijson.Field
File apijson.Field
LiveMode apijson.Field
Object apijson.Field
Source apijson.Field
UpdatedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Document) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r documentJSON) RawJSON() string {
return r.raw
}
type DocumentDocumentDetail struct {
ID string `json:"id,required" format:"uuid"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
DiscardedAt time.Time `json:"discarded_at,required,nullable" format:"date-time"`
DocumentIdentifier string `json:"document_identifier,required"`
DocumentIdentifierType string `json:"document_identifier_type,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"`
Object string `json:"object,required"`
UpdatedAt time.Time `json:"updated_at,required" format:"date-time"`
JSON documentDocumentDetailJSON `json:"-"`
}
// documentDocumentDetailJSON contains the JSON metadata for the struct
// [DocumentDocumentDetail]
type documentDocumentDetailJSON struct {
ID apijson.Field
CreatedAt apijson.Field
DiscardedAt apijson.Field
DocumentIdentifier apijson.Field
DocumentIdentifierType apijson.Field
LiveMode apijson.Field
Object apijson.Field
UpdatedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DocumentDocumentDetail) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r documentDocumentDetailJSON) RawJSON() string {
return r.raw
}
// The type of the associated object. Currently can be one of `payment_order`,
// `transaction`, `paper_item`, `expected_payment`, `counterparty`, `organization`,
// `case`, `internal_account`, `decision`, or `external_account`.
type DocumentDocumentableType string
const (
DocumentDocumentableTypeCase DocumentDocumentableType = "case"
DocumentDocumentableTypeCounterparty DocumentDocumentableType = "counterparty"
DocumentDocumentableTypeExpectedPayment DocumentDocumentableType = "expected_payment"
DocumentDocumentableTypeExternalAccount DocumentDocumentableType = "external_account"
DocumentDocumentableTypeIncomingPaymentDetail DocumentDocumentableType = "incoming_payment_detail"
DocumentDocumentableTypeInternalAccount DocumentDocumentableType = "internal_account"
DocumentDocumentableTypeOrganization DocumentDocumentableType = "organization"
DocumentDocumentableTypePaperItem DocumentDocumentableType = "paper_item"
DocumentDocumentableTypePaymentOrder DocumentDocumentableType = "payment_order"
DocumentDocumentableTypeTransaction DocumentDocumentableType = "transaction"
DocumentDocumentableTypeDecision DocumentDocumentableType = "decision"
DocumentDocumentableTypeConnection DocumentDocumentableType = "connection"
)
func (r DocumentDocumentableType) IsKnown() bool {
switch r {
case DocumentDocumentableTypeCase, DocumentDocumentableTypeCounterparty, DocumentDocumentableTypeExpectedPayment, DocumentDocumentableTypeExternalAccount, DocumentDocumentableTypeIncomingPaymentDetail, DocumentDocumentableTypeInternalAccount, DocumentDocumentableTypeOrganization, DocumentDocumentableTypePaperItem, DocumentDocumentableTypePaymentOrder, DocumentDocumentableTypeTransaction, DocumentDocumentableTypeDecision, DocumentDocumentableTypeConnection:
return true
}
return false
}
type DocumentFile struct {
// The MIME content type of the document.
ContentType string `json:"content_type"`
// The original filename of the document.
Filename string `json:"filename"`
// The size of the document in bytes.
Size int64 `json:"size"`
JSON documentFileJSON `json:"-"`
}
// documentFileJSON contains the JSON metadata for the struct [DocumentFile]
type documentFileJSON struct {
ContentType apijson.Field
Filename apijson.Field
Size apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DocumentFile) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r documentFileJSON) RawJSON() string {
return r.raw
}
type DocumentNewParams struct {
// The unique identifier for the associated object.
DocumentableID param.Field[string] `json:"documentable_id,required"`
DocumentableType param.Field[DocumentNewParamsDocumentableType] `json:"documentable_type,required"`
File param.Field[io.Reader] `json:"file,required" format:"binary"`
// A category given to the document, can be `null`.
DocumentType param.Field[string] `json:"document_type"`
}
func (r DocumentNewParams) MarshalMultipart() (data []byte, contentType string, err error) {
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
err = apiform.MarshalRoot(r, writer)
if err != nil {
writer.Close()
return nil, "", err
}
err = writer.Close()
if err != nil {
return nil, "", err
}
return buf.Bytes(), writer.FormDataContentType(), nil
}
type DocumentNewParamsDocumentableType string
const (
DocumentNewParamsDocumentableTypeCases DocumentNewParamsDocumentableType = "cases"
DocumentNewParamsDocumentableTypeCounterparties DocumentNewParamsDocumentableType = "counterparties"
DocumentNewParamsDocumentableTypeExpectedPayments DocumentNewParamsDocumentableType = "expected_payments"
DocumentNewParamsDocumentableTypeExternalAccounts DocumentNewParamsDocumentableType = "external_accounts"
DocumentNewParamsDocumentableTypeIncomingPaymentDetails DocumentNewParamsDocumentableType = "incoming_payment_details"
DocumentNewParamsDocumentableTypeInternalAccounts DocumentNewParamsDocumentableType = "internal_accounts"
DocumentNewParamsDocumentableTypeOrganizations DocumentNewParamsDocumentableType = "organizations"
DocumentNewParamsDocumentableTypePaperItems DocumentNewParamsDocumentableType = "paper_items"
DocumentNewParamsDocumentableTypePaymentOrders DocumentNewParamsDocumentableType = "payment_orders"
DocumentNewParamsDocumentableTypeTransactions DocumentNewParamsDocumentableType = "transactions"
DocumentNewParamsDocumentableTypeDecisions DocumentNewParamsDocumentableType = "decisions"
DocumentNewParamsDocumentableTypeConnections DocumentNewParamsDocumentableType = "connections"
)
func (r DocumentNewParamsDocumentableType) IsKnown() bool {
switch r {
case DocumentNewParamsDocumentableTypeCases, DocumentNewParamsDocumentableTypeCounterparties, DocumentNewParamsDocumentableTypeExpectedPayments, DocumentNewParamsDocumentableTypeExternalAccounts, DocumentNewParamsDocumentableTypeIncomingPaymentDetails, DocumentNewParamsDocumentableTypeInternalAccounts, DocumentNewParamsDocumentableTypeOrganizations, DocumentNewParamsDocumentableTypePaperItems, DocumentNewParamsDocumentableTypePaymentOrders, DocumentNewParamsDocumentableTypeTransactions, DocumentNewParamsDocumentableTypeDecisions, DocumentNewParamsDocumentableTypeConnections:
return true
}
return false
}
type DocumentListParams struct {
AfterCursor param.Field[string] `query:"after_cursor"`
// The unique identifier for the associated object.
DocumentableID param.Field[string] `query:"documentable_id"`
// The type of the associated object. Currently can be one of `payment_order`,
// `transaction`, `paper_item`, `expected_payment`, `counterparty`, `organization`,
// `case`, `internal_account`, `decision`, or `external_account`.
DocumentableType param.Field[DocumentListParamsDocumentableType] `query:"documentable_type"`
PerPage param.Field[int64] `query:"per_page"`
}
// URLQuery serializes [DocumentListParams]'s query parameters as `url.Values`.
func (r DocumentListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// The type of the associated object. Currently can be one of `payment_order`,
// `transaction`, `paper_item`, `expected_payment`, `counterparty`, `organization`,
// `case`, `internal_account`, `decision`, or `external_account`.
type DocumentListParamsDocumentableType string
const (
DocumentListParamsDocumentableTypeCases DocumentListParamsDocumentableType = "cases"
DocumentListParamsDocumentableTypeCounterparties DocumentListParamsDocumentableType = "counterparties"
DocumentListParamsDocumentableTypeExpectedPayments DocumentListParamsDocumentableType = "expected_payments"
DocumentListParamsDocumentableTypeExternalAccounts DocumentListParamsDocumentableType = "external_accounts"
DocumentListParamsDocumentableTypeIncomingPaymentDetails DocumentListParamsDocumentableType = "incoming_payment_details"
DocumentListParamsDocumentableTypeInternalAccounts DocumentListParamsDocumentableType = "internal_accounts"
DocumentListParamsDocumentableTypeOrganizations DocumentListParamsDocumentableType = "organizations"
DocumentListParamsDocumentableTypePaperItems DocumentListParamsDocumentableType = "paper_items"
DocumentListParamsDocumentableTypePaymentOrders DocumentListParamsDocumentableType = "payment_orders"
DocumentListParamsDocumentableTypeTransactions DocumentListParamsDocumentableType = "transactions"
DocumentListParamsDocumentableTypeDecisions DocumentListParamsDocumentableType = "decisions"
DocumentListParamsDocumentableTypeConnections DocumentListParamsDocumentableType = "connections"
)
func (r DocumentListParamsDocumentableType) IsKnown() bool {
switch r {
case DocumentListParamsDocumentableTypeCases, DocumentListParamsDocumentableTypeCounterparties, DocumentListParamsDocumentableTypeExpectedPayments, DocumentListParamsDocumentableTypeExternalAccounts, DocumentListParamsDocumentableTypeIncomingPaymentDetails, DocumentListParamsDocumentableTypeInternalAccounts, DocumentListParamsDocumentableTypeOrganizations, DocumentListParamsDocumentableTypePaperItems, DocumentListParamsDocumentableTypePaymentOrders, DocumentListParamsDocumentableTypeTransactions, DocumentListParamsDocumentableTypeDecisions, DocumentListParamsDocumentableTypeConnections:
return true
}
return false
}