/** * New Payment Gateway APIs * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * * The version of the OpenAPI document: 2022-01-01 * Contact: nextgenapi@cashfree.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 from 'request'; import http from 'http'; /* tslint:disable:no-unused-locals */ import { CFError } from '../model/cFError'; import { CFRefund } from '../model/cFRefund'; import { CFRefundRequest } from '../model/cFRefundRequest'; import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../model/models'; import { HttpError, RequestFile } from './apis'; let defaultBasePath = 'https://sandbox.cashfree.com/pg'; // =============================================== // This file is autogenerated - Please do not edit // =============================================== export enum RefundsApiApiKeys { } export class RefundsApi { protected _basePath = defaultBasePath; protected _defaultHeaders : any = {}; protected _useQuerystring : boolean = false; protected authentications = { 'default': new VoidAuth(), } 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: RefundsApiApiKeys, value: string) { (this.authentications as any)[RefundsApiApiKeys[key]].apiKey = value; } public addInterceptor(interceptor: Interceptor) { this.interceptors.push(interceptor); } /** * Use this API to initiate refunds. * @summary Create Refund * @param xClientId * @param xClientSecret * @param orderId * @param xApiVersion * @param xIdempotencyReplayed * @param xIdempotencyKey * @param xRequestId * @param cFRefundRequest */ public async createrefund (xClientId: string, xClientSecret: string, orderId: string, xApiVersion?: string, xIdempotencyReplayed?: boolean, xIdempotencyKey?: string, xRequestId?: string, cFRefundRequest?: CFRefundRequest, requestTimeout?: Number, webProxy?: any,options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ cfHeaders: http.IncomingHttpHeaders; cfRefund: CFRefund; }> { const localVarPath = this.basePath + '/orders/{order_id}/refunds' .replace('{' + 'order_id' + '}', encodeURIComponent(String(orderId))); 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 'xClientId' is not null or undefined if (xClientId === null || xClientId === undefined) { throw new Error('Required parameter xClientId was null or undefined when calling createrefund.'); } // verify required parameter 'xClientSecret' is not null or undefined if (xClientSecret === null || xClientSecret === undefined) { throw new Error('Required parameter xClientSecret was null or undefined when calling createrefund.'); } // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling createrefund.'); } localVarHeaderParams['x-client-id'] = ObjectSerializer.serialize(xClientId, "string"); localVarHeaderParams['x-client-secret'] = ObjectSerializer.serialize(xClientSecret, "string"); localVarHeaderParams['x-api-version'] = ObjectSerializer.serialize(xApiVersion, "string"); localVarHeaderParams['x-idempotency-replayed'] = ObjectSerializer.serialize(xIdempotencyReplayed, "boolean"); localVarHeaderParams['x-idempotency-key'] = ObjectSerializer.serialize(xIdempotencyKey, "string"); localVarHeaderParams['x-request-id'] = ObjectSerializer.serialize(xRequestId, "string"); (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(cFRefundRequest, "CFRefundRequest"), timeout:requestTimeout, ...(webProxy && { proxy : webProxy }) }; let authenticationPromise = Promise.resolve(); 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<{ cfHeaders: http.IncomingHttpHeaders; cfRefund: CFRefund; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "CFRefund"); resolve({ cfHeaders: response.headers, cfRefund: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * Use this API to fetch a specific refund processed on your Cashfree Account. * @summary Get Refund * @param xClientId * @param xClientSecret * @param orderId * @param refundId Refund Id of the refund you want to fetch. * @param xApiVersion * @param xIdempotencyReplayed * @param xIdempotencyKey * @param xRequestId */ public async getRefund (xClientId: string, xClientSecret: string, orderId: string, refundId: string, xApiVersion?: string, xIdempotencyReplayed?: boolean, xIdempotencyKey?: string, xRequestId?: string, requestTimeout?: Number, webProxy?: any, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ cfHeaders: http.IncomingHttpHeaders; cfRefund: CFRefund; }> { const localVarPath = this.basePath + '/orders/{order_id}/refunds/{refund_id}' .replace('{' + 'order_id' + '}', encodeURIComponent(String(orderId))) .replace('{' + 'refund_id' + '}', encodeURIComponent(String(refundId))); 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 'xClientId' is not null or undefined if (xClientId === null || xClientId === undefined) { throw new Error('Required parameter xClientId was null or undefined when calling getRefund.'); } // verify required parameter 'xClientSecret' is not null or undefined if (xClientSecret === null || xClientSecret === undefined) { throw new Error('Required parameter xClientSecret was null or undefined when calling getRefund.'); } // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getRefund.'); } // verify required parameter 'refundId' is not null or undefined if (refundId === null || refundId === undefined) { throw new Error('Required parameter refundId was null or undefined when calling getRefund.'); } localVarHeaderParams['x-client-id'] = ObjectSerializer.serialize(xClientId, "string"); localVarHeaderParams['x-client-secret'] = ObjectSerializer.serialize(xClientSecret, "string"); localVarHeaderParams['x-api-version'] = ObjectSerializer.serialize(xApiVersion, "string"); localVarHeaderParams['x-idempotency-replayed'] = ObjectSerializer.serialize(xIdempotencyReplayed, "boolean"); localVarHeaderParams['x-idempotency-key'] = ObjectSerializer.serialize(xIdempotencyKey, "string"); localVarHeaderParams['x-request-id'] = ObjectSerializer.serialize(xRequestId, "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, timeout:requestTimeout, ...(webProxy && { proxy : webProxy }), }; let authenticationPromise = Promise.resolve(); 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<{ cfHeaders: http.IncomingHttpHeaders; cfRefund: CFRefund; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "CFRefund"); resolve({ cfHeaders: response.headers, cfRefund: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } /** * Use this API to fetch all refunds processed against an order. * @summary Get All Refunds for an Order * @param xClientId * @param xClientSecret * @param orderId * @param xApiVersion */ public async getallrefundsfororder (xClientId: string, xClientSecret: string, orderId: string, xApiVersion?: string, requestTimeout?: Number, webProxy?: any, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ cfHeaders: http.IncomingHttpHeaders; cfRefunds: Array; }> { const localVarPath = this.basePath + '/orders/{order_id}/refunds' .replace('{' + 'order_id' + '}', encodeURIComponent(String(orderId))); 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 'xClientId' is not null or undefined if (xClientId === null || xClientId === undefined) { throw new Error('Required parameter xClientId was null or undefined when calling getallrefundsfororder.'); } // verify required parameter 'xClientSecret' is not null or undefined if (xClientSecret === null || xClientSecret === undefined) { throw new Error('Required parameter xClientSecret was null or undefined when calling getallrefundsfororder.'); } // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getallrefundsfororder.'); } localVarHeaderParams['x-client-id'] = ObjectSerializer.serialize(xClientId, "string"); localVarHeaderParams['x-client-secret'] = ObjectSerializer.serialize(xClientSecret, "string"); localVarHeaderParams['x-api-version'] = ObjectSerializer.serialize(xApiVersion, "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, timeout:requestTimeout, ...(webProxy && { proxy : webProxy }), }; let authenticationPromise = Promise.resolve(); 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<{ cfHeaders: http.IncomingHttpHeaders; cfRefunds: Array; }>((resolve, reject) => { localVarRequest(localVarRequestOptions, (error, response, body) => { if (error) { reject(error); } else { if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { body = ObjectSerializer.deserialize(body, "Array"); resolve({ cfHeaders: response.headers, cfRefunds: body }); } else { reject(new HttpError(response, body, response.statusCode)); } } }); }); }); } }