UNPKG

@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.

156 lines 8.75 kB
"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.OffersController = void 0; var tslib_1 = require("tslib"); var core_js_1 = require("../core.js"); var createOfferRequest_js_1 = require("../models/createOfferRequest.js"); var listOffersResponse_js_1 = require("../models/listOffersResponse.js"); var offerResponse_js_1 = require("../models/offerResponse.js"); var schema_js_1 = require("../schema.js"); var baseController_js_1 = require("./baseController.js"); var errorArrayMapResponseError_js_1 = require("../errors/errorArrayMapResponseError.js"); var errorListResponseError_js_1 = require("../errors/errorListResponseError.js"); var OffersController = /** @class */ (function (_super) { tslib_1.__extends(OffersController, _super); function OffersController() { return _super !== null && _super.apply(this, arguments) || this; } /** * Create an offer within your Advanced Billing site by sending a POST request. * * ## Documentation * * Offers allow you to package complicated combinations of products, components and coupons into a * convenient package which can then be subscribed to just like products. * * Once an offer is defined it can be used as an alternative to the product when creating subscriptions. * * Full documentation on how to use offers in the Advanced Billing UI can be located [here](https: * //maxio.zendesk.com/hc/en-us/articles/24261295098637-Offers-Overview). * * ## Using a Product Price Point * * You can optionally pass in a `product_price_point_id` that corresponds with the `product_id` and the * offer will use that price point. If a `product_price_point_id` is not passed in, the product's * default price point will be used. * * @param body * @return Response from the API call */ OffersController.prototype.createOffer = function (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', '/offers.json'); mapped = req.prepareArgs({ body: [body, (0, schema_js_1.optional)(createOfferRequest_js_1.createOfferRequestSchema)], }); req.header('Content-Type', 'application/json'); req.json(mapped.body); req.throwOn(422, errorArrayMapResponseError_js_1.ErrorArrayMapResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'."); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.callAsJson(offerResponse_js_1.offerResponseSchema, requestOptions)]; }); }); }; /** * This endpoint will list offers for a site. * * @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`. * @return Response from the API call */ OffersController.prototype.listOffers = function (_a, requestOptions_1) { return tslib_1.__awaiter(this, arguments, void 0, function (_b, requestOptions) { var req, mapped; var page = _b.page, perPage = _b.perPage, includeArchived = _b.includeArchived; return tslib_1.__generator(this, function (_c) { req = this.createRequest('GET', '/offers.json'); mapped = req.prepareArgs({ 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)())], }); 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.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(listOffersResponse_js_1.listOffersResponseSchema, requestOptions)]; }); }); }; /** * This method allows you to list a specific offer's attributes. This is different than list all offers * for a site, as it requires an `offer_id`. * * @param offerId The Chargify id of the offer * @return Response from the API call */ OffersController.prototype.readOffer = function (offerId, 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({ offerId: [offerId, (0, schema_js_1.number)()] }); req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/offers/", ".json"], ["/offers/", ".json"])), mapped.offerId); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.callAsJson(offerResponse_js_1.offerResponseSchema, requestOptions)]; }); }); }; /** * Archive an existing offer. Please provide an `offer_id` in order to archive the correct item. * * @param offerId The Chargify id of the offer * @return Response from the API call */ OffersController.prototype.archiveOffer = function (offerId, 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({ offerId: [offerId, (0, schema_js_1.number)()] }); req.appendTemplatePath(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["/offers/", "/archive.json"], ["/offers/", "/archive.json"])), mapped.offerId); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.call(requestOptions)]; }); }); }; /** * Unarchive a previously archived offer. Please provide an `offer_id` in order to un-archive the * correct item. * * @param offerId The Chargify id of the offer * @return Response from the API call */ OffersController.prototype.unarchiveOffer = function (offerId, 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({ offerId: [offerId, (0, schema_js_1.number)()] }); req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/offers/", "/unarchive.json"], ["/offers/", "/unarchive.json"])), mapped.offerId); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.call(requestOptions)]; }); }); }; return OffersController; }(baseController_js_1.BaseController)); exports.OffersController = OffersController; var templateObject_1, templateObject_2, templateObject_3; //# sourceMappingURL=offersController.js.map