/** * Bleumi Pay REST API * A simple and powerful REST API to integrate ERC-20, Ethereum, xDai, Algorand payments and/or payouts into your business or application * * The version of the OpenAPI document: 1.0.0 * Contact: info@bleumi.com * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ import localVarRequest = require('request'); import http = require('http'); /* tslint:disable:no-unused-locals */ import { BadRequest } from '../model/badRequest'; import { Chain } from '../model/chain'; import { CreatePayoutRequest } from '../model/createPayoutRequest'; import { CreatePayoutResponse } from '../model/createPayoutResponse'; import { PaginatedPayoutItems } from '../model/paginatedPayoutItems'; import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../model/models'; import { HttpBasicAuth, HttpBearerAuth, ApiKeyAuth, OAuth } from '../model/models'; import { HttpError, RequestFile } from './apis'; import { RequestValidator } from './requestValidator'; let defaultBasePath = 'https://api.pay.bleumi.com/'; // =============================================== // This file is autogenerated - Please do not edit // =============================================== export enum PayoutsApiApiKeys { ApiKeyAuth, } export class PayoutsApi { protected _basePath = defaultBasePath; protected _defaultHeaders : any = {}; protected _useQuerystring : boolean = false; protected authentications = { 'default': new VoidAuth(), 'ApiKeyAuth': new ApiKeyAuth('header', 'x-api-key'), } protected interceptors: Interceptor[] = []; constructor(basePath?: string); constructor(basePathOrUsername: string, password?: string, basePath?: string) { if (password) { if (basePath) { this.basePath = basePath; } } else { if (basePathOrUsername) { this.basePath = basePathOrUsername } } } set useQuerystring(value: boolean) { this._useQuerystring = value; } set basePath(basePath: string) { this._basePath = basePath; } set defaultHeaders(defaultHeaders: any) { this._defaultHeaders = defaultHeaders; } get defaultHeaders() { return this._defaultHeaders; } get basePath() { return this._basePath; } public setDefaultAuthentication(auth: Authentication) { this.authentications.default = auth; } public setApiKey(key: PayoutsApiApiKeys, value: string) { (this.authentications as any)[PayoutsApiApiKeys[key]].apiKey = value; } public addInterceptor(interceptor: Interceptor) { this.interceptors.push(interceptor); } /** * * @summary Create a payout. * @param createPayoutRequest Request body - used to specify payout creation parameters. * @param chain Ethereum network in which payment is to be created. Please refer documentation for Supported Networks */ public async createPayout (createPayoutRequest: CreatePayoutRequest, chain?: Chain, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: CreatePayoutResponse; }> { const localVarPath = this.basePath + '/v1/payout'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; // verify required parameter 'createPayoutRequest' is not null or undefined if (createPayoutRequest === null || createPayoutRequest === undefined) { throw new Error('Required parameter createPayoutRequest was null or undefined when calling createPayout.'); } if (chain !== undefined) { localVarQueryParameters['chain'] = ObjectSerializer.serialize(chain, "Chain"); } var msg = RequestValidator.ValidateCreatePayout(createPayoutRequest, chain); if (!RequestValidator.isEmpty(msg)) { throw new Error(msg); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: ObjectSerializer.serialize(createPayoutRequest, "CreatePayoutRequest") }; let authenticationPromise = Promise.resolve(); if (this.authentications.ApiKeyAuth.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.ApiKeyAuth.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: CreatePayoutResponse; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { body = ObjectSerializer.deserialize(body, "CreatePayoutResponse"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * * @summary Returns a list of payouts * @param nextToken Cursor to start results from * @param sortBy Sort payments by * @param startAt Get payouts from this timestamp (unix) * @param endAt Get payouts till this timestamp (unix) */ public async listPayouts (nextToken?: string, sortBy?: 'createdAt' | 'updatedAt', startAt?: string, endAt?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: PaginatedPayoutItems; }> { const localVarPath = this.basePath + '/v1/payout'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); const produces = ['application/json']; // give precedence to 'application/json' if (produces.indexOf('application/json') >= 0) { localVarHeaderParams.Accept = 'application/json'; } else { localVarHeaderParams.Accept = produces.join(','); } let localVarFormParams: any = {}; if (nextToken !== undefined) { localVarQueryParameters['nextToken'] = ObjectSerializer.serialize(nextToken, "string"); } if (sortBy !== undefined) { localVarQueryParameters['sortBy'] = ObjectSerializer.serialize(sortBy, "'createdAt' | 'updatedAt'"); } if (startAt !== undefined) { localVarQueryParameters['startAt'] = ObjectSerializer.serialize(startAt, "string"); } if (endAt !== undefined) { localVarQueryParameters['endAt'] = ObjectSerializer.serialize(endAt, "string"); } (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; let localVarRequestOptions: localVarRequest.Options = { method: 'GET', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, }; let authenticationPromise = Promise.resolve(); if (this.authentications.ApiKeyAuth.apiKey) { authenticationPromise = authenticationPromise.then(() => this.authentications.ApiKeyAuth.applyToRequest(localVarRequestOptions)); } authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); let interceptorPromise = authenticationPromise; for (const interceptor of this.interceptors) { interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); } return interceptorPromise.then(() => { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { (localVarRequestOptions).formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise<{ response: http.IncomingMessage; body: PaginatedPayoutItems; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { body = ObjectSerializer.deserialize(body, "PaginatedPayoutItems"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { resolve({ response: response, body: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } }