@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.
233 lines • 15.4 kB
JavaScript
"use strict";
/**
* AdvancedBilling
*
* This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProductsController = void 0;
var tslib_1 = require("tslib");
var core_js_1 = require("../core.js");
var basicDateField_js_1 = require("../models/basicDateField.js");
var createOrUpdateProductRequest_js_1 = require("../models/createOrUpdateProductRequest.js");
var listProductsFilter_js_1 = require("../models/listProductsFilter.js");
var listProductsInclude_js_1 = require("../models/listProductsInclude.js");
var productResponse_js_1 = require("../models/productResponse.js");
var schema_js_1 = require("../schema.js");
var baseController_js_1 = require("./baseController.js");
var errorListResponseError_js_1 = require("../errors/errorListResponseError.js");
var ProductsController = /** @class */ (function (_super) {
tslib_1.__extends(ProductsController, _super);
function ProductsController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Creates a product in your Advanced Billing site.
*
* See the following product docuemation for more information:
*
* + [Products Documentation](https://maxio.zendesk.com/hc/en-us/articles/24261090117645-Products-
* Overview)
* + [Changing a Subscription's Product](https://maxio.zendesk.com/hc/en-us/articles/24252069837581-
* Product-Changes-and-Migrations)
*
* @param productFamilyId Either the product family's id or its handle
* prefixed with `handle:`
* @param body
* @return Response from the API call
*/
ProductsController.prototype.createProduct = function (productFamilyId, 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({
productFamilyId: [productFamilyId, (0, schema_js_1.string)()],
body: [body, (0, schema_js_1.optional)(createOrUpdateProductRequest_js_1.createOrUpdateProductRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/product_families/", "/products.json"], ["/product_families/", "/products.json"])), mapped.productFamilyId);
req.throwOn(422, errorListResponseError_js_1.ErrorListResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(productResponse_js_1.productResponseSchema, requestOptions)];
});
});
};
/**
* Reads the current details of a product.
*
* @param productId The Advanced Billing id of the product
* @return Response from the API call
*/
ProductsController.prototype.readProduct = function (productId, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('GET');
mapped = req.prepareArgs({ productId: [productId, (0, schema_js_1.number)()] });
req.appendTemplatePath(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["/products/", ".json"], ["/products/", ".json"])), mapped.productId);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(productResponse_js_1.productResponseSchema, requestOptions)];
});
});
};
/**
* Updates aspects of an existing product.
*
* ### Input Attributes Update Notes
*
* + `update_return_params` The parameters we will append to your `update_return_url`. See Return URLs
* and Parameters
*
* ### Product Price Point
*
* Updating a product using this endpoint will create a new price point and set it as the default price
* point for this product. If you should like to update an existing product price point, that must be
* done separately.
*
* @param productId The Advanced Billing id of the product
* @param body
* @return Response from the API call
*/
ProductsController.prototype.updateProduct = function (productId, 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({
productId: [productId, (0, schema_js_1.number)()],
body: [body, (0, schema_js_1.optional)(createOrUpdateProductRequest_js_1.createOrUpdateProductRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/products/", ".json"], ["/products/", ".json"])), mapped.productId);
req.throwOn(422, errorListResponseError_js_1.ErrorListResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(productResponse_js_1.productResponseSchema, requestOptions)];
});
});
};
/**
* Archives the product. All current subscribers will be unffected; their subscription/purchase will
* continue to be charged monthly.
*
* This will restrict the option to chose the product for purchase via the Billing Portal, as well as
* disable Public Signup Pages for the product.
*
* @param productId The Advanced Billing id of the product
* @return Response from the API call
*/
ProductsController.prototype.archiveProduct = function (productId, 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({ productId: [productId, (0, schema_js_1.number)()] });
req.appendTemplatePath(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["/products/", ".json"], ["/products/", ".json"])), mapped.productId);
req.throwOn(422, errorListResponseError_js_1.ErrorListResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(productResponse_js_1.productResponseSchema, requestOptions)];
});
});
};
/**
* Retrieves a Product object by its `api_handle`.
*
* @param apiHandle The handle of the product
* @return Response from the API call
*/
ProductsController.prototype.readProductByHandle = function (apiHandle, requestOptions) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_a) {
req = this.createRequest('GET');
mapped = req.prepareArgs({ apiHandle: [apiHandle, (0, schema_js_1.string)()] });
req.appendTemplatePath(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["/products/handle/", ".json"], ["/products/handle/", ".json"])), mapped.apiHandle);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(productResponse_js_1.productResponseSchema, requestOptions)];
});
});
};
/**
* This method allows to retrieve a list of Products belonging to a Site.
*
* @param dateField The type of filter you would like to apply to your search.
* Use in query: `date_field=created_at`.
* @param filter Filter to use for List Products operations
* @param endDate The end date (format YYYY-MM-DD) with which to filter the
* date_field. Returns products with a timestamp up to and
* including 11:59:59PM in your site’s time zone on the date
* specified.
* @param endDatetime The end date and time (format YYYY-MM-DD HH:MM:SS) with
* which to filter the date_field. Returns products 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.
* @param startDate The start date (format YYYY-MM-DD) with which to filter the
* date_field. Returns products with a timestamp at or after
* midnight (12:00:00 AM) 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 products 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 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 includeArchived Include archived products. Use in query:
* `include_archived=true`.
* @param include Allows including additional data in the response. Use in
* query `include=prepaid_product_price_point`.
* @return Response from the API call
*/
ProductsController.prototype.listProducts = function (_a, requestOptions_1) {
return tslib_1.__awaiter(this, arguments, void 0, function (_b, requestOptions) {
var req, mapped;
var dateField = _b.dateField, filter = _b.filter, endDate = _b.endDate, endDatetime = _b.endDatetime, startDate = _b.startDate, startDatetime = _b.startDatetime, page = _b.page, perPage = _b.perPage, includeArchived = _b.includeArchived, include = _b.include;
return tslib_1.__generator(this, function (_c) {
req = this.createRequest('GET', '/products.json');
mapped = req.prepareArgs({
dateField: [dateField, (0, schema_js_1.optional)(basicDateField_js_1.basicDateFieldSchema)],
filter: [filter, (0, schema_js_1.optional)(listProductsFilter_js_1.listProductsFilterSchema)],
endDate: [endDate, (0, schema_js_1.optional)((0, schema_js_1.string)())],
endDatetime: [endDatetime, (0, schema_js_1.optional)((0, schema_js_1.string)())],
startDate: [startDate, (0, schema_js_1.optional)((0, schema_js_1.string)())],
startDatetime: [startDatetime, (0, schema_js_1.optional)((0, schema_js_1.string)())],
page: [page, (0, schema_js_1.optional)((0, schema_js_1.number)())],
perPage: [perPage, (0, schema_js_1.optional)((0, schema_js_1.number)())],
includeArchived: [includeArchived, (0, schema_js_1.optional)((0, schema_js_1.boolean)())],
include: [include, (0, schema_js_1.optional)(listProductsInclude_js_1.listProductsIncludeSchema)],
});
req.query('date_field', mapped.dateField, core_js_1.commaPrefix);
req.query('filter', mapped.filter, core_js_1.commaPrefix);
req.query('end_date', mapped.endDate, core_js_1.commaPrefix);
req.query('end_datetime', mapped.endDatetime, core_js_1.commaPrefix);
req.query('start_date', mapped.startDate, core_js_1.commaPrefix);
req.query('start_datetime', mapped.startDatetime, core_js_1.commaPrefix);
req.query('page', mapped.page, core_js_1.commaPrefix);
req.query('per_page', mapped.perPage, core_js_1.commaPrefix);
req.query('include_archived', mapped.includeArchived, core_js_1.commaPrefix);
req.query('include', mapped.include, core_js_1.commaPrefix);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_js_1.array)(productResponse_js_1.productResponseSchema), requestOptions)];
});
});
};
return ProductsController;
}(baseController_js_1.BaseController));
exports.ProductsController = ProductsController;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
//# sourceMappingURL=productsController.js.map