@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.
321 lines • 20.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.SubscriptionGroupsController = void 0;
var tslib_1 = require("tslib");
var core_js_1 = require("../core.js");
var addSubscriptionToAGroup_js_1 = require("../models/addSubscriptionToAGroup.js");
var createSubscriptionGroupRequest_js_1 = require("../models/createSubscriptionGroupRequest.js");
var deleteSubscriptionGroupResponse_js_1 = require("../models/deleteSubscriptionGroupResponse.js");
var fullSubscriptionGroupResponse_js_1 = require("../models/fullSubscriptionGroupResponse.js");
var listSubscriptionGroupsResponse_js_1 = require("../models/listSubscriptionGroupsResponse.js");
var subscriptionGroupInclude_js_1 = require("../models/subscriptionGroupInclude.js");
var subscriptionGroupResponse_js_1 = require("../models/subscriptionGroupResponse.js");
var subscriptionGroupSignupRequest_js_1 = require("../models/subscriptionGroupSignupRequest.js");
var subscriptionGroupSignupResponse_js_1 = require("../models/subscriptionGroupSignupResponse.js");
var subscriptionGroupsListInclude_js_1 = require("../models/subscriptionGroupsListInclude.js");
var updateSubscriptionGroupRequest_js_1 = require("../models/updateSubscriptionGroupRequest.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 subscriptionGroupCreateErrorResponseError_js_1 = require("../errors/subscriptionGroupCreateErrorResponseError.js");
var subscriptionGroupSignupErrorResponseError_js_1 = require("../errors/subscriptionGroupSignupErrorResponseError.js");
var subscriptionGroupUpdateErrorResponseError_js_1 = require("../errors/subscriptionGroupUpdateErrorResponseError.js");
var SubscriptionGroupsController = /** @class */ (function (_super) {
tslib_1.__extends(SubscriptionGroupsController, _super);
function SubscriptionGroupsController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Create multiple subscriptions at once under the same customer and consolidate them into a
* subscription group.
*
* You must provide one and only one of the `payer_id`/`payer_reference`/`payer_attributes` for the
* customer attached to the group.
*
* You must provide one and only one of the
* `payment_profile_id`/`credit_card_attributes`/`bank_account_attributes` for the payment profile
* attached to the group.
*
* Only one of the `subscriptions` can have `"primary": true` attribute set.
*
* When passing product to a subscription you can use either `product_id` or `product_handle` or
* `offer_id`. You can also use `custom_price` instead.
* The subscription request examples below will be split into two sections.
* The first section, "Subscription Customization", will focus on passing different information with a
* subscription, such as components, calendar billing, and custom fields. These examples will presume
* you are using a secure chargify_token generated by Chargify.js.
*
* @param body
* @return Response from the API call
*/
SubscriptionGroupsController.prototype.signupWithSubscriptionGroup = 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', '/subscription_groups/signup.json');
mapped = req.prepareArgs({
body: [body, (0, schema_js_1.optional)(subscriptionGroupSignupRequest_js_1.subscriptionGroupSignupRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.throwOn(422, subscriptionGroupSignupErrorResponseError_js_1.SubscriptionGroupSignupErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(subscriptionGroupSignupResponse_js_1.subscriptionGroupSignupResponseSchema, requestOptions)];
});
});
};
/**
* Creates a subscription group with given members.
*
* @param body
* @return Response from the API call
*/
SubscriptionGroupsController.prototype.createSubscriptionGroup = 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', '/subscription_groups.json');
mapped = req.prepareArgs({
body: [body, (0, schema_js_1.optional)(createSubscriptionGroupRequest_js_1.createSubscriptionGroupRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.throwOn(422, subscriptionGroupCreateErrorResponseError_js_1.SubscriptionGroupCreateErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(subscriptionGroupResponse_js_1.subscriptionGroupResponseSchema, requestOptions)];
});
});
};
/**
* Returns an array of subscription groups for the site. The response is paginated and will return a
* `meta` key with pagination information.
*
* #### Account Balance Information
*
* Account balance information for the subscription groups is not returned by default. If this
* information is desired, the `include[]=account_balances` parameter must be provided with the request.
*
* @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 include A list of additional information to include in the response.
* The following values are supported: - `account_balances`:
* Account balance information for the subscription groups. Use in
* query: `include[]=account_balances`
* @return Response from the API call
*/
SubscriptionGroupsController.prototype.listSubscriptionGroups = function (_a, requestOptions_1) {
return tslib_1.__awaiter(this, arguments, void 0, function (_b, requestOptions) {
var req, mapped;
var page = _b.page, perPage = _b.perPage, include = _b.include;
return tslib_1.__generator(this, function (_c) {
req = this.createRequest('GET', '/subscription_groups.json');
mapped = req.prepareArgs({
page: [page, (0, schema_js_1.optional)((0, schema_js_1.number)())],
perPage: [perPage, (0, schema_js_1.optional)((0, schema_js_1.number)())],
include: [include, (0, schema_js_1.optional)((0, schema_js_1.array)(subscriptionGroupsListInclude_js_1.subscriptionGroupsListIncludeSchema))],
});
req.query('page', mapped.page, core_js_1.unindexedPrefix);
req.query('per_page', mapped.perPage, core_js_1.unindexedPrefix);
req.query('include', mapped.include, core_js_1.unindexedPrefix);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(listSubscriptionGroupsResponse_js_1.listSubscriptionGroupsResponseSchema, requestOptions)];
});
});
};
/**
* Use this endpoint to find subscription group details.
*
* #### Current Billing Amount in Cents
*
* Current billing amount for the subscription group is not returned by default. If this information is
* desired, the `include[]=current_billing_amount_in_cents` parameter must be provided with the request.
*
* @param uid The uid of the subscription group
* @param include Allows including additional data in the response. Use in query:
* `include[]=current_billing_amount_in_cents`.
* @return Response from the API call
*/
SubscriptionGroupsController.prototype.readSubscriptionGroup = function (uid, include, 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({
uid: [uid, (0, schema_js_1.string)()],
include: [include, (0, schema_js_1.optional)((0, schema_js_1.array)(subscriptionGroupInclude_js_1.subscriptionGroupIncludeSchema))],
});
req.query('include', mapped.include, core_js_1.unindexedPrefix);
req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/subscription_groups/", ".json"], ["/subscription_groups/", ".json"])), mapped.uid);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(fullSubscriptionGroupResponse_js_1.fullSubscriptionGroupResponseSchema, requestOptions)];
});
});
};
/**
* Use this endpoint to update subscription group members.
* `"member_ids"` should contain an array of both subscription IDs to set as group members and
* subscription IDs already present in the groups. Not including them will result in removing them from
* subscription group. To clean up members, just leave the array empty.
*
* @param uid The uid of the subscription group
* @param body
* @return Response from the API call
*/
SubscriptionGroupsController.prototype.updateSubscriptionGroupMembers = function (uid, 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('PUT');
mapped = req.prepareArgs({
uid: [uid, (0, schema_js_1.string)()],
body: [body, (0, schema_js_1.optional)(updateSubscriptionGroupRequest_js_1.updateSubscriptionGroupRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["/subscription_groups/", ".json"], ["/subscription_groups/", ".json"])), mapped.uid);
req.throwOn(422, subscriptionGroupUpdateErrorResponseError_js_1.SubscriptionGroupUpdateErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(subscriptionGroupResponse_js_1.subscriptionGroupResponseSchema, requestOptions)];
});
});
};
/**
* Use this endpoint to delete subscription group.
* Only groups without members can be deleted
*
* @param uid The uid of the subscription group
* @return Response from the API call
*/
SubscriptionGroupsController.prototype.deleteSubscriptionGroup = 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('DELETE');
mapped = req.prepareArgs({ uid: [uid, (0, schema_js_1.string)()] });
req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/subscription_groups/", ".json"], ["/subscription_groups/", ".json"])), mapped.uid);
req.throwOn(404, core_1.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(deleteSubscriptionGroupResponse_js_1.deleteSubscriptionGroupResponseSchema, requestOptions)];
});
});
};
/**
* Use this endpoint to find subscription group associated with subscription.
*
* If the subscription is not in a group endpoint will return 404 code.
*
* @param subscriptionId The Advanced Billing id of the subscription associated with the subscription
* group
* @return Response from the API call
*/
SubscriptionGroupsController.prototype.findSubscriptionGroup = 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', '/subscription_groups/lookup.json');
mapped = req.prepareArgs({
subscriptionId: [subscriptionId, (0, schema_js_1.string)()],
});
req.query('subscription_id', mapped.subscriptionId, core_js_1.commaPrefix);
req.throwOn(404, core_1.ApiError, true, "Not Found:'{$response.body}'");
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(fullSubscriptionGroupResponse_js_1.fullSubscriptionGroupResponseSchema, requestOptions)];
});
});
};
/**
* For sites making use of the [Relationship Billing](https://maxio.zendesk.com/hc/en-
* us/articles/24252287829645-Advanced-Billing-Invoices-Overview) and [Customer Hierarchy](https:
* //maxio.zendesk.com/hc/en-us/articles/24252185211533-Customer-Hierarchies-WhoPays#customer-
* hierarchies) features, it is possible to add existing subscriptions to subscription groups.
*
* Passing `group` parameters with a `target` containing a `type` and optional `id` is all that's
* needed. When the `target` parameter specifies a `"customer"` or `"subscription"` that is already
* part of a hierarchy, the subscription will become a member of the customer's subscription group. If
* the target customer or subscription is not part of a subscription group, a new group will be created
* and the subscription will become part of the group with the specified target customer set as the
* responsible payer for the group's subscriptions.
*
* **Note:** In order to add an existing subscription to a subscription group, it must belong to either
* the same customer record as the target, or be within the same customer hierarchy.
*
* Rather than specifying a customer, the `target` parameter could instead simply have a value of
* * `"self"` which indicates the subscription will be paid for not by some other customer, but by the
* subscribing customer,
* * `"parent"` which indicates the subscription will be paid for by the subscribing customer's parent
* within a customer hierarchy, or
* * `"eldest"` which indicates the subscription will be paid for by the root-level customer in the
* subscribing customer's hierarchy.
*
* To create a new subscription into a subscription group, reference the following:
* [Create Subscription in a Subscription Group](https://developers.chargify.com/docs/api-
* docs/d571659cf0f24-create-subscription#subscription-in-a-subscription-group)
*
*
* @param subscriptionId The Chargify id of the subscription
* @param body
* @return Response from the API call
*/
SubscriptionGroupsController.prototype.addSubscriptionToGroup = 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)(addSubscriptionToAGroup_js_1.addSubscriptionToAGroupSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["/subscriptions/", "/group.json"], ["/subscriptions/", "/group.json"])), mapped.subscriptionId);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(subscriptionGroupResponse_js_1.subscriptionGroupResponseSchema, requestOptions)];
});
});
};
/**
* For sites making use of the [Relationship Billing](https://maxio.zendesk.com/hc/en-
* us/articles/24252287829645-Advanced-Billing-Invoices-Overview) and [Customer Hierarchy](https:
* //maxio.zendesk.com/hc/en-us/articles/24252185211533-Customer-Hierarchies-WhoPays#customer-
* hierarchies) features, it is possible to remove existing subscription from subscription group.
*
* @param subscriptionId The Chargify id of the subscription
* @return Response from the API call
*/
SubscriptionGroupsController.prototype.removeSubscriptionFromGroup = 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('DELETE');
mapped = req.prepareArgs({
subscriptionId: [subscriptionId, (0, schema_js_1.number)()],
});
req.appendTemplatePath(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["/subscriptions/", "/group.json"], ["/subscriptions/", "/group.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.call(requestOptions)];
});
});
};
return SubscriptionGroupsController;
}(baseController_js_1.BaseController));
exports.SubscriptionGroupsController = SubscriptionGroupsController;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
//# sourceMappingURL=subscriptionGroupsController.js.map