-
Notifications
You must be signed in to change notification settings - Fork 0
/
reports.go
357 lines (301 loc) · 15.1 KB
/
reports.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
// Code generated by the Paddle SDK Generator; DO NOT EDIT.
package paddle
import (
"context"
"encoding/json"
paddleerr "github.com/PaddleHQ/paddle-go-sdk/pkg/paddleerr"
)
// ErrReportCreationLimitExceeded represents a `report_creation_limit_exceeded` error.
// See https://developer.paddle.com/errors/reports/report_creation_limit_exceeded for more information.
var ErrReportCreationLimitExceeded = &paddleerr.Error{
Code: "report_creation_limit_exceeded",
Type: paddleerr.ErrorTypeRequestError,
}
// ErrReportNotReady represents a `report_not_ready` error.
// See https://developer.paddle.com/errors/reports/report_not_ready for more information.
var ErrReportNotReady = &paddleerr.Error{
Code: "report_not_ready",
Type: paddleerr.ErrorTypeRequestError,
}
// ErrReportExpired represents a `report_expired` error.
// See https://developer.paddle.com/errors/reports/report_expired for more information.
var ErrReportExpired = &paddleerr.Error{
Code: "report_expired",
Type: paddleerr.ErrorTypeRequestError,
}
// ErrReportFailed represents a `report_failed` error.
// See https://developer.paddle.com/errors/reports/report_failed for more information.
var ErrReportFailed = &paddleerr.Error{
Code: "report_failed",
Type: paddleerr.ErrorTypeRequestError,
}
/*
ReportStatus: Status of this report. Set automatically by Paddle.
Reports are created as `pending` initially, then move to `ready` when they're available to download..
*/
type ReportStatus string
const (
ReportStatusPending ReportStatus = "pending"
ReportStatusReady ReportStatus = "ready"
ReportStatusFailed ReportStatus = "failed"
ReportStatusExpired ReportStatus = "expired"
)
// ReportTypeTransactions: Type of report..
type ReportTypeTransactions string
const (
ReportTypeTransactionsAdjustments ReportTypeTransactions = "adjustments"
ReportTypeTransactionsAdjustmentLineItems ReportTypeTransactions = "adjustment_line_items"
ReportTypeTransactionsTransactions ReportTypeTransactions = "transactions"
ReportTypeTransactionsTransactionLineItems ReportTypeTransactions = "transaction_line_items"
ReportTypeTransactionsProductsPrices ReportTypeTransactions = "products_prices"
ReportTypeTransactionsDiscounts ReportTypeTransactions = "discounts"
)
// Name: Field name to filter by..
type ReportsName string
const (
ReportsNameAction ReportsName = "action"
ReportsNameCurrencyCode ReportsName = "currency_code"
ReportsNameStatus ReportsName = "status"
ReportsNameUpdatedAt ReportsName = "updated_at"
ReportsNameCollectionMode ReportsName = "collection_mode"
ReportsNameOrigin ReportsName = "origin"
ReportsNameProductStatus ReportsName = "product_status"
ReportsNamePriceStatus ReportsName = "price_status"
ReportsNameProductType ReportsName = "product_type"
ReportsNamePriceType ReportsName = "price_type"
ReportsNameProductUpdatedAt ReportsName = "product_updated_at"
ReportsNamePriceUpdatedAt ReportsName = "price_updated_at"
ReportsNameType ReportsName = "type"
)
// Operator: Operator to use when filtering. Valid when filtering by `updated_at`, `null` otherwise..
type ReportsOperator string
const (
ReportsOperatorLt ReportsOperator = "lt"
ReportsOperatorGte ReportsOperator = "gte"
)
// ReportFilters: List of filters applied to this report.
type ReportFilters struct {
// Name: Field name to filter by.
Name ReportsName `json:"name,omitempty"`
// Operator: Operator to use when filtering. Valid when filtering by `updated_at`, `null` otherwise.
Operator *ReportsOperator `json:"operator,omitempty"`
// Value: Value to filter by. Check the allowed values descriptions for the `name` field to see valid values for a field.
Value string `json:"value,omitempty"`
}
// Report: Represents a report entity.
type Report struct {
// ID: Unique Paddle ID for this report, prefixed with `rep_`
ID string `json:"id,omitempty"`
/*
Status: Status of this report. Set automatically by Paddle.
Reports are created as `pending` initially, then move to `ready` when they're available to download.
*/
Status ReportStatus `json:"status,omitempty"`
// Rows: Number of records in this report. `null` if the report is `pending`.
Rows *int `json:"rows,omitempty"`
// Type: Type of report.
Type ReportTypeTransactions `json:"type,omitempty"`
// Filters: List of filters applied to this report.
Filters []ReportFilters `json:"filters,omitempty"`
// ExpiresAt: RFC 3339 datetime string of when this report expires. The report is no longer available to download after this date.
ExpiresAt *string `json:"expires_at,omitempty"`
// UpdatedAt: RFC 3339 datetime string of when this report was last updated.
UpdatedAt string `json:"updated_at,omitempty"`
// CreatedAt: RFC 3339 datetime string of when this report was created.
CreatedAt string `json:"created_at,omitempty"`
}
// ReportTypeAdjustments: Type of report to create..
type ReportTypeAdjustments string
const (
ReportTypeAdjustmentsAdjustments ReportTypeAdjustments = "adjustments"
ReportTypeAdjustmentsAdjustmentLineItems ReportTypeAdjustments = "adjustment_line_items"
)
// ReportsReportFilters: Filter criteria for this report. If omitted, reports are filtered to include data updated in the last 30 days. This means `updated_at` is greater than or equal to (`gte`) the date 30 days ago from the time the report was generated.
type ReportsReportFilters struct {
// Name: Field name to filter by.
Name ReportsName `json:"name,omitempty"`
// Operator: Operator to use when filtering. Valid when filtering by `updated_at`, `null` otherwise.
Operator *ReportsOperator `json:"operator,omitempty"`
// Value: Value to filter by. Check the allowed values descriptions for the `name` field to see valid values for a field.
Value string `json:"value,omitempty"`
}
// AdjustmentsReports: Request body when creating reports for adjustments or adjustment line items.
type AdjustmentsReports struct {
// Type: Type of report to create.
Type ReportTypeAdjustments `json:"type,omitempty"`
// Filters: Filter criteria for this report. If omitted, reports are filtered to include data updated in the last 30 days. This means `updated_at` is greater than or equal to (`gte`) the date 30 days ago from the time the report was generated.
Filters []ReportsReportFilters `json:"filters,omitempty"`
}
// ReportsReportsReportFilters: Filter criteria for this report. If omitted, reports are filtered to include data updated in the last 30 days. This means `updated_at` is greater than or equal to (`gte`) the date 30 days ago from the time the report was generated.
type ReportsReportsReportFilters struct {
// Name: Field name to filter by.
Name ReportsName `json:"name,omitempty"`
// Operator: Operator to use when filtering. Valid when filtering by `updated_at`, `null` otherwise.
Operator *ReportsOperator `json:"operator,omitempty"`
// Value: Value to filter by. Check the allowed values descriptions for the `name` field to see valid values for a field.
Value string `json:"value,omitempty"`
}
// TransactionsReports: Request body when creating reports for transaction or transaction line items.
type TransactionsReports struct {
// Type: Type of report to create.
Type ReportTypeTransactions `json:"type,omitempty"`
// Filters: Filter criteria for this report. If omitted, reports are filtered to include data updated in the last 30 days. This means `updated_at` is greater than or equal to (`gte`) the date 30 days ago from the time the report was generated.
Filters []ReportsReportsReportFilters `json:"filters,omitempty"`
}
// Type: Type of report to create..
type Type string
const TypeProductsPrices Type = "products_prices"
// ReportsReportsReportsReportFilters: Filter criteria for this report. If omitted, reports are filtered to include data updated in the last 30 days. This means `product_updated_at` and `price_updated_at` are greater than or equal to (`gte`) the date 30 days ago from the time the report was generated.
type ReportsReportsReportsReportFilters struct {
// Name: Field name to filter by.
Name ReportsName `json:"name,omitempty"`
// Operator: Operator to use when filtering. Valid when filtering by `product_updated_at` or `price_updated_at`, `null` otherwise.
Operator *ReportsOperator `json:"operator,omitempty"`
// Value: Value to filter by.
Value string `json:"value,omitempty"`
}
// ProductsAndPricesReport: Request body when creating a products and prices report.
type ProductsAndPricesReport struct {
// Type: Type of report to create.
Type Type `json:"type,omitempty"`
// Filters: Filter criteria for this report. If omitted, reports are filtered to include data updated in the last 30 days. This means `product_updated_at` and `price_updated_at` are greater than or equal to (`gte`) the date 30 days ago from the time the report was generated.
Filters []ReportsReportsReportsReportFilters `json:"filters,omitempty"`
}
// ReportsReportsReportsReportsReportFilters: Filter criteria for this report. If omitted, reports are filtered to include data updated in the last 30 days. This means `updated_at` is greater than or equal to (`gte`) the date 30 days ago from the time the report was generated.
type ReportsReportsReportsReportsReportFilters struct {
// Name: Field name to filter by.
Name ReportsName `json:"name,omitempty"`
// Operator: Operator to use when filtering. Valid when filtering by `updated_at`, `null` otherwise.
Operator *ReportsOperator `json:"operator,omitempty"`
// Value: Value to filter by. Check the allowed values descriptions for the `name` field to see valid values for a field.
Value string `json:"value,omitempty"`
}
// DiscountsReport: Request body when creating a discounts report.
type DiscountsReport struct {
// Type: Type of report to create.
Type Type `json:"type,omitempty"`
// Filters: Filter criteria for this report. If omitted, reports are filtered to include data updated in the last 30 days. This means `updated_at` is greater than or equal to (`gte`) the date 30 days ago from the time the report was generated.
Filters []ReportsReportsReportsReportsReportFilters `json:"filters,omitempty"`
}
type ReportCSV struct {
// URL: URL of the requested resource.
URL string `json:"url,omitempty"`
}
// ReportsClient is a client for the Reports resource.
type ReportsClient struct {
doer Doer
}
// ListReportsRequest is given as an input to ListReports.
type ListReportsRequest struct {
// After is a query parameter.
// Return entities after the specified Paddle ID when working with paginated endpoints. Used in the `meta.pagination.next` URL in responses for list operations.
After *string `in:"query=after;omitempty" json:"-"`
// OrderBy is a query parameter.
/*
Order returned entities by the specified field and direction (`[ASC]` or `[DESC]`). For example, `?order_by=id[ASC]`.
Valid fields for ordering: `id`.
*/
OrderBy *string `in:"query=order_by;omitempty" json:"-"`
// PerPage is a query parameter.
/*
Set how many entities are returned per page. Paddle returns the maximum number of results if a number greater than the maximum is requested. Check `meta.pagination.per_page` in the response to see how many were returned.
Default: `50`; Maximum: `200`.
*/
PerPage *int `in:"query=per_page;omitempty" json:"-"`
// Status is a query parameter.
// Return entities that match the specified status. Use a comma-separated list to specify multiple status values.
Status []string `in:"query=status;omitempty" json:"-"`
}
// ListReports performs the GET operation on a Reports resource.
func (c *ReportsClient) ListReports(ctx context.Context, req *ListReportsRequest) (res *Collection[*Report], err error) {
if err := c.doer.Do(ctx, "GET", "/reports", req, &res); err != nil {
return nil, err
}
return res, nil
}
// NewCreateReportRequestAdjustmentsReports takes a AdjustmentsReports type
// and creates a CreateReportRequest for use in a request.
func NewCreateReportRequestAdjustmentsReports(r *AdjustmentsReports) *CreateReportRequest {
return &CreateReportRequest{AdjustmentsReports: r}
}
// NewCreateReportRequestTransactionsReports takes a TransactionsReports type
// and creates a CreateReportRequest for use in a request.
func NewCreateReportRequestTransactionsReports(r *TransactionsReports) *CreateReportRequest {
return &CreateReportRequest{TransactionsReports: r}
}
// NewCreateReportRequestProductsAndPricesReport takes a ProductsAndPricesReport type
// and creates a CreateReportRequest for use in a request.
func NewCreateReportRequestProductsAndPricesReport(r *ProductsAndPricesReport) *CreateReportRequest {
return &CreateReportRequest{ProductsAndPricesReport: r}
}
// NewCreateReportRequestDiscountsReport takes a DiscountsReport type
// and creates a CreateReportRequest for use in a request.
func NewCreateReportRequestDiscountsReport(r *DiscountsReport) *CreateReportRequest {
return &CreateReportRequest{DiscountsReport: r}
}
// CreateReportRequest represents a union request type of the following types:
// - `AdjustmentsReports`
// - `TransactionsReports`
// - `ProductsAndPricesReport`
// - `DiscountsReport`
//
// The following constructor functions can be used to create a new instance of this type.
// - `NewCreateReportRequestAdjustmentsReports()`
// - `NewCreateReportRequestTransactionsReports()`
// - `NewCreateReportRequestProductsAndPricesReport()`
// - `NewCreateReportRequestDiscountsReport()`
//
// Only one of the values can be set at a time, the first non-nil value will be used in the request.
type CreateReportRequest struct {
*AdjustmentsReports
*TransactionsReports
*ProductsAndPricesReport
*DiscountsReport
}
// CreateReport performs the POST operation on a Reports resource.
func (c *ReportsClient) CreateReport(ctx context.Context, req *CreateReportRequest) (res *Report, err error) {
if err := c.doer.Do(ctx, "POST", "/reports", req, &res); err != nil {
return nil, err
}
return res, nil
}
// MarshalJSON implements the json.Marshaler interface.
func (u CreateReportRequest) MarshalJSON() ([]byte, error) {
if u.AdjustmentsReports != nil {
return json.Marshal(u.AdjustmentsReports)
}
if u.TransactionsReports != nil {
return json.Marshal(u.TransactionsReports)
}
if u.ProductsAndPricesReport != nil {
return json.Marshal(u.ProductsAndPricesReport)
}
if u.DiscountsReport != nil {
return json.Marshal(u.DiscountsReport)
}
return nil, nil
}
// GetReportCSVRequest is given as an input to GetReportCSV.
type GetReportCSVRequest struct {
// URL path parameters.
ReportID string `in:"path=report_id" json:"-"`
}
// GetReportCSV performs the GET operation on a Reports resource.
func (c *ReportsClient) GetReportCSV(ctx context.Context, req *GetReportCSVRequest) (res *ReportCSV, err error) {
if err := c.doer.Do(ctx, "GET", "/reports/{report_id}/download-url", req, &res); err != nil {
return nil, err
}
return res, nil
}
// GetReportRequest is given as an input to GetReport.
type GetReportRequest struct {
// URL path parameters.
ReportID string `in:"path=report_id" json:"-"`
}
// GetReport performs the GET operation on a Reports resource.
func (c *ReportsClient) GetReport(ctx context.Context, req *GetReportRequest) (res *Report, err error) {
if err := c.doer.Do(ctx, "GET", "/reports/{report_id}", req, &res); err != nil {
return nil, err
}
return res, nil
}