UNPKG

square-connect

Version:

JavaScript client library for the Square Connect v2 API

379 lines (320 loc) 17 kB
/** * Square Connect API * Client library for accessing the Square Connect APIs * * OpenAPI spec version: 2.0 * Contact: developers@squareup.com * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * * Swagger Codegen version: 2.3.0-SNAPSHOT * */ var ApiClient = require('../ApiClient'); var CancelSubscriptionResponse = require('../model/CancelSubscriptionResponse'); var CreateSubscriptionRequest = require('../model/CreateSubscriptionRequest'); var CreateSubscriptionResponse = require('../model/CreateSubscriptionResponse'); var ListSubscriptionEventsResponse = require('../model/ListSubscriptionEventsResponse'); var RetrieveSubscriptionResponse = require('../model/RetrieveSubscriptionResponse'); var SearchSubscriptionsRequest = require('../model/SearchSubscriptionsRequest'); var SearchSubscriptionsResponse = require('../model/SearchSubscriptionsResponse'); var UpdateSubscriptionRequest = require('../model/UpdateSubscriptionRequest'); var UpdateSubscriptionResponse = require('../model/UpdateSubscriptionResponse'); /** * Subscriptions service. * @module api/SubscriptionsApi */ /** * Constructs a new SubscriptionsApi. * @alias module:api/SubscriptionsApi * @class * @param {module:ApiClient} apiClient Optional API client implementation to use, * default to {@link module:ApiClient#instance} if unspecified. */ module.exports = function(apiClient) { this.apiClient = apiClient || ApiClient.instance; /** * CancelSubscription * Note: This endpoint is in beta. * Sets the `canceled_date` field to the end of the active billing period. After this date, the status changes from ACTIVE to CANCELED. * @param {String} subscriptionId The ID of the subscription to cancel. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/CancelSubscriptionResponse} and HTTP response */ this.cancelSubscriptionWithHttpInfo = function(subscriptionId) { var postBody = null; // verify the required parameter 'subscriptionId' is set if (subscriptionId === undefined || subscriptionId === null) { throw new Error("Missing the required parameter 'subscriptionId' when calling cancelSubscription"); } var pathParams = { 'subscription_id': subscriptionId }; var queryParams = { }; var headerParams = { }; headerParams['Square-Version'] = '2020-12-16'; var formParams = { }; var authNames = ['oauth2']; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = CancelSubscriptionResponse; return this.apiClient.callApi( '/v2/subscriptions/{subscription_id}/cancel', 'POST', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * CancelSubscription * Sets the `canceled_date` field to the end of the active billing period. After this date, the status changes from ACTIVE to CANCELED. * @param {String} subscriptionId The ID of the subscription to cancel. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/CancelSubscriptionResponse} */ this.cancelSubscription = function(subscriptionId) { return this.cancelSubscriptionWithHttpInfo(subscriptionId) .then(function(response_and_data) { return response_and_data.data; }); } /** * CreateSubscription * Note: This endpoint is in beta. * Creates a subscription for a customer to a subscription plan. If you provide a card on file in the request, Square charges the card for the subscription. Otherwise, Square bills an invoice to the customer's email address. The subscription starts immediately, unless the request includes the optional `start_date`. Each individual subscription is associated with a particular location. * @param {module:model/CreateSubscriptionRequest} body An object containing the fields to POST for the request. See the corresponding object definition for field details. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/CreateSubscriptionResponse} and HTTP response */ this.createSubscriptionWithHttpInfo = function(body) { var postBody = body; // verify the required parameter 'body' is set if (body === undefined || body === null) { throw new Error("Missing the required parameter 'body' when calling createSubscription"); } var pathParams = { }; var queryParams = { }; var headerParams = { }; headerParams['Square-Version'] = '2020-12-16'; var formParams = { }; var authNames = ['oauth2']; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = CreateSubscriptionResponse; return this.apiClient.callApi( '/v2/subscriptions', 'POST', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * CreateSubscription * Creates a subscription for a customer to a subscription plan. If you provide a card on file in the request, Square charges the card for the subscription. Otherwise, Square bills an invoice to the customer's email address. The subscription starts immediately, unless the request includes the optional `start_date`. Each individual subscription is associated with a particular location. * @param {module:model/CreateSubscriptionRequest} body An object containing the fields to POST for the request. See the corresponding object definition for field details. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/CreateSubscriptionResponse} */ this.createSubscription = function(body) { return this.createSubscriptionWithHttpInfo(body) .then(function(response_and_data) { return response_and_data.data; }); } /** * ListSubscriptionEvents * Note: This endpoint is in beta. * Lists all events for a specific subscription. In the current implementation, only `START_SUBSCRIPTION` and `STOP_SUBSCRIPTION` (when the subscription was canceled) events are returned. * @param {String} subscriptionId The ID of the subscription to retrieve the events for. * @param {Object} opts Optional parameters * @param {String} opts.cursor A pagination cursor returned by a previous call to this endpoint. Provide this to retrieve the next set of results for the original query. For more information, see [Pagination](https://developer.squareup.com/docs/docs/working-with-apis/pagination). * @param {Number} opts.limit The upper limit on the number of subscription events to return in the response. Default: `200` * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/ListSubscriptionEventsResponse} and HTTP response */ this.listSubscriptionEventsWithHttpInfo = function(subscriptionId, opts) { opts = opts || {}; var postBody = null; // verify the required parameter 'subscriptionId' is set if (subscriptionId === undefined || subscriptionId === null) { throw new Error("Missing the required parameter 'subscriptionId' when calling listSubscriptionEvents"); } var pathParams = { 'subscription_id': subscriptionId }; var queryParams = { 'cursor': opts['cursor'], 'limit': opts['limit'] }; var headerParams = { }; headerParams['Square-Version'] = '2020-12-16'; var formParams = { }; var authNames = ['oauth2']; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = ListSubscriptionEventsResponse; return this.apiClient.callApi( '/v2/subscriptions/{subscription_id}/events', 'GET', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * ListSubscriptionEvents * Lists all events for a specific subscription. In the current implementation, only `START_SUBSCRIPTION` and `STOP_SUBSCRIPTION` (when the subscription was canceled) events are returned. * @param {String} subscriptionId The ID of the subscription to retrieve the events for. * @param {Object} opts Optional parameters * @param {String} opts.cursor A pagination cursor returned by a previous call to this endpoint. Provide this to retrieve the next set of results for the original query. For more information, see [Pagination](https://developer.squareup.com/docs/docs/working-with-apis/pagination). * @param {Number} opts.limit The upper limit on the number of subscription events to return in the response. Default: `200` * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/ListSubscriptionEventsResponse} */ this.listSubscriptionEvents = function(subscriptionId, opts) { return this.listSubscriptionEventsWithHttpInfo(subscriptionId, opts) .then(function(response_and_data) { return response_and_data.data; }); } /** * RetrieveSubscription * Note: This endpoint is in beta. * Retrieves a subscription. * @param {String} subscriptionId The ID of the subscription to retrieve. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/RetrieveSubscriptionResponse} and HTTP response */ this.retrieveSubscriptionWithHttpInfo = function(subscriptionId) { var postBody = null; // verify the required parameter 'subscriptionId' is set if (subscriptionId === undefined || subscriptionId === null) { throw new Error("Missing the required parameter 'subscriptionId' when calling retrieveSubscription"); } var pathParams = { 'subscription_id': subscriptionId }; var queryParams = { }; var headerParams = { }; headerParams['Square-Version'] = '2020-12-16'; var formParams = { }; var authNames = ['oauth2']; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = RetrieveSubscriptionResponse; return this.apiClient.callApi( '/v2/subscriptions/{subscription_id}', 'GET', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * RetrieveSubscription * Retrieves a subscription. * @param {String} subscriptionId The ID of the subscription to retrieve. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/RetrieveSubscriptionResponse} */ this.retrieveSubscription = function(subscriptionId) { return this.retrieveSubscriptionWithHttpInfo(subscriptionId) .then(function(response_and_data) { return response_and_data.data; }); } /** * SearchSubscriptions * Note: This endpoint is in beta. * Searches for subscriptions. Results are ordered chronologically by subscription creation date. If the request specifies more than one location ID, the endpoint orders the result by location ID, and then by creation date within each location. If no locations are given in the query, all locations are searched. You can also optionally specify `customer_ids` to search by customer. If left unset, all customers associated with the specified locations are returned. If the request specifies customer IDs, the endpoint orders results first by location, within location by customer ID, and within customer by subscription creation date. For more information, see [Retrieve subscriptions](/docs/subscriptions-api/overview#retrieve-subscriptions). * @param {module:model/SearchSubscriptionsRequest} body An object containing the fields to POST for the request. See the corresponding object definition for field details. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/SearchSubscriptionsResponse} and HTTP response */ this.searchSubscriptionsWithHttpInfo = function(body) { var postBody = body; // verify the required parameter 'body' is set if (body === undefined || body === null) { throw new Error("Missing the required parameter 'body' when calling searchSubscriptions"); } var pathParams = { }; var queryParams = { }; var headerParams = { }; headerParams['Square-Version'] = '2020-12-16'; var formParams = { }; var authNames = ['oauth2']; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = SearchSubscriptionsResponse; return this.apiClient.callApi( '/v2/subscriptions/search', 'POST', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * SearchSubscriptions * Searches for subscriptions. Results are ordered chronologically by subscription creation date. If the request specifies more than one location ID, the endpoint orders the result by location ID, and then by creation date within each location. If no locations are given in the query, all locations are searched. You can also optionally specify `customer_ids` to search by customer. If left unset, all customers associated with the specified locations are returned. If the request specifies customer IDs, the endpoint orders results first by location, within location by customer ID, and within customer by subscription creation date. For more information, see [Retrieve subscriptions](/docs/subscriptions-api/overview#retrieve-subscriptions). * @param {module:model/SearchSubscriptionsRequest} body An object containing the fields to POST for the request. See the corresponding object definition for field details. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/SearchSubscriptionsResponse} */ this.searchSubscriptions = function(body) { return this.searchSubscriptionsWithHttpInfo(body) .then(function(response_and_data) { return response_and_data.data; }); } /** * UpdateSubscription * Note: This endpoint is in beta. * Updates a subscription. You can set, modify, and clear the `subscription` field values. * @param {String} subscriptionId The ID for the subscription to update. * @param {module:model/UpdateSubscriptionRequest} body An object containing the fields to POST for the request. See the corresponding object definition for field details. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/UpdateSubscriptionResponse} and HTTP response */ this.updateSubscriptionWithHttpInfo = function(subscriptionId, body) { var postBody = body; // verify the required parameter 'subscriptionId' is set if (subscriptionId === undefined || subscriptionId === null) { throw new Error("Missing the required parameter 'subscriptionId' when calling updateSubscription"); } // verify the required parameter 'body' is set if (body === undefined || body === null) { throw new Error("Missing the required parameter 'body' when calling updateSubscription"); } var pathParams = { 'subscription_id': subscriptionId }; var queryParams = { }; var headerParams = { }; headerParams['Square-Version'] = '2020-12-16'; var formParams = { }; var authNames = ['oauth2']; var contentTypes = ['application/json']; var accepts = ['application/json']; var returnType = UpdateSubscriptionResponse; return this.apiClient.callApi( '/v2/subscriptions/{subscription_id}', 'PUT', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * UpdateSubscription * Updates a subscription. You can set, modify, and clear the `subscription` field values. * @param {String} subscriptionId The ID for the subscription to update. * @param {module:model/UpdateSubscriptionRequest} body An object containing the fields to POST for the request. See the corresponding object definition for field details. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/UpdateSubscriptionResponse} */ this.updateSubscription = function(subscriptionId, body) { return this.updateSubscriptionWithHttpInfo(subscriptionId, body) .then(function(response_and_data) { return response_and_data.data; }); } };