@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.
382 lines • 25 kB
JavaScript
"use strict";
/**
* AdvancedBilling
*
* This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
exports.__esModule = true;
exports.ProformaInvoicesController = void 0;
var tslib_1 = require("tslib");
var core_1 = require("../core");
var createSignupProformaPreviewInclude_1 = require("../models/createSignupProformaPreviewInclude");
var createSubscriptionRequest_1 = require("../models/createSubscriptionRequest");
var direction_1 = require("../models/direction");
var listProformaInvoicesResponse_1 = require("../models/listProformaInvoicesResponse");
var proformaInvoice_1 = require("../models/proformaInvoice");
var proformaInvoiceStatus_1 = require("../models/proformaInvoiceStatus");
var signupProformaPreviewResponse_1 = require("../models/signupProformaPreviewResponse");
var voidInvoiceRequest_1 = require("../models/voidInvoiceRequest");
var schema_1 = require("../schema");
var baseController_1 = require("./baseController");
var core_2 = require("@apimatic/core");
var errorArrayMapResponseError_1 = require("../errors/errorArrayMapResponseError");
var errorListResponseError_1 = require("../errors/errorListResponseError");
var proformaBadRequestErrorResponseError_1 = require("../errors/proformaBadRequestErrorResponseError");
var ProformaInvoicesController = /** @class */ (function (_super) {
tslib_1.__extends(ProformaInvoicesController, _super);
function ProformaInvoicesController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* This endpoint will trigger the creation of a consolidated proforma invoice asynchronously. It will
* return a 201 with no message, or a 422 with any errors. To find and view the new consolidated
* proforma invoice, you may poll the subscription group listing for proforma invoices; only one
* consolidated proforma invoice may be created per group at a time.
*
* If the information becomes outdated, simply void the old consolidated proforma invoice and generate
* a new one.
*
* ## Restrictions
*
* Proforma invoices are only available on Relationship Invoicing sites. To create a proforma invoice,
* the subscription must not be prepaid, and must be in a live state.
*
* @param uid The uid of the subscription group
* @return Response from the API call
*/
ProformaInvoicesController.prototype.createConsolidatedProformaInvoice = function (uid, 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({ uid: [uid, (0, schema_1.string)()] });
req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/subscription_groups/", "/proforma_invoices.json"], ["/subscription_groups/", "/proforma_invoices.json"])), mapped.uid);
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.call(requestOptions)];
});
});
};
/**
* Only proforma invoices with a `consolidation_level` of parent are returned.
*
* By default, proforma invoices returned on the index will only include totals, not detailed
* breakdowns for `line_items`, `discounts`, `taxes`, `credits`, `payments`, `custom_fields`. To
* include breakdowns, pass the specific field as a key in the query with a value set to true.
*
*
* @param uid The uid of the subscription group
* @param lineItems Include line items data
* @param discounts Include discounts data
* @param taxes Include taxes data
* @param credits Include credits data
* @param payments Include payments data
* @param customFields Include custom fields data
* @return Response from the API call
*/
ProformaInvoicesController.prototype.listSubscriptionGroupProformaInvoices = function (_a, requestOptions) {
var uid = _a.uid, lineItems = _a.lineItems, discounts = _a.discounts, taxes = _a.taxes, credits = _a.credits, payments = _a.payments, customFields = _a.customFields;
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({
uid: [uid, (0, schema_1.string)()],
lineItems: [lineItems, (0, schema_1.optional)((0, schema_1.boolean)())],
discounts: [discounts, (0, schema_1.optional)((0, schema_1.boolean)())],
taxes: [taxes, (0, schema_1.optional)((0, schema_1.boolean)())],
credits: [credits, (0, schema_1.optional)((0, schema_1.boolean)())],
payments: [payments, (0, schema_1.optional)((0, schema_1.boolean)())],
customFields: [customFields, (0, schema_1.optional)((0, schema_1.boolean)())]
});
req.query('line_items', mapped.lineItems, core_1.commaPrefix);
req.query('discounts', mapped.discounts, core_1.commaPrefix);
req.query('taxes', mapped.taxes, core_1.commaPrefix);
req.query('credits', mapped.credits, core_1.commaPrefix);
req.query('payments', mapped.payments, core_1.commaPrefix);
req.query('custom_fields', mapped.customFields, core_1.commaPrefix);
req.appendTemplatePath(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["/subscription_groups/", "/proforma_invoices.json"], ["/subscription_groups/", "/proforma_invoices.json"])), mapped.uid);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(listProformaInvoicesResponse_1.listProformaInvoicesResponseSchema, requestOptions)];
});
});
};
/**
* Use this endpoint to read the details of an existing proforma invoice.
*
* ## Restrictions
*
* Proforma invoices are only available on Relationship Invoicing sites.
*
* @param proformaInvoiceUid The uid of the proforma invoice
* @return Response from the API call
*/
ProformaInvoicesController.prototype.readProformaInvoice = function (proformaInvoiceUid, 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({
proformaInvoiceUid: [proformaInvoiceUid, (0, schema_1.string)()]
});
req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/proforma_invoices/", ".json"], ["/proforma_invoices/", ".json"])), mapped.proformaInvoiceUid);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(proformaInvoice_1.proformaInvoiceSchema, requestOptions)];
});
});
};
/**
* This endpoint will create a proforma invoice and return it as a response. If the information becomes
* outdated, simply void the old proforma invoice and generate a new one.
*
* If you would like to preview the next billing amounts without generating a full proforma invoice,
* please use the renewal preview endpoint.
*
* ## Restrictions
*
* Proforma invoices are only available on Relationship Invoicing sites. To create a proforma invoice,
* the subscription must not be in a group, must not be prepaid, and must be in a live state.
*
* @param subscriptionId The Chargify id of the subscription
* @return Response from the API call
*/
ProformaInvoicesController.prototype.createProformaInvoice = 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('POST');
mapped = req.prepareArgs({
subscriptionId: [subscriptionId, (0, schema_1.number)()]
});
req.appendTemplatePath(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["/subscriptions/", "/proforma_invoices.json"], ["/subscriptions/", "/proforma_invoices.json"])), mapped.subscriptionId);
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(proformaInvoice_1.proformaInvoiceSchema, requestOptions)];
});
});
};
/**
* By default, proforma invoices returned on the index will only include totals, not detailed
* breakdowns for `line_items`, `discounts`, `taxes`, `credits`, `payments`, or `custom_fields`. To
* include breakdowns, pass the specific field as a key in the query with a value set to `true`.
*
* @param subscriptionId The Chargify id of the subscription
* @param startDate The beginning date range for the invoice's Due Date, in the YYYY-
* MM-DD format.
* @param endDate The ending date range for the invoice's Due Date, in the YYYY-MM-
* DD format.
* @param status The current status of the invoice. Allowed Values: draft, open,
* paid, pending, voided
* @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 direction The sort direction of the returned invoices.
* @param lineItems Include line items data
* @param discounts Include discounts data
* @param taxes Include taxes data
* @param credits Include credits data
* @param payments Include payments data
* @param customFields Include custom fields data
* @return Response from the API call
*/
ProformaInvoicesController.prototype.listProformaInvoices = function (_a, requestOptions) {
var subscriptionId = _a.subscriptionId, startDate = _a.startDate, endDate = _a.endDate, status = _a.status, page = _a.page, perPage = _a.perPage, direction = _a.direction, lineItems = _a.lineItems, discounts = _a.discounts, taxes = _a.taxes, credits = _a.credits, payments = _a.payments, customFields = _a.customFields;
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({
subscriptionId: [subscriptionId, (0, schema_1.number)()],
startDate: [startDate, (0, schema_1.optional)((0, schema_1.string)())],
endDate: [endDate, (0, schema_1.optional)((0, schema_1.string)())],
status: [status, (0, schema_1.optional)(proformaInvoiceStatus_1.proformaInvoiceStatusSchema)],
page: [page, (0, schema_1.optional)((0, schema_1.number)())],
perPage: [perPage, (0, schema_1.optional)((0, schema_1.number)())],
direction: [direction, (0, schema_1.optional)(direction_1.directionSchema)],
lineItems: [lineItems, (0, schema_1.optional)((0, schema_1.boolean)())],
discounts: [discounts, (0, schema_1.optional)((0, schema_1.boolean)())],
taxes: [taxes, (0, schema_1.optional)((0, schema_1.boolean)())],
credits: [credits, (0, schema_1.optional)((0, schema_1.boolean)())],
payments: [payments, (0, schema_1.optional)((0, schema_1.boolean)())],
customFields: [customFields, (0, schema_1.optional)((0, schema_1.boolean)())]
});
req.query('start_date', mapped.startDate, core_1.commaPrefix);
req.query('end_date', mapped.endDate, core_1.commaPrefix);
req.query('status', mapped.status, core_1.commaPrefix);
req.query('page', mapped.page, core_1.commaPrefix);
req.query('per_page', mapped.perPage, core_1.commaPrefix);
req.query('direction', mapped.direction, core_1.commaPrefix);
req.query('line_items', mapped.lineItems, core_1.commaPrefix);
req.query('discounts', mapped.discounts, core_1.commaPrefix);
req.query('taxes', mapped.taxes, core_1.commaPrefix);
req.query('credits', mapped.credits, core_1.commaPrefix);
req.query('payments', mapped.payments, core_1.commaPrefix);
req.query('custom_fields', mapped.customFields, core_1.commaPrefix);
req.appendTemplatePath(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["/subscriptions/", "/proforma_invoices.json"], ["/subscriptions/", "/proforma_invoices.json"])), mapped.subscriptionId);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(listProformaInvoicesResponse_1.listProformaInvoicesResponseSchema, requestOptions)];
});
});
};
/**
* This endpoint will void a proforma invoice that has the status "draft".
*
* ## Restrictions
*
* Proforma invoices are only available on Relationship Invoicing sites.
*
* Only proforma invoices that have the appropriate status may be reopened. If the invoice identified
* by {uid} does not have the appropriate status, the response will have HTTP status code 422 and an
* error message.
*
* A reason for the void operation is required to be included in the request body. If one is not
* provided, the response will have HTTP status code 422 and an error message.
*
* @param proformaInvoiceUid The uid of the proforma invoice
* @param body
* @return Response from the API call
*/
ProformaInvoicesController.prototype.voidProformaInvoice = function (proformaInvoiceUid, 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({
proformaInvoiceUid: [proformaInvoiceUid, (0, schema_1.string)()],
body: [body, (0, schema_1.optional)(voidInvoiceRequest_1.voidInvoiceRequestSchema)]
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["/proforma_invoices/", "/void.json"], ["/proforma_invoices/", "/void.json"])), mapped.proformaInvoiceUid);
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(proformaInvoice_1.proformaInvoiceSchema, requestOptions)];
});
});
};
/**
* Return a preview of the data that will be included on a given subscription's proforma invoice if one
* were to be generated. It will have similar line items and totals as a renewal preview, but the
* response will be presented in the format of a proforma invoice. Consequently it will include
* additional information such as the name and addresses that will appear on the proforma invoice.
*
* The preview endpoint is subject to all the same conditions as the proforma invoice endpoint. For
* example, previews are only available on the Relationship Invoicing architecture, and previews cannot
* be made for end-of-life subscriptions.
*
* If all the data returned in the preview is as expected, you may then create a static proforma
* invoice and send it to your customer. The data within a preview will not be saved and will not be
* accessible after the call is made.
*
* Alternatively, if you have some proforma invoices already, you may make a preview call to determine
* whether any billing information for the subscription's upcoming renewal has changed.
*
* @param subscriptionId The Chargify id of the subscription
* @return Response from the API call
*/
ProformaInvoicesController.prototype.previewProformaInvoice = 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('POST');
mapped = req.prepareArgs({
subscriptionId: [subscriptionId, (0, schema_1.number)()]
});
req.appendTemplatePath(templateObject_7 || (templateObject_7 = tslib_1.__makeTemplateObject(["/subscriptions/", "/proforma_invoices/preview.json"], ["/subscriptions/", "/proforma_invoices/preview.json"])), mapped.subscriptionId);
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(proformaInvoice_1.proformaInvoiceSchema, requestOptions)];
});
});
};
/**
* This endpoint is only available for Relationship Invoicing sites. It cannot be used to create
* consolidated proforma invoices or preview prepaid subscriptions.
*
* Create a proforma invoice to preview costs before a subscription's signup. Like other proforma
* invoices, it can be emailed to the customer, voided, and publicly viewed on the chargifypay domain.
*
* Pass a payload that resembles a subscription create or signup preview request. For example, you can
* specify components, coupons/a referral, offers, custom pricing, and an existing customer or payment
* profile to populate a shipping or billing address.
*
* A product and customer first name, last name, and email are the minimum requirements. We recommend
* associating the proforma invoice with a customer_id to easily find their proforma invoices, since
* the subscription_id will always be blank.
*
* @param body
* @return Response from the API call
*/
ProformaInvoicesController.prototype.createSignupProformaInvoice = 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', '/subscriptions/proforma_invoices.json');
mapped = req.prepareArgs({
body: [body, (0, schema_1.optional)(createSubscriptionRequest_1.createSubscriptionRequestSchema)]
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.throwOn(400, proformaBadRequestErrorResponseError_1.ProformaBadRequestErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.throwOn(422, errorArrayMapResponseError_1.ErrorArrayMapResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(proformaInvoice_1.proformaInvoiceSchema, requestOptions)];
});
});
};
/**
* This endpoint is only available for Relationship Invoicing sites. It cannot be used to create
* consolidated proforma invoice previews or preview prepaid subscriptions.
*
* Create a signup preview in the format of a proforma invoice to preview costs before a subscription's
* signup. You have the option of optionally previewing the first renewal's costs as well. The proforma
* invoice preview will not be persisted.
*
* Pass a payload that resembles a subscription create or signup preview request. For example, you can
* specify components, coupons/a referral, offers, custom pricing, and an existing customer or payment
* profile to populate a shipping or billing address.
*
* A product and customer first name, last name, and email are the minimum requirements.
*
* @param include Choose to include a proforma invoice preview for the
* first renewal. Use in query
* `include=next_proforma_invoice`.
* @param body
* @return Response from the API call
*/
ProformaInvoicesController.prototype.previewSignupProformaInvoice = function (include, 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', '/subscriptions/proforma_invoices/preview.json');
mapped = req.prepareArgs({
include: [include, (0, schema_1.optional)(createSignupProformaPreviewInclude_1.createSignupProformaPreviewIncludeSchema)],
body: [body, (0, schema_1.optional)(createSubscriptionRequest_1.createSubscriptionRequestSchema)]
});
req.header('Content-Type', 'application/json');
req.query('include', mapped.include, core_1.commaPrefix);
req.json(mapped.body);
req.throwOn(400, proformaBadRequestErrorResponseError_1.ProformaBadRequestErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.throwOn(422, errorArrayMapResponseError_1.ErrorArrayMapResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(signupProformaPreviewResponse_1.signupProformaPreviewResponseSchema, requestOptions)];
});
});
};
return ProformaInvoicesController;
}(baseController_1.BaseController));
exports.ProformaInvoicesController = ProformaInvoicesController;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
//# sourceMappingURL=proformaInvoicesController.js.map