-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinvoicelineitem.go
257 lines (236 loc) · 10.3 KB
/
invoicelineitem.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
// 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"
)
// InvoiceLineItemService 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 [NewInvoiceLineItemService] method instead.
type InvoiceLineItemService struct {
Options []option.RequestOption
}
// NewInvoiceLineItemService 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 NewInvoiceLineItemService(opts ...option.RequestOption) (r *InvoiceLineItemService) {
r = &InvoiceLineItemService{}
r.Options = opts
return
}
// create invoice_line_item
func (r *InvoiceLineItemService) New(ctx context.Context, invoiceID string, body InvoiceLineItemNewParams, opts ...option.RequestOption) (res *InvoiceLineItem, err error) {
opts = append(r.Options[:], opts...)
if invoiceID == "" {
err = errors.New("missing required invoice_id parameter")
return
}
path := fmt.Sprintf("api/invoices/%s/invoice_line_items", invoiceID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// get invoice_line_item
func (r *InvoiceLineItemService) Get(ctx context.Context, invoiceID string, id string, opts ...option.RequestOption) (res *InvoiceLineItem, err error) {
opts = append(r.Options[:], opts...)
if invoiceID == "" {
err = errors.New("missing required invoice_id parameter")
return
}
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("api/invoices/%s/invoice_line_items/%s", invoiceID, id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// update invoice_line_item
func (r *InvoiceLineItemService) Update(ctx context.Context, invoiceID string, id string, body InvoiceLineItemUpdateParams, opts ...option.RequestOption) (res *InvoiceLineItem, err error) {
opts = append(r.Options[:], opts...)
if invoiceID == "" {
err = errors.New("missing required invoice_id parameter")
return
}
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("api/invoices/%s/invoice_line_items/%s", invoiceID, id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
return
}
// list invoice_line_items
func (r *InvoiceLineItemService) List(ctx context.Context, invoiceID string, query InvoiceLineItemListParams, opts ...option.RequestOption) (res *pagination.Page[InvoiceLineItem], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if invoiceID == "" {
err = errors.New("missing required invoice_id parameter")
return
}
path := fmt.Sprintf("api/invoices/%s/invoice_line_items", invoiceID)
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 invoice_line_items
func (r *InvoiceLineItemService) ListAutoPaging(ctx context.Context, invoiceID string, query InvoiceLineItemListParams, opts ...option.RequestOption) *pagination.PageAutoPager[InvoiceLineItem] {
return pagination.NewPageAutoPager(r.List(ctx, invoiceID, query, opts...))
}
// delete invoice_line_item
func (r *InvoiceLineItemService) Delete(ctx context.Context, invoiceID string, id string, opts ...option.RequestOption) (res *InvoiceLineItem, err error) {
opts = append(r.Options[:], opts...)
if invoiceID == "" {
err = errors.New("missing required invoice_id parameter")
return
}
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("api/invoices/%s/invoice_line_items/%s", invoiceID, id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
type InvoiceLineItem struct {
ID string `json:"id,required" format:"uuid"`
// The total amount for this line item specified in the invoice currency's smallest
// unit.
Amount int64 `json:"amount,required"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// An optional free-form description of the line item.
Description string `json:"description,required"`
// Either `debit` or `credit`. `debit` indicates that a client owes the business
// money and increases the invoice's `total_amount` due. `credit` has the opposite
// intention and effect.
Direction string `json:"direction,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"`
// The name of the line item, typically a product or SKU name.
Name string `json:"name,required"`
Object string `json:"object,required"`
// The number of units of a product or service that this line item is for. Must be
// a whole number. Defaults to 1 if not provided.
Quantity int64 `json:"quantity,required"`
// The cost per unit of the product or service that this line item is for,
// specified in the invoice currency's smallest unit.
UnitAmount int64 `json:"unit_amount,required"`
// The cost per unit of the product or service that this line item is for,
// specified in the invoice currency's smallest unit. Accepts decimal strings with
// up to 12 decimals
UnitAmountDecimal string `json:"unit_amount_decimal,required"`
UpdatedAt time.Time `json:"updated_at,required" format:"date-time"`
JSON invoiceLineItemJSON `json:"-"`
}
// invoiceLineItemJSON contains the JSON metadata for the struct [InvoiceLineItem]
type invoiceLineItemJSON struct {
ID apijson.Field
Amount apijson.Field
CreatedAt apijson.Field
Description apijson.Field
Direction apijson.Field
LiveMode apijson.Field
Metadata apijson.Field
Name apijson.Field
Object apijson.Field
Quantity apijson.Field
UnitAmount apijson.Field
UnitAmountDecimal apijson.Field
UpdatedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *InvoiceLineItem) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r invoiceLineItemJSON) RawJSON() string {
return r.raw
}
type InvoiceLineItemNewParams struct {
// The name of the line item, typically a product or SKU name.
Name param.Field[string] `json:"name,required"`
// The cost per unit of the product or service that this line item is for,
// specified in the invoice currency's smallest unit.
UnitAmount param.Field[int64] `json:"unit_amount,required"`
// An optional free-form description of the line item.
Description param.Field[string] `json:"description"`
// Either `debit` or `credit`. `debit` indicates that a client owes the business
// money and increases the invoice's `total_amount` due. `credit` has the opposite
// intention and effect.
Direction param.Field[string] `json:"direction"`
// Additional data represented as key-value pairs. Both the key and value must be
// strings.
Metadata param.Field[map[string]string] `json:"metadata"`
// The number of units of a product or service that this line item is for. Must be
// a whole number. Defaults to 1 if not provided.
Quantity param.Field[int64] `json:"quantity"`
// The cost per unit of the product or service that this line item is for,
// specified in the invoice currency's smallest unit. Accepts decimal strings with
// up to 12 decimals
UnitAmountDecimal param.Field[string] `json:"unit_amount_decimal"`
}
func (r InvoiceLineItemNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type InvoiceLineItemUpdateParams struct {
// An optional free-form description of the line item.
Description param.Field[string] `json:"description"`
// Either `debit` or `credit`. `debit` indicates that a client owes the business
// money and increases the invoice's `total_amount` due. `credit` has the opposite
// intention and effect.
Direction param.Field[string] `json:"direction"`
// Additional data represented as key-value pairs. Both the key and value must be
// strings.
Metadata param.Field[map[string]string] `json:"metadata"`
// The name of the line item, typically a product or SKU name.
Name param.Field[string] `json:"name"`
// The number of units of a product or service that this line item is for. Must be
// a whole number. Defaults to 1 if not provided.
Quantity param.Field[int64] `json:"quantity"`
// The cost per unit of the product or service that this line item is for,
// specified in the invoice currency's smallest unit.
UnitAmount param.Field[int64] `json:"unit_amount"`
// The cost per unit of the product or service that this line item is for,
// specified in the invoice currency's smallest unit. Accepts decimal strings with
// up to 12 decimals
UnitAmountDecimal param.Field[string] `json:"unit_amount_decimal"`
}
func (r InvoiceLineItemUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type InvoiceLineItemListParams struct {
AfterCursor param.Field[string] `query:"after_cursor"`
PerPage param.Field[int64] `query:"per_page"`
}
// URLQuery serializes [InvoiceLineItemListParams]'s query parameters as
// `url.Values`.
func (r InvoiceLineItemListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}