@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.
165 lines • 9.27 kB
JavaScript
"use strict";
/**
* AdvancedBilling
*
* This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
exports.__esModule = true;
exports.ReasonCodesController = void 0;
var tslib_1 = require("tslib");
var core_1 = require("../core");
var createReasonCodeRequest_1 = require("../models/createReasonCodeRequest");
var okResponse_1 = require("../models/okResponse");
var reasonCodeResponse_1 = require("../models/reasonCodeResponse");
var updateReasonCodeRequest_1 = require("../models/updateReasonCodeRequest");
var schema_1 = require("../schema");
var baseController_1 = require("./baseController");
var core_2 = require("@apimatic/core");
var errorListResponseError_1 = require("../errors/errorListResponseError");
var ReasonCodesController = /** @class */ (function (_super) {
tslib_1.__extends(ReasonCodesController, _super);
function ReasonCodesController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* # Reason Codes Intro
*
* ReasonCodes are a way to gain a high level view of why your customers are cancelling the
* subscription to your product or service.
*
* Add a set of churn reason codes to be displayed in-app and/or the Maxio Billing Portal. As your
* subscribers decide to cancel their subscription, learn why they decided to cancel.
*
* ## Reason Code Documentation
*
* Full documentation on how Reason Codes operate within Advanced Billing can be located under the
* following links.
*
* [Churn Reason Codes](https://maxio.zendesk.com/hc/en-us/articles/24286647554701-Churn-Reason-Codes)
*
* ## Create Reason Code
*
* This method gives a merchant the option to create a reason codes for a given Site.
*
* @param body
* @return Response from the API call
*/
ReasonCodesController.prototype.createReasonCode = 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', '/reason_codes.json');
mapped = req.prepareArgs({
body: [body, (0, schema_1.optional)(createReasonCodeRequest_1.createReasonCodeRequestSchema)]
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.throwOn(422, errorListResponseError_1.ErrorListResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(reasonCodeResponse_1.reasonCodeResponseSchema, requestOptions)];
});
});
};
/**
* This method gives a merchant the option to retrieve a list of all of the current churn codes for a
* given 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`.
* @return Response from the API call
*/
ReasonCodesController.prototype.listReasonCodes = function (_a, requestOptions) {
var page = _a.page, perPage = _a.perPage;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var req, mapped;
return tslib_1.__generator(this, function (_b) {
req = this.createRequest('GET', '/reason_codes.json');
mapped = req.prepareArgs({
page: [page, (0, schema_1.optional)((0, schema_1.number)())],
perPage: [perPage, (0, schema_1.optional)((0, schema_1.number)())]
});
req.query('page', mapped.page, core_1.commaPrefix);
req.query('per_page', mapped.perPage, core_1.commaPrefix);
req.throwOn(422, errorListResponseError_1.ErrorListResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_1.array)(reasonCodeResponse_1.reasonCodeResponseSchema), requestOptions)];
});
});
};
/**
* This method gives a merchant the option to retrieve a list of a particular code for a given Site by
* providing the unique numerical ID of the code.
*
* @param reasonCodeId The Advanced Billing id of the reason code
* @return Response from the API call
*/
ReasonCodesController.prototype.readReasonCode = function (reasonCodeId, 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({ reasonCodeId: [reasonCodeId, (0, schema_1.number)()] });
req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/reason_codes/", ".json"], ["/reason_codes/", ".json"])), mapped.reasonCodeId);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(reasonCodeResponse_1.reasonCodeResponseSchema, requestOptions)];
});
});
};
/**
* This method gives a merchant the option to update an existing reason code for a given site.
*
* @param reasonCodeId The Advanced Billing id of the reason code
* @param body
* @return Response from the API call
*/
ReasonCodesController.prototype.updateReasonCode = function (reasonCodeId, 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({
reasonCodeId: [reasonCodeId, (0, schema_1.number)()],
body: [body, (0, schema_1.optional)(updateReasonCodeRequest_1.updateReasonCodeRequestSchema)]
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["/reason_codes/", ".json"], ["/reason_codes/", ".json"])), mapped.reasonCodeId);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.throwOn(422, errorListResponseError_1.ErrorListResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(reasonCodeResponse_1.reasonCodeResponseSchema, requestOptions)];
});
});
};
/**
* This method gives a merchant the option to delete one reason code from the Churn Reason Codes. This
* code will be immediately removed. This action is not reversible.
*
* @param reasonCodeId The Advanced Billing id of the reason code
* @return Response from the API call
*/
ReasonCodesController.prototype.deleteReasonCode = function (reasonCodeId, 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({ reasonCodeId: [reasonCodeId, (0, schema_1.number)()] });
req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/reason_codes/", ".json"], ["/reason_codes/", ".json"])), mapped.reasonCodeId);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(okResponse_1.okResponseSchema, requestOptions)];
});
});
};
return ReasonCodesController;
}(baseController_1.BaseController));
exports.ReasonCodesController = ReasonCodesController;
var templateObject_1, templateObject_2, templateObject_3;
//# sourceMappingURL=reasonCodesController.js.map