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.

228 lines 12.9 kB
"use strict"; /** * AdvancedBilling * * This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ). */ exports.__esModule = true; exports.WebhooksController = void 0; var tslib_1 = require("tslib"); var core_1 = require("../core"); var createOrUpdateEndpointRequest_1 = require("../models/createOrUpdateEndpointRequest"); var enableWebhooksRequest_1 = require("../models/enableWebhooksRequest"); var enableWebhooksResponse_1 = require("../models/enableWebhooksResponse"); var endpoint_1 = require("../models/endpoint"); var endpointResponse_1 = require("../models/endpointResponse"); var replayWebhooksRequest_1 = require("../models/replayWebhooksRequest"); var replayWebhooksResponse_1 = require("../models/replayWebhooksResponse"); var webhookOrder_1 = require("../models/webhookOrder"); var webhookResponse_1 = require("../models/webhookResponse"); var webhookStatus_1 = require("../models/webhookStatus"); var schema_1 = require("../schema"); var baseController_1 = require("./baseController"); var core_2 = require("@apimatic/core"); var errorListResponseError_1 = require("../errors/errorListResponseError"); var WebhooksController = /** @class */ (function (_super) { tslib_1.__extends(WebhooksController, _super); function WebhooksController() { return _super !== null && _super.apply(this, arguments) || this; } /** * ## Webhooks Intro * * The Webhooks API allows you to view a list of all webhooks and to selectively resend individual or * groups of webhooks. Webhooks will be sent on endpoints specified by you. Endpoints can be added via * API or Web UI. There is also an option to enable / disable webhooks via API request. * * We recommend that you review Advanced Billing's webhook documentation located in our help site. The * following resources will help guide you on how to use webhooks in Advanced Billing, in addition to * these webhook endpoints: * * + [Adding/editing new webhooks](https://maxio.zendesk.com/hc/en-us/articles/24286723085197- * Webhooks#configure-webhook-url) * + [Webhooks introduction and delivery information](https://maxio.zendesk.com/hc/en- * us/articles/24266143173901-Webhooks-Overview) * + [Main webhook reference](https://maxio.zendesk.com/hc/en-us/articles/24266136649869-Webhooks- * Reference) * + [Available webhooks and payloads](https://maxio.zendesk.com/hc/en-us/articles/24266136649869- * Webhooks-Reference#events) * * ## List Webhooks for a Site * * This method allows you to fetch data about webhooks. You can pass query parameters if you want to * filter webhooks. * * @param status Webhooks with matching status would be returned. * @param sinceDate Format YYYY-MM-DD. Returns Webhooks with the created_at date greater than or * equal to the one specified. * @param untilDate Format YYYY-MM-DD. Returns Webhooks with the created_at date less than or * equal to the one specified. * @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 order The order in which the Webhooks are returned. * @param subscription The Advanced Billing id of a subscription you'd like to filter for * @return Response from the API call */ WebhooksController.prototype.listWebhooks = function (_a, requestOptions) { var status = _a.status, sinceDate = _a.sinceDate, untilDate = _a.untilDate, page = _a.page, perPage = _a.perPage, order = _a.order, subscription = _a.subscription; return tslib_1.__awaiter(this, void 0, void 0, function () { var req, mapped; return tslib_1.__generator(this, function (_b) { req = this.createRequest('GET', '/webhooks.json'); mapped = req.prepareArgs({ status: [status, (0, schema_1.optional)(webhookStatus_1.webhookStatusSchema)], sinceDate: [sinceDate, (0, schema_1.optional)((0, schema_1.string)())], untilDate: [untilDate, (0, schema_1.optional)((0, schema_1.string)())], page: [page, (0, schema_1.optional)((0, schema_1.number)())], perPage: [perPage, (0, schema_1.optional)((0, schema_1.number)())], order: [order, (0, schema_1.optional)(webhookOrder_1.webhookOrderSchema)], subscription: [subscription, (0, schema_1.optional)((0, schema_1.number)())] }); req.query('status', mapped.status, core_1.commaPrefix); req.query('since_date', mapped.sinceDate, core_1.commaPrefix); req.query('until_date', mapped.untilDate, core_1.commaPrefix); req.query('page', mapped.page, core_1.commaPrefix); req.query('per_page', mapped.perPage, core_1.commaPrefix); req.query('order', mapped.order, core_1.commaPrefix); req.query('subscription', mapped.subscription, core_1.commaPrefix); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.callAsJson((0, schema_1.array)(webhookResponse_1.webhookResponseSchema), requestOptions)]; }); }); }; /** * This method allows you to enable webhooks via API for your site * * @param body * @return Response from the API call */ WebhooksController.prototype.enableWebhooks = 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('PUT', '/webhooks/settings.json'); mapped = req.prepareArgs({ body: [body, (0, schema_1.optional)(enableWebhooksRequest_1.enableWebhooksRequestSchema)] }); req.header('Content-Type', 'application/json'); req.json(mapped.body); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.callAsJson(enableWebhooksResponse_1.enableWebhooksResponseSchema, requestOptions)]; }); }); }; /** * Posting to the replay endpoint does not immediately resend the webhooks. They are added to a queue * and will be sent as soon as possible, depending on available system resources. * * You may submit an array of up to 1000 webhook IDs to replay in the request. * * @param body * @return Response from the API call */ WebhooksController.prototype.replayWebhooks = 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', '/webhooks/replay.json'); mapped = req.prepareArgs({ body: [body, (0, schema_1.optional)(replayWebhooksRequest_1.replayWebhooksRequestSchema)] }); req.header('Content-Type', 'application/json'); req.json(mapped.body); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.callAsJson(replayWebhooksResponse_1.replayWebhooksResponseSchema, requestOptions)]; }); }); }; /** * The Chargify API allows you to create an endpoint and assign a list of webhooks subscriptions * (events) to it. * * You can check available events here. * [Event keys](https://maxio.zendesk.com/hc/en-us/articles/24266136649869-Webhooks-Reference#events) * * @param body * @return Response from the API call */ WebhooksController.prototype.createEndpoint = 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', '/endpoints.json'); mapped = req.prepareArgs({ body: [body, (0, schema_1.optional)(createOrUpdateEndpointRequest_1.createOrUpdateEndpointRequestSchema)] }); req.header('Content-Type', 'application/json'); req.json(mapped.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(endpointResponse_1.endpointResponseSchema, requestOptions)]; }); }); }; /** * This method returns created endpoints for site. * * @return Response from the API call */ WebhooksController.prototype.listEndpoints = function (requestOptions) { return tslib_1.__awaiter(this, void 0, void 0, function () { var req; return tslib_1.__generator(this, function (_a) { req = this.createRequest('GET', '/endpoints.json'); req.authenticate([{ basicAuth: true }]); return [2 /*return*/, req.callAsJson((0, schema_1.array)(endpoint_1.endpointSchema), requestOptions)]; }); }); }; /** * You can update an Endpoint via the API with a PUT request to the resource endpoint. * * You can change the `url` of your endpoint which consumes webhooks or list of `webhook_subscriptions`. * Check available [Event keys](https://maxio.zendesk.com/hc/en-us/articles/24266136649869-Webhooks- * Reference#events). * * Always send a complete list of events which you want subscribe/watch. * Sending an PUT request for existing endpoint with empty list of `webhook_subscriptions` will end * with unsubscribe from all events. * * If you want unsubscribe from specific event, just send a list of `webhook_subscriptions` without the * specific event key. * * @param endpointId The Advanced Billing id for the endpoint that should * be updated * @param body * @return Response from the API call */ WebhooksController.prototype.updateEndpoint = function (endpointId, 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({ endpointId: [endpointId, (0, schema_1.number)()], body: [body, (0, schema_1.optional)(createOrUpdateEndpointRequest_1.createOrUpdateEndpointRequestSchema)] }); req.header('Content-Type', 'application/json'); req.json(mapped.body); req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/endpoints/", ".json"], ["/endpoints/", ".json"])), mapped.endpointId); 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(endpointResponse_1.endpointResponseSchema, requestOptions)]; }); }); }; return WebhooksController; }(baseController_1.BaseController)); exports.WebhooksController = WebhooksController; var templateObject_1; //# sourceMappingURL=webhooksController.js.map