UNPKG

@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.

317 lines 19.7 kB
"use strict"; /** * AdvancedBilling * * This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ). */ exports.__esModule = true; exports.SubscriptionGroupsController = void 0; var tslib_1 = require("tslib"); var core_1 = require("../core"); var addSubscriptionToAGroup_1 = require("../models/addSubscriptionToAGroup"); var createSubscriptionGroupRequest_1 = require("../models/createSubscriptionGroupRequest"); var deleteSubscriptionGroupResponse_1 = require("../models/deleteSubscriptionGroupResponse"); var fullSubscriptionGroupResponse_1 = require("../models/fullSubscriptionGroupResponse"); var listSubscriptionGroupsResponse_1 = require("../models/listSubscriptionGroupsResponse"); var subscriptionGroupInclude_1 = require("../models/subscriptionGroupInclude"); var subscriptionGroupResponse_1 = require("../models/subscriptionGroupResponse"); var subscriptionGroupSignupRequest_1 = require("../models/subscriptionGroupSignupRequest"); var subscriptionGroupSignupResponse_1 = require("../models/subscriptionGroupSignupResponse"); var subscriptionGroupsListInclude_1 = require("../models/subscriptionGroupsListInclude"); var updateSubscriptionGroupRequest_1 = require("../models/updateSubscriptionGroupRequest"); var schema_1 = require("../schema"); var baseController_1 = require("./baseController"); var core_2 = require("@apimatic/core"); var errorListResponseError_1 = require("../errors/errorListResponseError"); var subscriptionGroupCreateErrorResponseError_1 = require("../errors/subscriptionGroupCreateErrorResponseError"); var subscriptionGroupSignupErrorResponseError_1 = require("../errors/subscriptionGroupSignupErrorResponseError"); var subscriptionGroupUpdateErrorResponseError_1 = require("../errors/subscriptionGroupUpdateErrorResponseError"); 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. * * @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_1.optional)(subscriptionGroupSignupRequest_1.subscriptionGroupSignupRequestSchema)] }); req.header('Content-Type', 'application/json'); req.json(mapped.body); req.throwOn(422, subscriptionGroupSignupErrorResponseError_1.SubscriptionGroupSignupErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'."); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.callAsJson(subscriptionGroupSignupResponse_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_1.optional)(createSubscriptionGroupRequest_1.createSubscriptionGroupRequestSchema)] }); req.header('Content-Type', 'application/json'); req.json(mapped.body); req.throwOn(422, subscriptionGroupCreateErrorResponseError_1.SubscriptionGroupCreateErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'."); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.callAsJson(subscriptionGroupResponse_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) { var page = _a.page, perPage = _a.perPage, include = _a.include; return tslib_1.__awaiter(this, void 0, void 0, function () { var req, mapped; return tslib_1.__generator(this, function (_b) { req = this.createRequest('GET', '/subscription_groups.json'); mapped = req.prepareArgs({ page: [page, (0, schema_1.optional)((0, schema_1.number)())], perPage: [perPage, (0, schema_1.optional)((0, schema_1.number)())], include: [include, (0, schema_1.optional)((0, schema_1.array)(subscriptionGroupsListInclude_1.subscriptionGroupsListIncludeSchema))] }); req.query('page', mapped.page, core_1.unindexedPrefix); req.query('per_page', mapped.perPage, core_1.unindexedPrefix); req.query('include', mapped.include, core_1.unindexedPrefix); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.callAsJson(listSubscriptionGroupsResponse_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_1.string)()], include: [include, (0, schema_1.optional)((0, schema_1.array)(subscriptionGroupInclude_1.subscriptionGroupIncludeSchema))] }); req.query('include', mapped.include, core_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_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_1.string)()], body: [body, (0, schema_1.optional)(updateSubscriptionGroupRequest_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_1.SubscriptionGroupUpdateErrorResponseError, true, "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'."); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.callAsJson(subscriptionGroupResponse_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_1.string)()] }); req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/subscription_groups/", ".json"], ["/subscription_groups/", ".json"])), mapped.uid); req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'"); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.callAsJson(deleteSubscriptionGroupResponse_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_1.string)()] }); req.query('subscription_id', mapped.subscriptionId, core_1.commaPrefix); req.throwOn(404, core_2.ApiError, true, "Not Found:'{$response.body}'"); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.callAsJson(fullSubscriptionGroupResponse_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. * * **Please 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, please 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_1.number)()], body: [body, (0, schema_1.optional)(addSubscriptionToAGroup_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_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_1.number)()] }); req.appendTemplatePath(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["/subscriptions/", "/group.json"], ["/subscriptions/", "/group.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.call(requestOptions)]; }); }); }; return SubscriptionGroupsController; }(baseController_1.BaseController)); exports.SubscriptionGroupsController = SubscriptionGroupsController; var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5; //# sourceMappingURL=subscriptionGroupsController.js.map