UNPKG

square-connect

Version:

JavaScript client library for the Square Connect v2 API

213 lines (183 loc) 9.9 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 GetPaymentRefundResponse = require('../model/GetPaymentRefundResponse'); var ListPaymentRefundsResponse = require('../model/ListPaymentRefundsResponse'); var RefundPaymentRequest = require('../model/RefundPaymentRequest'); var RefundPaymentResponse = require('../model/RefundPaymentResponse'); /** * Refunds service. * @module api/RefundsApi */ /** * Constructs a new RefundsApi. * @alias module:api/RefundsApi * @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; /** * GetPaymentRefund * Retrieves a specific refund using the `refund_id`. * @param {String} refundId The unique ID for the desired `PaymentRefund`. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/GetPaymentRefundResponse} and HTTP response */ this.getPaymentRefundWithHttpInfo = function(refundId) { var postBody = null; // verify the required parameter 'refundId' is set if (refundId === undefined || refundId === null) { throw new Error("Missing the required parameter 'refundId' when calling getPaymentRefund"); } var pathParams = { 'refund_id': refundId }; 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 = GetPaymentRefundResponse; return this.apiClient.callApi( '/v2/refunds/{refund_id}', 'GET', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * GetPaymentRefund * Retrieves a specific refund using the `refund_id`. * @param {String} refundId The unique ID for the desired `PaymentRefund`. * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/GetPaymentRefundResponse} */ this.getPaymentRefund = function(refundId) { return this.getPaymentRefundWithHttpInfo(refundId) .then(function(response_and_data) { return response_and_data.data; }); } /** * ListPaymentRefunds * Retrieves a list of refunds for the account making the request. The maximum results per page is 100. * @param {Object} opts Optional parameters * @param {String} opts.beginTime The timestamp for the beginning of the requested reporting period, in RFC 3339 format. Default: The current time minus one year. * @param {String} opts.endTime The timestamp for the end of the requested reporting period, in RFC 3339 format. Default: The current time. * @param {String} opts.sortOrder The order in which results are listed: - `ASC` - Oldest to newest. - `DESC` - Newest to oldest (default). * @param {String} opts.cursor A pagination cursor returned by a previous call to this endpoint. Provide this cursor to retrieve the next set of results for the original query. For more information, see [Pagination](https://developer.squareup.com/docs/basics/api101/pagination). * @param {String} opts.locationId Limit results to the location supplied. By default, results are returned for all locations associated with the seller. * @param {String} opts.status If provided, only refunds with the given status are returned. For a list of refund status values, see `PaymentRefund`. Default: If omitted, refunds are returned regardless of their status. * @param {String} opts.sourceType If provided, only refunds with the given source type are returned. - `CARD` - List refunds only for payments where `CARD` was specified as the payment source. Default: If omitted, refunds are returned regardless of the source type. * @param {Number} opts.limit The maximum number of results to be returned in a single page. It is possible to receive fewer results than the specified limit on a given page. If the supplied value is greater than 100, no more than 100 results are returned. Default: 100 * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/ListPaymentRefundsResponse} and HTTP response */ this.listPaymentRefundsWithHttpInfo = function(opts) { opts = opts || {}; var postBody = null; var pathParams = { }; var queryParams = { 'begin_time': opts['beginTime'], 'end_time': opts['endTime'], 'sort_order': opts['sortOrder'], 'cursor': opts['cursor'], 'location_id': opts['locationId'], 'status': opts['status'], 'source_type': opts['sourceType'], '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 = ListPaymentRefundsResponse; return this.apiClient.callApi( '/v2/refunds', 'GET', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * ListPaymentRefunds * Retrieves a list of refunds for the account making the request. The maximum results per page is 100. * @param {Object} opts Optional parameters * @param {String} opts.beginTime The timestamp for the beginning of the requested reporting period, in RFC 3339 format. Default: The current time minus one year. * @param {String} opts.endTime The timestamp for the end of the requested reporting period, in RFC 3339 format. Default: The current time. * @param {String} opts.sortOrder The order in which results are listed: - `ASC` - Oldest to newest. - `DESC` - Newest to oldest (default). * @param {String} opts.cursor A pagination cursor returned by a previous call to this endpoint. Provide this cursor to retrieve the next set of results for the original query. For more information, see [Pagination](https://developer.squareup.com/docs/basics/api101/pagination). * @param {String} opts.locationId Limit results to the location supplied. By default, results are returned for all locations associated with the seller. * @param {String} opts.status If provided, only refunds with the given status are returned. For a list of refund status values, see `PaymentRefund`. Default: If omitted, refunds are returned regardless of their status. * @param {String} opts.sourceType If provided, only refunds with the given source type are returned. - `CARD` - List refunds only for payments where `CARD` was specified as the payment source. Default: If omitted, refunds are returned regardless of the source type. * @param {Number} opts.limit The maximum number of results to be returned in a single page. It is possible to receive fewer results than the specified limit on a given page. If the supplied value is greater than 100, no more than 100 results are returned. Default: 100 * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/ListPaymentRefundsResponse} */ this.listPaymentRefunds = function(opts) { return this.listPaymentRefundsWithHttpInfo(opts) .then(function(response_and_data) { return response_and_data.data; }); } /** * RefundPayment * Refunds a payment. You can refund the entire payment amount or a portion of it. * @param {module:model/RefundPaymentRequest} 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/RefundPaymentResponse} and HTTP response */ this.refundPaymentWithHttpInfo = 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 refundPayment"); } 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 = RefundPaymentResponse; return this.apiClient.callApi( '/v2/refunds', 'POST', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); } /** * RefundPayment * Refunds a payment. You can refund the entire payment amount or a portion of it. * @param {module:model/RefundPaymentRequest} 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/RefundPaymentResponse} */ this.refundPayment = function(body) { return this.refundPaymentWithHttpInfo(body) .then(function(response_and_data) { return response_and_data.data; }); } };