diff --git a/client/api.go b/client/api.go index e817bdf76b..65e9926958 100644 --- a/client/api.go +++ b/client/api.go @@ -41,6 +41,8 @@ import ( "github.com/stripe/stripe-go/product" "github.com/stripe/stripe-go/recipient" "github.com/stripe/stripe-go/refund" + "github.com/stripe/stripe-go/reporting/reportrun" + "github.com/stripe/stripe-go/reporting/reporttype" "github.com/stripe/stripe-go/reversal" "github.com/stripe/stripe-go/sigma/scheduledqueryrun" "github.com/stripe/stripe-go/sku" @@ -132,6 +134,10 @@ type API struct { Recipients *recipient.Client // Refunds is the client used to invoke /refunds APIs. Refunds *refund.Client + // ReportRuns is the client used to invoke /reporting/report_runs APIs. + ReportRuns *reportrun.Client + // ReportTypes is the client used to invoke /reporting/report_types APIs. + ReportTypes *reporttype.Client // Reversals is the client used to invoke /transfers/reversals APIs. Reversals *reversal.Client // SigmaScheduledQueryRuns is the client used to invoke /sigma/scheduled_query_runs APIs. @@ -204,6 +210,8 @@ func (a *API) Init(key string, backends *stripe.Backends) { a.Products = &product.Client{B: backends.API, Key: key} a.Recipients = &recipient.Client{B: backends.API, Key: key} a.Refunds = &refund.Client{B: backends.API, Key: key} + a.ReportRuns = &reportrun.Client{B: backends.API, Key: key} + a.ReportTypes = &reporttype.Client{B: backends.API, Key: key} a.Reversals = &reversal.Client{B: backends.API, Key: key} a.SigmaScheduledQueryRuns = &scheduledqueryrun.Client{B: backends.API, Key: key} a.Skus = &sku.Client{B: backends.API, Key: key} diff --git a/reporting/reportrun/client.go b/reporting/reportrun/client.go new file mode 100644 index 0000000000..7ae03e13dd --- /dev/null +++ b/reporting/reportrun/client.go @@ -0,0 +1,76 @@ +// Package reportrun provides API functions related to report runs. +// +// For more details, see: https://stripe.com/docs/api/go#reporting_report_run +package reportrun + +import ( + "net/http" + + stripe "github.com/stripe/stripe-go" + "github.com/stripe/stripe-go/form" +) + +// Client is used to invoke /reporting/report_runs APIs. +type Client struct { + B stripe.Backend + Key string +} + +// New creates a new report run. +func New(params *stripe.ReportRunParams) (*stripe.ReportRun, error) { + return getC().New(params) +} + +// New creates a new report run. +func (c Client) New(params *stripe.ReportRunParams) (*stripe.ReportRun, error) { + reportrun := &stripe.ReportRun{} + err := c.B.Call(http.MethodPost, "/reporting/report_runs", c.Key, params, reportrun) + return reportrun, err +} + +// Get returns the details of a report run. +func Get(id string, params *stripe.ReportRunParams) (*stripe.ReportRun, error) { + return getC().Get(id, params) +} + +// Get returns the details of a report run. +func (c Client) Get(id string, params *stripe.ReportRunParams) (*stripe.ReportRun, error) { + path := stripe.FormatURLPath("/reporting/report_runs/%s", id) + reportrun := &stripe.ReportRun{} + err := c.B.Call(http.MethodGet, path, c.Key, params, reportrun) + return reportrun, err +} + +// List returns a list of report runs. +func List(params *stripe.ReportRunListParams) *Iter { + return getC().List(params) +} + +// List returns a list of report runs. +func (c Client) List(listParams *stripe.ReportRunListParams) *Iter { + return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) { + list := &stripe.ReportRunList{} + err := c.B.CallRaw(http.MethodGet, "/reporting/report_runs", c.Key, b, p, list) + + ret := make([]interface{}, len(list.Data)) + for i, v := range list.Data { + ret[i] = v + } + + return ret, list.ListMeta, err + })} +} + +// Iter is an iterator for report runs. +type Iter struct { + *stripe.Iter +} + +// ReportRun returns the report run which the iterator is currently pointing to. +func (i *Iter) ReportRun() *stripe.ReportRun { + return i.Current().(*stripe.ReportRun) +} + +func getC() Client { + return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} +} diff --git a/reporting/reportrun/client_test.go b/reporting/reportrun/client_test.go new file mode 100644 index 0000000000..9815327176 --- /dev/null +++ b/reporting/reportrun/client_test.go @@ -0,0 +1,38 @@ +package reportrun + +import ( + "testing" + + assert "github.com/stretchr/testify/require" + stripe "github.com/stripe/stripe-go" + _ "github.com/stripe/stripe-go/testing" +) + +func TestReportRunGet(t *testing.T) { + reportrun, err := Get("frr_123", nil) + assert.Nil(t, err) + assert.NotNil(t, reportrun) + assert.Equal(t, "reporting.report_run", reportrun.Object) +} + +func TestReportRunList(t *testing.T) { + i := List(&stripe.ReportRunListParams{}) + + // Verify that we can get at least one reportrun + assert.True(t, i.Next()) + assert.Nil(t, i.Err()) + assert.NotNil(t, i.ReportRun()) + assert.Equal(t, "reporting.report_run", i.ReportRun().Object) +} + +func TestReportRunNew(t *testing.T) { + reportrun, err := New(&stripe.ReportRunParams{ + Parameters: &stripe.ReportRunParametersParams{ + ConnectedAccount: stripe.String("acct_123"), + }, + ReportType: stripe.String("activity.summary.1"), + }) + assert.Nil(t, err) + assert.NotNil(t, reportrun) + assert.Equal(t, "reporting.report_run", reportrun.Object) +} diff --git a/reporting/reporttype/client.go b/reporting/reporttype/client.go new file mode 100644 index 0000000000..2cecb42fd8 --- /dev/null +++ b/reporting/reporttype/client.go @@ -0,0 +1,64 @@ +// Package reporttype provides API functions related to report types. +// +// For more details, see: https://stripe.com/docs/api/go#reporting_report_type +package reporttype + +import ( + "net/http" + + stripe "github.com/stripe/stripe-go" + "github.com/stripe/stripe-go/form" +) + +// Client is used to invoke /reporting/report_types APIs. +type Client struct { + B stripe.Backend + Key string +} + +// Get returns the details of a report type. +func Get(id string, params *stripe.ReportTypeParams) (*stripe.ReportType, error) { + return getC().Get(id, params) +} + +// Get returns the details of a report type. +func (c Client) Get(id string, params *stripe.ReportTypeParams) (*stripe.ReportType, error) { + path := stripe.FormatURLPath("/reporting/report_types/%s", id) + reporttype := &stripe.ReportType{} + err := c.B.Call(http.MethodGet, path, c.Key, params, reporttype) + return reporttype, err +} + +// List returns a list of report types. +func List(params *stripe.ReportTypeListParams) *Iter { + return getC().List(params) +} + +// List returns a list of report types. +func (c Client) List(listParams *stripe.ReportTypeListParams) *Iter { + return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) { + list := &stripe.ReportTypeList{} + err := c.B.CallRaw(http.MethodGet, "/reporting/report_types", c.Key, b, p, list) + + ret := make([]interface{}, len(list.Data)) + for i, v := range list.Data { + ret[i] = v + } + + return ret, list.ListMeta, err + })} +} + +// Iter is an iterator for report types. +type Iter struct { + *stripe.Iter +} + +// ReportType returns the report type which the iterator is currently pointing to. +func (i *Iter) ReportType() *stripe.ReportType { + return i.Current().(*stripe.ReportType) +} + +func getC() Client { + return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} +} diff --git a/reporting/reporttype/client_test.go b/reporting/reporttype/client_test.go new file mode 100644 index 0000000000..42784a1aac --- /dev/null +++ b/reporting/reporttype/client_test.go @@ -0,0 +1,26 @@ +package reporttype + +import ( + "testing" + + assert "github.com/stretchr/testify/require" + stripe "github.com/stripe/stripe-go" + _ "github.com/stripe/stripe-go/testing" +) + +func TestReportTestGet(t *testing.T) { + reporttype, err := Get("activity.summary.1", nil) + assert.Nil(t, err) + assert.NotNil(t, reporttype) + assert.Equal(t, "reporting.report_type", reporttype.Object) +} + +func TestReportTestList(t *testing.T) { + i := List(&stripe.ReportTypeListParams{}) + + // Verify that we can get at least one reporttype + assert.True(t, i.Next()) + assert.Nil(t, i.Err()) + assert.NotNil(t, i.ReportType()) + assert.Equal(t, "reporting.report_type", i.ReportType().Object) +} diff --git a/reporting_reportrun.go b/reporting_reportrun.go new file mode 100644 index 0000000000..244400ca17 --- /dev/null +++ b/reporting_reportrun.go @@ -0,0 +1,65 @@ +package stripe + +// ReportRunStatus is the possible values for status on a report run. +type ReportRunStatus string + +// List of values that ReportRunStatus can take. +const ( + ReportRunStatusFailed ReportRunStatus = "failed" + ReportRunStatusPending ReportRunStatus = "pending" + ReportRunStatusSucceeded ReportRunStatus = "succeeded" +) + +// ReportRunParametersParams is the set of parameters that can be used when creating a report run. +type ReportRunParametersParams struct { + ConnectedAccount *string `form:"connected_account"` + Currency *string `form:"currency"` + IntervalEnd *int64 `form:"interval_end"` + IntervalStart *int64 `form:"interval_start"` + Payout *string `form:"payout"` + ReportingCategory *string `form:"reporting_category"` +} + +// ReportRunParams is the set of parameters that can be used when creating a report run. +type ReportRunParams struct { + Params `form:"*"` + Parameters *ReportRunParametersParams `form:"parameters"` + ReportType *string `form:"report_type"` +} + +// ReportRunListParams is the set of parameters that can be used when listing report runs. +type ReportRunListParams struct { + ListParams `form:"*"` + Created *int64 `form:"created"` + CreatedRange *RangeQueryParams `form:"created"` +} + +// ReportRunParameters describes the parameters hash on a report run. +type ReportRunParameters struct { + ConnectedAccount string `json:"connected_account"` + Currency Currency `json:"currency"` + IntervalEnd int64 `json:"interval_end"` + IntervalStart int64 `json:"interval_start"` + Payout string `json:"payout"` + ReportingCategory string `json:"reporting_category"` +} + +// ReportRun is the resource representing a report run. +type ReportRun struct { + Created int64 `json:"created"` + Error string `json:"error"` + ID string `json:"id"` + Livemode bool `json:"livemode"` + Object string `json:"object"` + Parameters *ReportRunParameters `json:"parameters"` + ReportType string `json:"report_type"` + Result *FileUpload `json:"result"` + Status ReportRunStatus `json:"status"` + SucceededAt int64 `json:"succeeded_at"` +} + +// ReportRunList is a list of report runs as retrieved from a list endpoint. +type ReportRunList struct { + ListMeta + Data []*ReportRun `json:"data"` +} diff --git a/reporting_reporttype.go b/reporting_reporttype.go new file mode 100644 index 0000000000..36503b40e7 --- /dev/null +++ b/reporting_reporttype.go @@ -0,0 +1,29 @@ +package stripe + +// ReportTypeListParams is the set of parameters that can be used when listing report types. +type ReportTypeListParams struct { + ListParams `form:"*"` +} + +// ReportTypeParams is the set of parameters that can be used when retrieving a report type. +type ReportTypeParams struct { + Params `form:"*"` +} + +// ReportType is the resource representing a report type. +type ReportType struct { + Created int64 `json:"created"` + DataAvailableEnd int64 `json:"data_available_end"` + DataAvailableStart int64 `json:"data_available_start"` + ID string `json:"id"` + Name string `json:"name"` + Object string `json:"object"` + Updated int64 `json:"updated"` + Version int64 `json:"version"` +} + +// ReportTypeList is a list of report types as retrieved from a list endpoint. +type ReportTypeList struct { + ListMeta + Data []*ReportType `json:"data"` +}