@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.
172 lines • 10.2 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.BillingPortalController = void 0;
var tslib_1 = require("tslib");
var core_js_1 = require("../core.js");
var autoInvite_js_1 = require("../models/autoInvite.js");
var customerResponse_js_1 = require("../models/customerResponse.js");
var portalManagementLink_js_1 = require("../models/portalManagementLink.js");
var resentInvitation_js_1 = require("../models/resentInvitation.js");
var revokedInvitation_js_1 = require("../models/revokedInvitation.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 tooManyManagementLinkRequestsError_js_1 = require("../errors/tooManyManagementLinkRequestsError.js");
var BillingPortalController = /** @class */ (function (_super) {
tslib_1.__extends(BillingPortalController, _super);
function BillingPortalController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* ## Billing Portal Documentation
*
* Full documentation on how the Billing Portal operates within the Advanced Billing UI can be located
* [here](https://maxio.zendesk.com/hc/en-us/articles/24252412965133-Billing-Portal-Overview).
*
* This documentation is focused on how the to configure the Billing Portal Settings, as well as
* Subscriber Interaction and Merchant Management of the Billing Portal.
*
* You can use this endpoint to enable Billing Portal access for a Customer, with the option of sending
* the Customer an Invitation email at the same time.
*
* ## Billing Portal Security
*
* If your customer has been invited to the Billing Portal, then they will receive a link to manage
* their subscription (the “Management URL”) automatically at the bottom of their statements, invoices,
* and receipts. **This link changes periodically for security and is only valid for 65 days.**
*
* If you need to provide your customer their Management URL through other means, you can retrieve it
* via the API. Because the URL is cryptographically signed with a timestamp, it is not possible for
* merchants to generate the URL without requesting it from Advanced Billing.
*
* In order to prevent abuse & overuse, we ask that you request a new URL only when absolutely
* necessary. Management URLs are good for 65 days, so you should re-use a previously generated one as
* much as possible. If you use the URL frequently (such as to display on your website), **do not**
* make an API request to Advanced Billing every time.
*
* @param customerId The Chargify id of the customer
* @param autoInvite When set to 1, an Invitation email will be sent to the Customer. When set to 0,
* or not sent, an email will not be sent. Use in query: `auto_invite=1`.
* @return Response from the API call
*/
BillingPortalController.prototype.enableBillingPortalForCustomer = function (customerId, autoInvite, 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({
customerId: [customerId, (0, schema_js_1.number)()],
autoInvite: [autoInvite, (0, schema_js_1.optional)(autoInvite_js_1.autoInviteSchema)],
});
req.query('auto_invite', mapped.autoInvite, core_js_1.commaPrefix);
req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/portal/customers/", "/enable.json"], ["/portal/customers/", "/enable.json"])), mapped.customerId);
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(customerResponse_js_1.customerResponseSchema, requestOptions)];
});
});
};
/**
* This method will provide to the API user the exact URL required for a subscriber to access the
* Billing Portal.
*
* ## Rules for Management Link API
*
* + When retrieving a management URL, multiple requests for the same customer in a short period will
* return the **same** URL
* + We will not generate a new URL for 15 days
* + You must cache and remember this URL if you are going to need it again within 15 days
* + Only request a new URL after the `new_link_available_at` date
* + You are limited to 15 requests for the same URL. If you make more than 15 requests before
* `new_link_available_at`, you will be blocked from further Management URL requests (with a response
* code `429`)
*
* @param customerId The Chargify id of the customer
* @return Response from the API call
*/
BillingPortalController.prototype.readBillingPortalLink = function (customerId, 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({ customerId: [customerId, (0, schema_js_1.number)()] });
req.appendTemplatePath(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["/portal/customers/", "/management_link.json"], ["/portal/customers/", "/management_link.json"])), mapped.customerId);
req.throwOn(422, errorListResponseError_js_1.ErrorListResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.throwOn(429, tooManyManagementLinkRequestsError_js_1.TooManyManagementLinkRequestsError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(portalManagementLink_js_1.portalManagementLinkSchema, requestOptions)];
});
});
};
/**
* You can resend a customer's Billing Portal invitation.
*
* If you attempt to resend an invitation 5 times within 30 minutes, you will receive a `422` response
* with `error` message in the body.
*
* If you attempt to resend an invitation when the Billing Portal is already disabled for a Customer,
* you will receive a `422` error response.
*
* If you attempt to resend an invitation when the Billing Portal is already disabled for a Customer,
* you will receive a `422` error response.
*
* If you attempt to resend an invitation when the Customer does not exist a Customer, you will receive
* a `404` error response.
*
* ## Limitations
*
* This endpoint will only return a JSON response.
*
* @param customerId The Chargify id of the customer
* @return Response from the API call
*/
BillingPortalController.prototype.resendBillingPortalInvitation = function (customerId, 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({ customerId: [customerId, (0, schema_js_1.number)()] });
req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/portal/customers/", "/invitations/invite.json"], ["/portal/customers/", "/invitations/invite.json"])), mapped.customerId);
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(resentInvitation_js_1.resentInvitationSchema, requestOptions)];
});
});
};
/**
* You can revoke a customer's Billing Portal invitation.
*
* If you attempt to revoke an invitation when the Billing Portal is already disabled for a Customer,
* you will receive a 422 error response.
*
* ## Limitations
*
* This endpoint will only return a JSON response.
*
* @param customerId The Chargify id of the customer
* @return Response from the API call
*/
BillingPortalController.prototype.revokeBillingPortalAccess = function (customerId, 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({ customerId: [customerId, (0, schema_js_1.number)()] });
req.appendTemplatePath(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["/portal/customers/", "/invitations/revoke.json"], ["/portal/customers/", "/invitations/revoke.json"])), mapped.customerId);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(revokedInvitation_js_1.revokedInvitationSchema, requestOptions)];
});
});
};
return BillingPortalController;
}(baseController_js_1.BaseController));
exports.BillingPortalController = BillingPortalController;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
//# sourceMappingURL=billingPortalController.js.map