@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.
252 lines • 16.4 kB
JavaScript
"use strict";
/**
* AdvancedBilling
*
* This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
exports.__esModule = true;
exports.EventsBasedBillingSegmentsController = void 0;
var tslib_1 = require("tslib");
var core_1 = require("../core");
var bulkCreateSegments_1 = require("../models/bulkCreateSegments");
var bulkUpdateSegments_1 = require("../models/bulkUpdateSegments");
var createSegmentRequest_1 = require("../models/createSegmentRequest");
var listSegmentsFilter_1 = require("../models/listSegmentsFilter");
var listSegmentsResponse_1 = require("../models/listSegmentsResponse");
var segmentResponse_1 = require("../models/segmentResponse");
var updateSegmentRequest_1 = require("../models/updateSegmentRequest");
var schema_1 = require("../schema");
var baseController_1 = require("./baseController");
var core_2 = require("@apimatic/core");
var eventBasedBillingListSegmentsErrorsError_1 = require("../errors/eventBasedBillingListSegmentsErrorsError");
var eventBasedBillingSegmentError_1 = require("../errors/eventBasedBillingSegmentError");
var eventBasedBillingSegmentErrorsError_1 = require("../errors/eventBasedBillingSegmentErrorsError");
var EventsBasedBillingSegmentsController = /** @class */ (function (_super) {
tslib_1.__extends(EventsBasedBillingSegmentsController, _super);
function EventsBasedBillingSegmentsController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* This endpoint creates a new Segment for a Component with segmented Metric. It allows you to specify
* properties to bill upon and prices for each Segment. You can only pass as many "property_values" as
* the related Metric has segmenting properties defined.
*
* You may specify component and/or price point by using either the numeric ID or the `handle:gold`
* syntax.
*
* @param componentId ID or Handle for the Component
* @param pricePointId ID or Handle for the Price Point belonging to the Component
* @param body
* @return Response from the API call
*/
EventsBasedBillingSegmentsController.prototype.createSegment = function (componentId, pricePointId, body, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('POST');
mapped = req.prepareArgs({
componentId: [componentId, (0, schema_1.string)()],
pricePointId: [pricePointId, (0, schema_1.string)()],
body: [body, (0, schema_1.optional)(createSegmentRequest_1.createSegmentRequestSchema)]
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/components/", "/price_points/", "/segments.json"], ["/components/", "/price_points/", "/segments.json"])), mapped.componentId, mapped.pricePointId);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.throwOn(422, eventBasedBillingSegmentErrorsError_1.EventBasedBillingSegmentErrorsError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(segmentResponse_1.segmentResponseSchema, requestOptions)];
});
});
};
/**
* This endpoint allows you to fetch Segments created for a given Price Point. They will be returned in
* the order of creation.
*
* You can pass `page` and `per_page` parameters in order to access all of the segments. By default it
* will return `30` records. You can set `per_page` to `200` at most.
*
* You may specify component and/or price point by using either the numeric ID or the `handle:gold`
* syntax.
*
* @param componentId ID or Handle for the Component
* @param pricePointId ID or Handle for the Price Point belonging to the Component
* @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 30. The maximum allowed values is 200;
* any per_page value over 200 will be changed to 200. Use in
* query `per_page=200`.
* @param filter Filter to use for List Segments for a Price Point operation
* @return Response from the API call
*/
EventsBasedBillingSegmentsController.prototype.listSegmentsForPricePoint = function (_a, requestOptions) {
var componentId = _a.componentId, pricePointId = _a.pricePointId, page = _a.page, perPage = _a.perPage, 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({
componentId: [componentId, (0, schema_1.string)()],
pricePointId: [pricePointId, (0, schema_1.string)()],
page: [page, (0, schema_1.optional)((0, schema_1.number)())],
perPage: [perPage, (0, schema_1.optional)((0, schema_1.number)())],
filter: [filter, (0, schema_1.optional)(listSegmentsFilter_1.listSegmentsFilterSchema)]
});
req.query('page', mapped.page, core_1.commaPrefix);
req.query('per_page', mapped.perPage, core_1.commaPrefix);
req.query('filter', mapped.filter, core_1.commaPrefix);
req.appendTemplatePath(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["/components/", "/price_points/", "/segments.json"], ["/components/", "/price_points/", "/segments.json"])), mapped.componentId, mapped.pricePointId);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.throwOn(422, eventBasedBillingListSegmentsErrorsError_1.EventBasedBillingListSegmentsErrorsError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(listSegmentsResponse_1.listSegmentsResponseSchema, requestOptions)];
});
});
};
/**
* This endpoint updates a single Segment for a Component with a segmented Metric. It allows you to
* update the pricing for the segment.
*
* You may specify component and/or price point by using either the numeric ID or the `handle:gold`
* syntax.
*
* @param componentId ID or Handle of the Component
* @param pricePointId ID or Handle of the Price Point belonging to the Component
* @param id The ID of the Segment
* @param body
* @return Response from the API call
*/
EventsBasedBillingSegmentsController.prototype.updateSegment = function (componentId, pricePointId, id, body, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('PUT');
mapped = req.prepareArgs({
componentId: [componentId, (0, schema_1.string)()],
pricePointId: [pricePointId, (0, schema_1.string)()],
id: [id, (0, schema_1.number)()],
body: [body, (0, schema_1.optional)(updateSegmentRequest_1.updateSegmentRequestSchema)]
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/components/", "/price_points/", "/segments/", ".json"], ["/components/", "/price_points/", "/segments/", ".json"])), mapped.componentId, mapped.pricePointId, mapped.id);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.throwOn(422, eventBasedBillingSegmentErrorsError_1.EventBasedBillingSegmentErrorsError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(segmentResponse_1.segmentResponseSchema, requestOptions)];
});
});
};
/**
* This endpoint allows you to delete a Segment with specified ID.
*
* You may specify component and/or price point by using either the numeric ID or the `handle:gold`
* syntax.
*
* @param componentId ID or Handle of the Component
* @param pricePointId ID or Handle of the Price Point belonging to the Component
* @param id The ID of the Segment
* @return Response from the API call
*/
EventsBasedBillingSegmentsController.prototype.deleteSegment = function (componentId, pricePointId, id, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('DELETE');
mapped = req.prepareArgs({
componentId: [componentId, (0, schema_1.string)()],
pricePointId: [pricePointId, (0, schema_1.string)()],
id: [id, (0, schema_1.number)()]
});
req.appendTemplatePath(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["/components/", "/price_points/", "/segments/", ".json"], ["/components/", "/price_points/", "/segments/", ".json"])), mapped.componentId, mapped.pricePointId, mapped.id);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.throwOn(422, core_2.ApiError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.call(requestOptions)];
});
});
};
/**
* This endpoint allows you to create multiple segments in one request. The array of segments can
* contain up to `2000` records.
*
* If any of the records contain an error the whole request would fail and none of the requested
* segments get created. The error response contains a message for only the one segment that failed
* validation, with the corresponding index in the array.
*
* You may specify component and/or price point by using either the numeric ID or the `handle:gold`
* syntax.
*
* @param componentId ID or Handle for the Component
* @param pricePointId ID or Handle for the Price Point belonging to the Component
* @param body
* @return Response from the API call
*/
EventsBasedBillingSegmentsController.prototype.bulkCreateSegments = function (componentId, pricePointId, body, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('POST');
mapped = req.prepareArgs({
componentId: [componentId, (0, schema_1.string)()],
pricePointId: [pricePointId, (0, schema_1.string)()],
body: [body, (0, schema_1.optional)(bulkCreateSegments_1.bulkCreateSegmentsSchema)]
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["/components/", "/price_points/", "/segments/bulk.json"], ["/components/", "/price_points/", "/segments/bulk.json"])), mapped.componentId, mapped.pricePointId);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.throwOn(422, eventBasedBillingSegmentError_1.EventBasedBillingSegmentError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(listSegmentsResponse_1.listSegmentsResponseSchema, requestOptions)];
});
});
};
/**
* This endpoint allows you to update multiple segments in one request. The array of segments can
* contain up to `1000` records.
*
* If any of the records contain an error the whole request would fail and none of the requested
* segments get updated. The error response contains a message for only the one segment that failed
* validation, with the corresponding index in the array.
*
* You may specify component and/or price point by using either the numeric ID or the `handle:gold`
* syntax.
*
* @param componentId ID or Handle for the Component
* @param pricePointId ID or Handle for the Price Point belonging to the Component
* @param body
* @return Response from the API call
*/
EventsBasedBillingSegmentsController.prototype.bulkUpdateSegments = function (componentId, pricePointId, body, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('PUT');
mapped = req.prepareArgs({
componentId: [componentId, (0, schema_1.string)()],
pricePointId: [pricePointId, (0, schema_1.string)()],
body: [body, (0, schema_1.optional)(bulkUpdateSegments_1.bulkUpdateSegmentsSchema)]
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["/components/", "/price_points/", "/segments/bulk.json"], ["/components/", "/price_points/", "/segments/bulk.json"])), mapped.componentId, mapped.pricePointId);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.throwOn(422, eventBasedBillingSegmentError_1.EventBasedBillingSegmentError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(listSegmentsResponse_1.listSegmentsResponseSchema, requestOptions)];
});
});
};
return EventsBasedBillingSegmentsController;
}(baseController_1.BaseController));
exports.EventsBasedBillingSegmentsController = EventsBasedBillingSegmentsController;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
//# sourceMappingURL=eventsBasedBillingSegmentsController.js.map