@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.
113 lines • 6.79 kB
JavaScript
;
/**
* AdvancedBilling
*
* This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdvanceInvoiceController = void 0;
var tslib_1 = require("tslib");
var invoice_js_1 = require("../models/invoice.js");
var issueAdvanceInvoiceRequest_js_1 = require("../models/issueAdvanceInvoiceRequest.js");
var voidInvoiceRequest_js_1 = require("../models/voidInvoiceRequest.js");
var schema_js_1 = require("../schema.js");
var baseController_js_1 = require("./baseController.js");
var core_1 = require("@apimatic/core");
var errorListResponseError_js_1 = require("../errors/errorListResponseError.js");
var AdvanceInvoiceController = /** @class */ (function (_super) {
tslib_1.__extends(AdvanceInvoiceController, _super);
function AdvanceInvoiceController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Generate an invoice in advance for a subscription's next renewal date. [See our docs](https://maxio.
* zendesk.com/hc/en-us/articles/24252026404749-Issue-Invoice-In-Advance) for more information on
* advance invoices, including eligibility on generating one; for the most part, they function like any
* other invoice, except they are issued early and have special behavior upon being voided.
* A subscription may only have one advance invoice per billing period. Attempting to issue an advance
* invoice when one already exists will return an error.
* That said, regeneration of the invoice may be forced with the params `force: true`, which will void
* an advance invoice if one exists and generate a new one. If no advance invoice exists, a new one
* will be generated.
* We recommend using either the create or preview endpoints for proforma invoices to preview this
* advance invoice before using this endpoint to generate it.
*
*
* @param subscriptionId The Chargify id of the subscription
* @param body
* @return Response from the API call
*/
AdvanceInvoiceController.prototype.issueAdvanceInvoice = function (subscriptionId, 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({
subscriptionId: [subscriptionId, (0, schema_js_1.number)()],
body: [body, (0, schema_js_1.optional)(issueAdvanceInvoiceRequest_js_1.issueAdvanceInvoiceRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/subscriptions/", "/advance_invoice/issue.json"], ["/subscriptions/", "/advance_invoice/issue.json"])), mapped.subscriptionId);
req.throwOn(404, core_1.ApiError, true, "Not Found:'{$response.body}'");
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(invoice_js_1.invoiceSchema, requestOptions)];
});
});
};
/**
* Once an advance invoice has been generated for a subscription's upcoming renewal, it can be viewed
* through this endpoint. There can only be one advance invoice per subscription per billing cycle.
*
* @param subscriptionId The Chargify id of the subscription
* @return Response from the API call
*/
AdvanceInvoiceController.prototype.readAdvanceInvoice = function (subscriptionId, 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({
subscriptionId: [subscriptionId, (0, schema_js_1.number)()],
});
req.appendTemplatePath(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["/subscriptions/", "/advance_invoice.json"], ["/subscriptions/", "/advance_invoice.json"])), mapped.subscriptionId);
req.throwOn(404, core_1.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(invoice_js_1.invoiceSchema, requestOptions)];
});
});
};
/**
* Void a subscription's existing advance invoice. Once voided, it can later be regenerated if desired.
* A `reason` is required in order to void, and the invoice must have an open status. Voiding will
* cause any prepayments and credits that were applied to the invoice to be returned to the
* subscription. For a full overview of the impact of voiding, [see our help docs]($m/Invoice).
*
* @param subscriptionId The Chargify id of the subscription
* @param body
* @return Response from the API call
*/
AdvanceInvoiceController.prototype.voidAdvanceInvoice = function (subscriptionId, 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({
subscriptionId: [subscriptionId, (0, schema_js_1.number)()],
body: [body, (0, schema_js_1.optional)(voidInvoiceRequest_js_1.voidInvoiceRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/subscriptions/", "/advance_invoice/void.json"], ["/subscriptions/", "/advance_invoice/void.json"])), mapped.subscriptionId);
req.throwOn(404, core_1.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(invoice_js_1.invoiceSchema, requestOptions)];
});
});
};
return AdvanceInvoiceController;
}(baseController_js_1.BaseController));
exports.AdvanceInvoiceController = AdvanceInvoiceController;
var templateObject_1, templateObject_2, templateObject_3;
//# sourceMappingURL=advanceInvoiceController.js.map