@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.
270 lines • 16.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.CustomersController = void 0;
var tslib_1 = require("tslib");
var core_js_1 = require("../core.js");
var basicDateField_js_1 = require("../models/basicDateField.js");
var createCustomerRequest_js_1 = require("../models/createCustomerRequest.js");
var customerResponse_js_1 = require("../models/customerResponse.js");
var sortingDirection_js_1 = require("../models/sortingDirection.js");
var subscriptionResponse_js_1 = require("../models/subscriptionResponse.js");
var updateCustomerRequest_js_1 = require("../models/updateCustomerRequest.js");
var schema_js_1 = require("../schema.js");
var baseController_js_1 = require("./baseController.js");
var core_1 = require("@apimatic/core");
var customerErrorResponseError_js_1 = require("../errors/customerErrorResponseError.js");
var CustomersController = /** @class */ (function (_super) {
tslib_1.__extends(CustomersController, _super);
function CustomersController() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* You may create a new Customer at any time, or you may create a Customer at the same time you create
* a Subscription. The only validation restriction is that you may only create one customer for a given
* reference value.
*
* If provided, the `reference` value must be unique. It represents a unique identifier for the
* customer from your own app, i.e. the customer’s ID. This allows you to retrieve a given customer via
* a piece of shared information. Alternatively, you may choose to leave `reference` blank, and store
* Advanced Billing’s unique ID for the customer, which is in the `id` attribute.
*
* Full documentation on how to locate, create and edit Customers in the Advanced Billing UI can be
* located [here](https://maxio.zendesk.com/hc/en-us/articles/24252190590093-Customer-Details).
*
* ## Required Country Format
*
* Advanced Billing requires that you use the ISO Standard Country codes when formatting country
* attribute of the customer.
*
* Countries should be formatted as 2 characters. For more information, see the following wikipedia
* article on [ISO_3166-1.](http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes)
*
* ## Required State Format
*
* Advanced Billing requires that you use the ISO Standard State codes when formatting state attribute
* of the customer.
*
* + US States (2 characters): [ISO_3166-2](https://en.wikipedia.org/wiki/ISO_3166-2:US)
*
* + States Outside the US (2-3 characters): To find the correct state codes outside of the US, go to
* [ISO_3166-1](http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes) and click on the link in the
* “ISO 3166-2 codes” column next to country you wish to populate.
*
* ## Locale
*
* Advanced Billing allows you to attribute a language/region to your customer to deliver invoices in
* any required language.
* For more: [Customer Locale](https://maxio.zendesk.com/hc/en-us/articles/24286672013709-Customer-
* Locale)
*
* @param body
* @return Response from the API call
*/
CustomersController.prototype.createCustomer = 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', '/customers.json');
mapped = req.prepareArgs({
body: [body, (0, schema_js_1.optional)(createCustomerRequest_js_1.createCustomerRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.throwOn(422, customerErrorResponseError_js_1.CustomerErrorResponseError, 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 request will by default list all customers associated with your Site.
*
* ## Find Customer
*
* Use the search feature with the `q` query parameter to retrieve an array of customers that matches
* the search query.
*
* Common use cases are:
*
* + Search by an email
* + Search by an Advanced Billing ID
* + Search by an organization
* + Search by a reference value from your application
* + Search by a first or last name
*
* To retrieve a single, exact match by reference, use the [lookup endpoint](https://developers.
* chargify.com/docs/api-docs/b710d8fbef104-read-customer-by-reference).
*
* @param direction Direction to sort customers by time of creation
* @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 50. The maximum allowed values is 200; any per_page
* value over 200 will be changed to 200. Use in query `per_page=200`.
* @param dateField The type of filter you would like to apply to your search. Use in query:
* `date_field=created_at`.
* @param startDate The start date (format YYYY-MM-DD) with which to filter the date_field.
* Returns subscriptions with a timestamp at or after midnight (12:00:00
* AM) in your site’s time zone on the date specified.
* @param endDate The end date (format YYYY-MM-DD) with which to filter the date_field.
* Returns subscriptions with a timestamp up to and including 11:59:59PM in
* your site’s time zone on the date specified.
* @param startDatetime The start date and time (format YYYY-MM-DD HH:MM:SS) with which to
* filter the date_field. Returns subscriptions with a timestamp at or
* after exact time provided in query. You can specify timezone in query -
* otherwise your site's time zone will be used. If provided, this
* parameter will be used instead of start_date.
* @param endDatetime The end date and time (format YYYY-MM-DD HH:MM:SS) with which to filter
* the date_field. Returns subscriptions with a timestamp at or before
* exact time provided in query. You can specify timezone in query -
* otherwise your site's time zone will be used. If provided, this
* parameter will be used instead of end_date.
* @param q A search query by which to filter customers (can be an email, an ID, a
* reference, organization)
* @return Response from the API call
*/
CustomersController.prototype.listCustomers = function (_a, requestOptions_1) {
return tslib_1.__awaiter(this, arguments, void 0, function (_b, requestOptions) {
var req, mapped;
var direction = _b.direction, page = _b.page, perPage = _b.perPage, dateField = _b.dateField, startDate = _b.startDate, endDate = _b.endDate, startDatetime = _b.startDatetime, endDatetime = _b.endDatetime, q = _b.q;
return tslib_1.__generator(this, function (_c) {
req = this.createRequest('GET', '/customers.json');
mapped = req.prepareArgs({
direction: [direction, (0, schema_js_1.optional)(sortingDirection_js_1.sortingDirectionSchema)],
page: [page, (0, schema_js_1.optional)((0, schema_js_1.number)())],
perPage: [perPage, (0, schema_js_1.optional)((0, schema_js_1.number)())],
dateField: [dateField, (0, schema_js_1.optional)(basicDateField_js_1.basicDateFieldSchema)],
startDate: [startDate, (0, schema_js_1.optional)((0, schema_js_1.string)())],
endDate: [endDate, (0, schema_js_1.optional)((0, schema_js_1.string)())],
startDatetime: [startDatetime, (0, schema_js_1.optional)((0, schema_js_1.string)())],
endDatetime: [endDatetime, (0, schema_js_1.optional)((0, schema_js_1.string)())],
q: [q, (0, schema_js_1.optional)((0, schema_js_1.string)())],
});
req.query('direction', mapped.direction, core_js_1.commaPrefix);
req.query('page', mapped.page, core_js_1.commaPrefix);
req.query('per_page', mapped.perPage, core_js_1.commaPrefix);
req.query('date_field', mapped.dateField, core_js_1.commaPrefix);
req.query('start_date', mapped.startDate, core_js_1.commaPrefix);
req.query('end_date', mapped.endDate, core_js_1.commaPrefix);
req.query('start_datetime', mapped.startDatetime, core_js_1.commaPrefix);
req.query('end_datetime', mapped.endDatetime, core_js_1.commaPrefix);
req.query('q', mapped.q, core_js_1.commaPrefix);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_js_1.array)(customerResponse_js_1.customerResponseSchema), requestOptions)];
});
});
};
/**
* Retrieves the Customer properties by Advanced Billing-generated Customer ID.
*
* @param id The Advanced Billing id of the customer
* @return Response from the API call
*/
CustomersController.prototype.readCustomer = function (id, 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({ id: [id, (0, schema_js_1.number)()] });
req.appendTemplatePath(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["/customers/", ".json"], ["/customers/", ".json"])), mapped.id);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(customerResponse_js_1.customerResponseSchema, requestOptions)];
});
});
};
/**
* This method allows to update the Customer.
*
* @param id The Advanced Billing id of the customer
* @param body
* @return Response from the API call
*/
CustomersController.prototype.updateCustomer = function (id, 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({
id: [id, (0, schema_js_1.number)()],
body: [body, (0, schema_js_1.optional)(updateCustomerRequest_js_1.updateCustomerRequestSchema)],
});
req.header('Content-Type', 'application/json');
req.json(mapped.body);
req.appendTemplatePath(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["/customers/", ".json"], ["/customers/", ".json"])), mapped.id);
req.throwOn(404, core_1.ApiError, true, "Not Found:'{$response.body}'");
req.throwOn(422, customerErrorResponseError_js_1.CustomerErrorResponseError, 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 allows you to delete the Customer.
*
* @param id The Advanced Billing id of the customer
* @return Response from the API call
*/
CustomersController.prototype.deleteCustomer = function (id, 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({ id: [id, (0, schema_js_1.number)()] });
req.appendTemplatePath(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["/customers/", ".json"], ["/customers/", ".json"])), mapped.id);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.call(requestOptions)];
});
});
};
/**
* Use this method to return the customer object if you have the unique **Reference ID (Your App)**
* value handy. It will return a single match.
*
* @param reference Customer reference
* @return Response from the API call
*/
CustomersController.prototype.readCustomerByReference = function (reference, 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', '/customers/lookup.json');
mapped = req.prepareArgs({ reference: [reference, (0, schema_js_1.string)()] });
req.query('reference', mapped.reference, core_js_1.commaPrefix);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson(customerResponse_js_1.customerResponseSchema, requestOptions)];
});
});
};
/**
* This method lists all subscriptions that belong to a customer.
*
* @param customerId The Chargify id of the customer
* @return Response from the API call
*/
CustomersController.prototype.listCustomerSubscriptions = 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_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["/customers/", "/subscriptions.json"], ["/customers/", "/subscriptions.json"])), mapped.customerId);
req.authenticate([{ basicAuth: true }]);
return [2 /*return*/, req.callAsJson((0, schema_js_1.array)(subscriptionResponse_js_1.subscriptionResponseSchema), requestOptions)];
});
});
};
return CustomersController;
}(baseController_js_1.BaseController));
exports.CustomersController = CustomersController;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
//# sourceMappingURL=customersController.js.map