@maxio-com/advanced-billing-sdk
Version:
Ultimate billing and pricing flexibility for B2B SaaS. Maxio integrates directly into your product, so you can seamlessly manage your product catalog, bill customers, and collect payments.
272 lines • 17.4 kB
JavaScript
;
/**
* AdvancedBilling
*
* This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
exports.__esModule = true;
exports.EventsController = void 0;
var tslib_1 = require("tslib");
var core_1 = require("../core");
var countResponse_1 = require("../models/countResponse");
var direction_1 = require("../models/direction");
var eventKey_1 = require("../models/eventKey");
var eventResponse_1 = require("../models/eventResponse");
var listEventsDateField_1 = require("../models/listEventsDateField");
var schema_1 = require("../schema");
var baseController_1 = require("./baseController");
var EventsController = /** @class */ (function (_super) {
tslib_1.__extends(EventsController, _super);
function EventsController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* ## Events Intro
*
* Advanced Billing Events include various activity that happens around a Site. This information is
* **especially** useful to track down issues that arise when subscriptions are not created due to
* errors.
*
* Within the Advanced Billing UI, "Events" are referred to as "Site Activity". Full documentation on
* how to record view Events / Site Activty in the Advanced Billing UI can be located [here](https:
* //maxio.zendesk.com/hc/en-us/articles/24250671733517-Site-Activity).
*
* ## List Events for a Site
*
* This method will retrieve a list of events for a site. Use query string filters to narrow down
* results. You may use the `key` filter as part of your query string to narrow down results.
*
* ### Legacy Filters
*
* The following keys are no longer supported.
*
* + `payment_failure_recreated`
* + `payment_success_recreated`
* + `renewal_failure_recreated`
* + `renewal_success_recreated`
* + `zferral_revenue_post_failure` - (Specific to the deprecated Zferral integration)
* + `zferral_revenue_post_success` - (Specific to the deprecated Zferral integration)
*
* ## Event Key
* The event type is identified by the key property. You can check supported keys
* [here]($m/Event%20Key).
*
* ## Event Specific Data
*
* Different event types may include additional data in `event_specific_data` property.
* While some events share the same schema for `event_specific_data`, others may not include it at all.
* For precise mappings from key to event_specific_data, refer to [Event]($m/Event).
*
* ### Example
* Here’s an example event for the `subscription_product_change` event:
*
* ```
* {
* "event": {
* "id": 351,
* "key": "subscription_product_change",
* "message": "Product changed on Marky Mark's subscription from 'Basic' to 'Pro'",
* "subscription_id": 205,
* "event_specific_data": {
* "new_product_id": 3,
* "previous_product_id": 2
* },
* "created_at": "2012-01-30T10:43:31-05:00"
* }
* }
* ```
*
* Here’s an example event for the `subscription_state_change` event:
*
* ```
* {
* "event": {
* "id": 353,
* "key": "subscription_state_change",
* "message": "State changed on Marky Mark's subscription to Pro from trialing to active",
* "subscription_id": 205,
* "event_specific_data": {
* "new_subscription_state": "active",
* "previous_subscription_state": "trialing"
* },
* "created_at": "2012-01-30T10:43:33-05:00"
* }
* }
* ```
*
* @param page Result records are organized in pages. By default, the first page of
* results is displayed. The page parameter specifies a page number of
* results to fetch. You can start navigating through the pages to
* consume the results. You do this by passing in a page parameter.
* Retrieve the next page by adding ?page=2 to the query string. If
* there are no results to return, then an empty result set will be
* returned. Use in query `page=1`.
* @param perPage This parameter indicates how many records to fetch in each request.
* Default value is 20. The maximum allowed values is 200; any per_page
* value over 200 will be changed to 200. Use in query `per_page=200`.
* @param sinceId Returns events with an id greater than or equal to the one
* specified
* @param maxId Returns events with an id less than or equal to the one specified
* @param direction The sort direction of the returned events.
* @param filter You can pass multiple event keys after comma. Use in query
* `filter=signup_success,payment_success`.
* @param dateField The type of filter you would like to apply to your search.
* @param startDate The start date (format YYYY-MM-DD) with which to filter the
* date_field. Returns components with a timestamp at or after midnight
* (12:00:00 AM) in your site’s time zone on the date specified.
* @param endDate The end date (format YYYY-MM-DD) with which to filter the date_field.
* Returns components with a timestamp up to and including 11:59:59PM
* in your site’s time zone on the date specified.
* @param startDatetime The start date and time (format YYYY-MM-DD HH:MM:SS) with which to
* filter the date_field. Returns components with a timestamp at or
* after exact time provided in query. You can specify timezone in query
* - otherwise your site's time zone will be used. If provided, this
* parameter will be used instead of start_date.
* @param endDatetime The end date and time (format YYYY-MM-DD HH:MM:SS) with which to
* filter the date_field. Returns components with a timestamp at or
* before exact time provided in query. You can specify timezone in
* query - otherwise your site's time zone will be used. If provided,
* this parameter will be used instead of end_date.
* @return Response from the API call
*/
EventsController.prototype.listEvents = function (_a, requestOptions) {
var page = _a.page, perPage = _a.perPage, sinceId = _a.sinceId, maxId = _a.maxId, direction = _a.direction, filter = _a.filter, dateField = _a.dateField, startDate = _a.startDate, endDate = _a.endDate, startDatetime = _a.startDatetime, endDatetime = _a.endDatetime;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_b) {
req = this.createRequest('GET', '/events.json');
mapped = req.prepareArgs({
page: [page, (0, schema_1.optional)((0, schema_1.number)())],
perPage: [perPage, (0, schema_1.optional)((0, schema_1.number)())],
sinceId: [sinceId, (0, schema_1.optional)((0, schema_1.bigint)())],
maxId: [maxId, (0, schema_1.optional)((0, schema_1.bigint)())],
direction: [direction, (0, schema_1.optional)(direction_1.directionSchema)],
filter: [filter, (0, schema_1.optional)((0, schema_1.array)(eventKey_1.eventKeySchema))],
dateField: [dateField, (0, schema_1.optional)(listEventsDateField_1.listEventsDateFieldSchema)],
startDate: [startDate, (0, schema_1.optional)((0, schema_1.string)())],
endDate: [endDate, (0, schema_1.optional)((0, schema_1.string)())],
startDatetime: [startDatetime, (0, schema_1.optional)((0, schema_1.string)())],
endDatetime: [endDatetime, (0, schema_1.optional)((0, schema_1.string)())]
});
req.query('page', mapped.page, core_1.commaPrefix);
req.query('per_page', mapped.perPage, core_1.commaPrefix);
req.query('since_id', mapped.sinceId, core_1.commaPrefix);
req.query('max_id', mapped.maxId, core_1.commaPrefix);
req.query('direction', mapped.direction, core_1.commaPrefix);
req.query('filter', mapped.filter, core_1.commaPrefix);
req.query('date_field', mapped.dateField, core_1.commaPrefix);
req.query('start_date', mapped.startDate, core_1.commaPrefix);
req.query('end_date', mapped.endDate, core_1.commaPrefix);
req.query('start_datetime', mapped.startDatetime, core_1.commaPrefix);
req.query('end_datetime', mapped.endDatetime, core_1.commaPrefix);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_1.array)(eventResponse_1.eventResponseSchema), requestOptions)];
});
});
};
/**
* The following request will return a list of events for a subscription.
*
* ## Event Key
* The event type is identified by the key property. You can check supported keys
* [here]($m/Event%20Key).
*
* ## Event Specific Data
*
* Different event types may include additional data in `event_specific_data` property.
* While some events share the same schema for `event_specific_data`, others may not include it at all.
* For precise mappings from key to event_specific_data, refer to [Event]($m/Event).
*
* @param subscriptionId The Chargify id of the subscription
* @param page Result records are organized in pages. By default, the first page of results
* is displayed. The page parameter specifies a page number of results to fetch.
* You can start navigating through the pages to consume the results. You do
* this by passing in a page parameter. Retrieve the next page by adding ?page=2
* to the query string. If there are no results to return, then an empty result
* set will be returned. Use in query `page=1`.
* @param perPage This parameter indicates how many records to fetch in each request. Default
* value is 20. The maximum allowed values is 200; any per_page value over 200
* will be changed to 200. Use in query `per_page=200`.
* @param sinceId Returns events with an id greater than or equal to the one specified
* @param maxId Returns events with an id less than or equal to the one specified
* @param direction The sort direction of the returned events.
* @param filter You can pass multiple event keys after comma. Use in query
* `filter=signup_success,payment_success`.
* @return Response from the API call
*/
EventsController.prototype.listSubscriptionEvents = function (_a, requestOptions) {
var subscriptionId = _a.subscriptionId, page = _a.page, perPage = _a.perPage, sinceId = _a.sinceId, maxId = _a.maxId, direction = _a.direction, filter = _a.filter;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_b) {
req = this.createRequest('GET');
mapped = req.prepareArgs({
subscriptionId: [subscriptionId, (0, schema_1.number)()],
page: [page, (0, schema_1.optional)((0, schema_1.number)())],
perPage: [perPage, (0, schema_1.optional)((0, schema_1.number)())],
sinceId: [sinceId, (0, schema_1.optional)((0, schema_1.bigint)())],
maxId: [maxId, (0, schema_1.optional)((0, schema_1.bigint)())],
direction: [direction, (0, schema_1.optional)(direction_1.directionSchema)],
filter: [filter, (0, schema_1.optional)((0, schema_1.array)(eventKey_1.eventKeySchema))]
});
req.query('page', mapped.page, core_1.commaPrefix);
req.query('per_page', mapped.perPage, core_1.commaPrefix);
req.query('since_id', mapped.sinceId, core_1.commaPrefix);
req.query('max_id', mapped.maxId, core_1.commaPrefix);
req.query('direction', mapped.direction, core_1.commaPrefix);
req.query('filter', mapped.filter, core_1.commaPrefix);
req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/subscriptions/", "/events.json"], ["/subscriptions/", "/events.json"])), mapped.subscriptionId);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_1.array)(eventResponse_1.eventResponseSchema), requestOptions)];
});
});
};
/**
* Get a count of all the events for a given site by using this method.
*
* @param page Result records are organized in pages. By default, the first page of results is
* displayed. The page parameter specifies a page number of results to fetch. You can
* start navigating through the pages to consume the results. You do this by passing
* in a page parameter. Retrieve the next page by adding ?page=2 to the query string.
* If there are no results to return, then an empty result set will be returned. Use
* in query `page=1`.
* @param perPage This parameter indicates how many records to fetch in each request. Default value
* is 20. The maximum allowed values is 200; any per_page value over 200 will be
* changed to 200. Use in query `per_page=200`.
* @param sinceId Returns events with an id greater than or equal to the one specified
* @param maxId Returns events with an id less than or equal to the one specified
* @param direction The sort direction of the returned events.
* @param filter You can pass multiple event keys after comma. Use in query `filter=signup_success,
* payment_success`.
* @return Response from the API call
*/
EventsController.prototype.readEventsCount = function (_a, requestOptions) {
var page = _a.page, perPage = _a.perPage, sinceId = _a.sinceId, maxId = _a.maxId, direction = _a.direction, filter = _a.filter;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_b) {
req = this.createRequest('GET', '/events/count.json');
mapped = req.prepareArgs({
page: [page, (0, schema_1.optional)((0, schema_1.number)())],
perPage: [perPage, (0, schema_1.optional)((0, schema_1.number)())],
sinceId: [sinceId, (0, schema_1.optional)((0, schema_1.bigint)())],
maxId: [maxId, (0, schema_1.optional)((0, schema_1.bigint)())],
direction: [direction, (0, schema_1.optional)(direction_1.directionSchema)],
filter: [filter, (0, schema_1.optional)((0, schema_1.array)(eventKey_1.eventKeySchema))]
});
req.query('page', mapped.page, core_1.commaPrefix);
req.query('per_page', mapped.perPage, core_1.commaPrefix);
req.query('since_id', mapped.sinceId, core_1.commaPrefix);
req.query('max_id', mapped.maxId, core_1.commaPrefix);
req.query('direction', mapped.direction, core_1.commaPrefix);
req.query('filter', mapped.filter, core_1.commaPrefix);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(countResponse_1.countResponseSchema, requestOptions)];
});
});
};
return EventsController;
}(baseController_1.BaseController));
exports.EventsController = EventsController;
var templateObject_1;
//# sourceMappingURL=eventsController.js.map