nodejs-cryptomus
Version:
A comprehensive Node.js client for the Cryptomus API
96 lines (83 loc) • 2.17 kB
text/typescript
import { CryptomusClient } from '../client';
import {
CreatePayoutRequest,
PayoutInfo,
PayoutStatusRequest,
PayoutHistoryRequest
} from '../types';
import { filterUndefined, ensureString } from '../utils/helpers';
/**
* Payout service for managing payouts
*/
export class PayoutService {
private readonly client: CryptomusClient;
/**
* Create a new payout service
*
* @param client - Cryptomus API client
*/
constructor(client: CryptomusClient) {
this.client = client;
}
/**
* Create a new payout
*
* @param params - Payout creation parameters
* @returns Created payout information
*/
async createPayout(params: CreatePayoutRequest): Promise<PayoutInfo> {
const payload = {
...params,
amount: ensureString(params.amount)
};
const response = await this.client.requestPayout<PayoutInfo>(
'POST',
'/payout',
payload
);
return response.result;
}
/**
* Get payout information by UUID or order ID
*
* @param params - Parameters containing UUID or order ID
* @returns Payout information
*/
async getPayoutInfo(params: PayoutStatusRequest): Promise<PayoutInfo> {
if (!params.uuid && !params.order_id) {
throw new Error('Either uuid or order_id must be provided');
}
const response = await this.client.requestPayout<PayoutInfo>(
'POST',
'/payout/info',
filterUndefined(params)
);
return response.result;
}
/**
* Get payout history
*
* @param params - History request parameters
* @returns List of payouts
*/
async getPayoutHistory(params: PayoutHistoryRequest = {}): Promise<PayoutInfo[]> {
const response = await this.client.requestPayout<PayoutInfo[]>(
'POST',
'/payout/list',
filterUndefined(params)
);
return response.result;
}
/**
* Get list of available payout services
*
* @returns List of available payout services
*/
async getServices(): Promise<any[]> {
const response = await this.client.requestPayout<any[]>(
'GET',
'/payout/services'
);
return response.result;
}
}