takefy-cryptomus
Version:
TypeScript SDK for the Cryptomus payment system API
118 lines (117 loc) • 4.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PayoutsService = void 0;
const base_1 = require("./base");
/**
* Service class for handling payout-related operations in the Cryptomus API.
* Provides methods for creating payouts, transferring funds, and managing payout history.
*/
class PayoutsService extends base_1.BaseService {
/**
* Creates a new payout to a specified wallet address.
*
* @param {CreatePayoutRequest} data - Payout creation parameters including amount, currency, and destination.
* @returns {Promise<CreatePayoutResponse>} A promise that resolves with the created payout details.
* @throws {Error} If the payout creation fails or returns an error response.
*
* @example
* ```typescript
* const payout = await payouts.create({
* amount: "50",
* currency: "USDT",
* network: "TRX",
* address: "wallet-address",
* order_id: "payout123"
* });
* ```
*/
async create(data) {
return this.request("/payout", "POST", data, false);
}
/**
* Retrieves information about a specific payout.
*
* @param {GetPayoutInfoRequest} data - Parameters to identify the payout (uuid or order_id).
* @returns {Promise<GetPayoutInfoResponse>} A promise that resolves with the payout information.
* @throws {Error} If the request fails or returns an error response.
*
* @example
* ```typescript
* const info = await payouts.getInfo({
* uuid: "payout-uuid"
* });
* ```
*/
async getInfo(data) {
return this.request("/payout/info", "POST", data, false);
}
/**
* Retrieves a list of available payout services and their details.
*
* @returns {Promise<ListServicesResponse>} A promise that resolves with the list of payout services.
* @throws {Error} If the request fails or returns an error response.
*
* @example
* ```typescript
* const services = await payouts.listServices();
* ```
*/
async listServices() {
return this.request("/payout/services", "POST", undefined, false);
}
/**
* Retrieves payout history based on specified date range and filters.
*
* @param {GetPayoutHistoryRequest} data - Parameters for filtering payout history.
* @returns {Promise<GetPayoutHistoryResponse>} A promise that resolves with the payout history.
* @throws {Error} If the request fails or returns an error response.
*
* @example
* ```typescript
* const history = await payouts.getHistory({
* date_from: "2025-01-01",
* date_to: "2025-02-01"
* });
* ```
*/
async getHistory(data) {
return this.request("/payout/list", "POST", data, false);
}
async verifyWebhookSignature(params) {
const { ipAddress, request } = params;
if (ipAddress &&
typeof ipAddress === "string" &&
ipAddress !== "91.227.144.54") {
return false;
}
if (request &&
request.sign &&
typeof request.sign === "string" &&
this.generateSign(request, false, true) !== request.sign) {
return false;
}
return true;
}
/**
* Transfers funds to a personal wallet.
*
* @param {TransferToPersonalWalletRequest} data - Parameters for the transfer operation.
* @returns {Promise<TransferToPersonalWalletResponse>} A promise that resolves with the transfer details.
* @throws {Error} If the transfer fails or returns an error response.
*
* @example
* ```typescript
* const transfer = await payouts.transferToPersonalWallet({
* amount: "10",
* currency: "USDT"
* });
* ```
*/
async transferToPersonalWallet(data) {
return this.request("/payout/wallet", "POST", data, false);
}
async transferToBusinessWallet(params) {
return this.request("/transfer/to-business", "POST", params, false);
}
}
exports.PayoutsService = PayoutsService;