@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.1 kB
JavaScript
"use strict";
/**
* AdvancedBilling
*
* This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
exports.__esModule = true;
exports.SubscriptionInvoiceAccountController = void 0;
var tslib_1 = require("tslib");
var core_1 = require("../core");
var accountBalances_1 = require("../models/accountBalances");
var createPrepaymentRequest_1 = require("../models/createPrepaymentRequest");
var createPrepaymentResponse_1 = require("../models/createPrepaymentResponse");
var deductServiceCreditRequest_1 = require("../models/deductServiceCreditRequest");
var issueServiceCreditRequest_1 = require("../models/issueServiceCreditRequest");
var listPrepaymentsFilter_1 = require("../models/listPrepaymentsFilter");
var listServiceCreditsResponse_1 = require("../models/listServiceCreditsResponse");
var prepaymentResponse_1 = require("../models/prepaymentResponse");
var prepaymentsResponse_1 = require("../models/prepaymentsResponse");
var refundPrepaymentRequest_1 = require("../models/refundPrepaymentRequest");
var serviceCredit_1 = require("../models/serviceCredit");
var sortingDirection_1 = require("../models/sortingDirection");
var schema_1 = require("../schema");
var baseController_1 = require("./baseController");
var core_2 = require("@apimatic/core");
var errorListResponseError_1 = require("../errors/errorListResponseError");
var refundPrepaymentBaseErrorsResponseError_1 = require("../errors/refundPrepaymentBaseErrorsResponseError");
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_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_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.
*
* Please note that you **can't** pass `amount_in_cents`.
*
*
* @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_1.number)()],
body: [body, (0, schema_1.optional)(createPrepaymentRequest_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_2.ApiError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(createPrepaymentResponse_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) {
var subscriptionId = _a.subscriptionId, page = _a.page, perPage = _a.perPage, filter = _a.filter;
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)()],
page: [page, (0, schema_1.optional)((0, schema_1.number)())],
perPage: [perPage, (0, schema_1.optional)((0, schema_1.number)())],
filter: [filter, (0, schema_1.optional)(listPrepaymentsFilter_1.listPrepaymentsFilterSchema)]
});
req.query('page', mapped.page, core_1.commaPrefix);
req.query('per_page', mapped.perPage, core_1.commaPrefix);
req.query('filter', mapped.filter, core_1.commaPrefix);
req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/subscriptions/", "/prepayments.json"], ["/subscriptions/", "/prepayments.json"])), mapped.subscriptionId);
req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(prepaymentsResponse_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_1.number)()],
body: [body, (0, schema_1.optional)(issueServiceCreditRequest_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_2.ApiError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(serviceCredit_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_1.number)()],
body: [body, (0, schema_1.optional)(deductServiceCreditRequest_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_2.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_1.number)()],
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)(sortingDirection_1.sortingDirectionSchema)]
});
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.appendTemplatePath(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["/subscriptions/", "/service_credits/list.json"], ["/subscriptions/", "/service_credits/list.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(listServiceCreditsResponse_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_1.number)()],
prepaymentId: [prepaymentId, (0, schema_1.bigint)()],
body: [body, (0, schema_1.optional)(refundPrepaymentRequest_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_2.ApiError, true, "Not Found:'{$response.body}'");
req.throwOn(400, refundPrepaymentBaseErrorsResponseError_1.RefundPrepaymentBaseErrorsResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.throwOn(422, core_2.ApiError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(prepaymentResponse_1.prepaymentResponseSchema, requestOptions)];
});
});
};
return SubscriptionInvoiceAccountController;
}(baseController_1.BaseController));
exports.SubscriptionInvoiceAccountController = SubscriptionInvoiceAccountController;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
//# sourceMappingURL=subscriptionInvoiceAccountController.js.map