@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.
260 lines • 17.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.SubscriptionInvoiceAccountController = void 0;
var tslib_1 = require("tslib");
var core_js_1 = require("../core.js");
var accountBalances_js_1 = require("../models/accountBalances.js");
var createPrepaymentRequest_js_1 = require("../models/createPrepaymentRequest.js");
var createPrepaymentResponse_js_1 = require("../models/createPrepaymentResponse.js");
var deductServiceCreditRequest_js_1 = require("../models/deductServiceCreditRequest.js");
var issueServiceCreditRequest_js_1 = require("../models/issueServiceCreditRequest.js");
var listPrepaymentsFilter_js_1 = require("../models/listPrepaymentsFilter.js");
var listServiceCreditsResponse_js_1 = require("../models/listServiceCreditsResponse.js");
var prepaymentResponse_js_1 = require("../models/prepaymentResponse.js");
var prepaymentsResponse_js_1 = require("../models/prepaymentsResponse.js");
var refundPrepaymentRequest_js_1 = require("../models/refundPrepaymentRequest.js");
var serviceCredit_js_1 = require("../models/serviceCredit.js");
var sortingDirection_js_1 = require("../models/sortingDirection.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 refundPrepaymentBaseErrorsResponseError_js_1 = require("../errors/refundPrepaymentBaseErrorsResponseError.js");
var SubscriptionInvoiceAccountController = /** @class */ (function (_super) {
tslib_1.__extends(SubscriptionInvoiceAccountController, _super);
function SubscriptionInvoiceAccountController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Returns the `balance_in_cents` of the Subscription's Pending Discount, Service Credit, and
* Prepayment accounts, as well as the sum of the Subscription's open, payable invoices.
*
* @param subscriptionId The Chargify id of the subscription
* @return Response from the API call
*/
SubscriptionInvoiceAccountController.prototype.readAccountBalances = 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_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/subscriptions/", "/account_balances.json"], ["/subscriptions/", "/account_balances.json"])), mapped.subscriptionId);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(accountBalances_js_1.accountBalancesSchema, requestOptions)];
});
});
};
/**
* ## Create Prepayment
*
* In order to specify a prepayment made against a subscription, specify the `amount, memo, details,
* method`.
*
* When the `method` specified is `"credit_card_on_file"`, the prepayment amount will be collected
* using the default credit card payment profile and applied to the prepayment account balance. This
* is especially useful for manual replenishment of prepaid subscriptions.
*
* Note that passing `amount_in_cents` is now allowed.
*
*
* @param subscriptionId The Chargify id of the subscription
* @param body
* @return Response from the API call
*/
SubscriptionInvoiceAccountController.prototype.createPrepayment = 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)(createPrepaymentRequest_js_1.createPrepaymentRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["/subscriptions/", "/prepayments.json"], ["/subscriptions/", "/prepayments.json"])), mapped.subscriptionId);
req.throwOn(422, core_1.ApiError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(createPrepaymentResponse_js_1.createPrepaymentResponseSchema, requestOptions)];
});
});
};
/**
* This request will list a subscription's prepayments.
*
* @param subscriptionId The Chargify id of the subscription
* @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 filter Filter to use for List Prepayments operations
* @return Response from the API call
*/
SubscriptionInvoiceAccountController.prototype.listPrepayments = function (_a, requestOptions_1) {
return tslib_1.__awaiter(this, arguments, void 0, function (_b, requestOptions) {
var req, mapped;
var subscriptionId = _b.subscriptionId, page = _b.page, perPage = _b.perPage, filter = _b.filter;
return tslib_1.__generator(this, function (_c) {
req = this.createRequest('GET');
mapped = req.prepareArgs({
subscriptionId: [subscriptionId, (0, schema_js_1.number)()],
page: [page, (0, schema_js_1.optional)((0, schema_js_1.number)())],
perPage: [perPage, (0, schema_js_1.optional)((0, schema_js_1.number)())],
filter: [filter, (0, schema_js_1.optional)(listPrepaymentsFilter_js_1.listPrepaymentsFilterSchema)],
});
req.query('page', mapped.page, core_js_1.commaPrefix);
req.query('per_page', mapped.perPage, core_js_1.commaPrefix);
req.query('filter', mapped.filter, core_js_1.commaPrefix);
req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/subscriptions/", "/prepayments.json"], ["/subscriptions/", "/prepayments.json"])), mapped.subscriptionId);
req.throwOn(404, core_1.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(prepaymentsResponse_js_1.prepaymentsResponseSchema, requestOptions)];
});
});
};
/**
* Credit will be added to the subscription in the amount specified in the request body. The credit is
* subsequently applied to the next generated invoice.
*
* @param subscriptionId The Chargify id of the subscription
* @param body
* @return Response from the API call
*/
SubscriptionInvoiceAccountController.prototype.issueServiceCredit = 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)(issueServiceCreditRequest_js_1.issueServiceCreditRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["/subscriptions/", "/service_credits.json"], ["/subscriptions/", "/service_credits.json"])), mapped.subscriptionId);
req.throwOn(422, core_1.ApiError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(serviceCredit_js_1.serviceCreditSchema, requestOptions)];
});
});
};
/**
* Credit will be removed from the subscription in the amount specified in the request body. The credit
* amount being deducted must be equal to or less than the current credit balance.
*
* @param subscriptionId The Chargify id of the subscription
* @param body
* @return Response from the API call
*/
SubscriptionInvoiceAccountController.prototype.deductServiceCredit = 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)(deductServiceCreditRequest_js_1.deductServiceCreditRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["/subscriptions/", "/service_credit_deductions.json"], ["/subscriptions/", "/service_credit_deductions.json"])), mapped.subscriptionId);
req.throwOn(422, core_1.ApiError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.call(requestOptions)];
});
});
};
/**
* This request will list a subscription's service credits.
*
* @param subscriptionId The Chargify id of the subscription
* @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 Controls the order in which results are returned. Use in query
* `direction=asc`.
* @return Response from the API call
*/
SubscriptionInvoiceAccountController.prototype.listServiceCredits = function (subscriptionId, page, perPage, direction, 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)()],
page: [page, (0, schema_js_1.optional)((0, schema_js_1.number)())],
perPage: [perPage, (0, schema_js_1.optional)((0, schema_js_1.number)())],
direction: [direction, (0, schema_js_1.optional)(sortingDirection_js_1.sortingDirectionSchema)],
});
req.query('page', mapped.page, core_js_1.commaPrefix);
req.query('per_page', mapped.perPage, core_js_1.commaPrefix);
req.query('direction', mapped.direction, core_js_1.commaPrefix);
req.appendTemplatePath(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["/subscriptions/", "/service_credits/list.json"], ["/subscriptions/", "/service_credits/list.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(listServiceCreditsResponse_js_1.listServiceCreditsResponseSchema, requestOptions)];
});
});
};
/**
* This endpoint will refund, completely or partially, a particular prepayment applied to a
* subscription. The `prepayment_id` will be the account transaction ID of the original payment. The
* prepayment must have some amount remaining in order to be refunded.
*
* The amount may be passed either as a decimal, with `amount`, or an integer in cents, with
* `amount_in_cents`.
*
* @param subscriptionId The Chargify id of the subscription
* @param prepaymentId id of prepayment
* @param body
* @return Response from the API call
*/
SubscriptionInvoiceAccountController.prototype.refundPrepayment = function (subscriptionId, prepaymentId, 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)()],
prepaymentId: [prepaymentId, (0, schema_js_1.bigint)()],
body: [body, (0, schema_js_1.optional)(refundPrepaymentRequest_js_1.refundPrepaymentRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_7 || (templateObject_7 = tslib_1.__makeTemplateObject(["/subscriptions/", "/prepayments/", "/refunds.json"], ["/subscriptions/", "/prepayments/", "/refunds.json"])), mapped.subscriptionId, mapped.prepaymentId);
req.throwOn(404, core_1.ApiError, true, "Not Found:'{$response.body}'");
req.throwOn(400, refundPrepaymentBaseErrorsResponseError_js_1.RefundPrepaymentBaseErrorsResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.throwOn(422, core_1.ApiError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(prepaymentResponse_js_1.prepaymentResponseSchema, requestOptions)];
});
});
};
return SubscriptionInvoiceAccountController;
}(baseController_js_1.BaseController));
exports.SubscriptionInvoiceAccountController = SubscriptionInvoiceAccountController;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
//# sourceMappingURL=subscriptionInvoiceAccountController.js.map