Cryptomus API
A comprehensive Node.js client for the Cryptomus API. This package provides full support for payment processing, payouts, webhooks, and more.
Installation
npm install nodejs-cryptomus
Features
- Complete TypeScript support
- Support for both CommonJS and ESM
- Full implementation of all Cryptomus API endpoints
- Payment operations (invoices, static wallets, QR codes, etc.)
- Payout operations
- Webhook handling and validation
- Balance management
- Currency operations and limits
Quick Start
Initialize the client
import { Cryptomus } from 'nodejs-cryptomus';
const cryptomus = new Cryptomus({
merchantId: 'your-merchant-id',
paymentKey: 'your-payment-api-key',
payoutKey: 'your-payout-api-key'
});
Create a payment invoice
const invoice = await cryptomus.payment.createInvoice({
amount: '100',
currency: 'USDT',
order_id: 'order-123',
url_return: 'https://your-site.com/success',
url_callback: 'https://your-site.com/webhook'
});
console.log('Payment URL:', invoice.url);
Create a static wallet
const wallet = await cryptomus.payment.createStaticWallet({
currency: 'BTC',
order_id: 'wallet-123',
url_callback: 'https://your-site.com/webhook'
});
console.log('Wallet address:', wallet.wallet);
Handle webhooks
import express from 'express';
const app = express();
app.post('/webhook', express.json(), (req, res) => {
try {
const signature = req.headers['signature'] as string;
const webhook = cryptomus.paymentWebhook.parsePaymentWebhook(
JSON.stringify(req.body),
signature
);
if (webhook.status === 'paid') {
console.log(`Payment ${webhook.uuid} for order ${webhook.order_id} was successful`);
}
res.status(200).send('OK');
} catch (error) {
console.error('Webhook error:', error);
res.status(400).send('Invalid webhook');
}
});
Create a payout
const payout = await cryptomus.payout.createPayout({
amount: '50',
currency: 'USDT',
network: 'TRX',
address: 'recipient-address',
order_id: 'payout-123',
url_callback: 'https://your-site.com/payout-webhook'
});
console.log('Payout created:', payout.uuid);
Check account balance
const balance = await cryptomus.balance.getMerchantBalance();
console.log('Available balances:', balance);
Get available currencies
const currencies = await cryptomus.currency.getPaymentCurrencies();
console.log('Available payment currencies:', currencies);
Get payment limits
const limits = await cryptomus.currency.getPaymentLimits('BTC');
console.log('BTC payment limits:', limits);
Error Handling
The library throws CryptomusError for API-related errors:
try {
const result = await cryptomus.payment.createInvoice({
});
} catch (error) {
if (error instanceof CryptomusError) {
console.error('API Error:', error.message);
console.error('Status code:', error.statusCode);
console.error('Error details:', error.errors);
} else {
console.error('Unexpected error:', error);
}
}
API Documentation
Payment Operations
payment.createInvoice(params)
Creates a new payment invoice for cryptocurrency payments.
{
amount: string;
currency: string;
order_id: string;
url_return?: string;
url_callback?: string;
is_payment_multiple?: boolean;
lifetime?: number;
to_currency?: string;
subtract_fee_from_amount?: boolean;
custom_payload?: string;
}
{
url: string;
uuid: string;
currency: string;
status: string;
}
payment.getPaymentInfo(params)
Retrieves information about a specific payment.
{
uuid?: string;
order_id?: string;
}
{
uuid: string;
order_id: string;
amount: string;
payment_amount: string;
currency: string;
status: string;
}
payment.getPaymentHistory(params)
Retrieves payment history with optional filtering.
{
date_from?: string;
date_to?: string;
limit?: number;
offset?: number;
order?: 'asc' | 'desc';
status?: string;
}
{
items: Array<{
uuid: string;
order_id: string;
amount: string;
currency: string;
status: string;
}>;
count: number;
}
payment.createStaticWallet(params)
Creates a static wallet for accepting cryptocurrency payments.
{
currency: string;
order_id: string;
network?: string;
url_callback?: string;
custom_payload?: string;
}
{
wallet_uuid: string;
wallet: string;
currency: string;
network: string;
}
payment.blockWallet(params)
Blocks a previously created static wallet.
{
uuid?: string;
order_id?: string;
}
{
result: boolean;
}
payment.generateQrCode(params)
Generates a QR code for a payment or wallet address.
{
uuid: string;
type: 'wallet' | 'invoice';
}
{
qr_code: string;
}
payment.refund(params)
Creates a refund for a completed payment.
{
uuid: string;
address: string;
amount?: string;
}
{
result: boolean;
}
payment.testWebhook(params)
Tests your webhook endpoint by sending a sample webhook.
{
order_id: string;
url_callback: string;
}
{
result: boolean;
}
payment.resendWebhook(params)
Resends a webhook for a specific payment.
{
uuid?: string;
order_id?: string;
}
{
result: boolean;
}
payment.getServices()
Retrieves a list of available payment services and currencies.
{
services: Array<{
currency: string;
network: string;
is_available: boolean;
min_amount: string;
max_amount: string;
}>;
}
Payout Operations
payout.createPayout(params)
Creates a new cryptocurrency payout to a specified address.
{
amount: string;
currency: string;
network: string;
address: string;
order_id: string;
url_callback?: string;
is_subtract?: boolean;
additional_data?: string;
}
{
uuid: string;
order_id: string;
amount: string;
currency: string;
status: string;
}
payout.getPayoutInfo(params)
Retrieves information about a specific payout.
{
uuid?: string;
order_id?: string;
}
{
uuid: string;
order_id: string;
amount: string;
currency: string;
status: string;
}
payout.getPayoutHistory(params)
Retrieves payout history with optional filtering.
{
date_from?: string;
date_to?: string;
limit?: number;
offset?: number;
order?: 'asc' | 'desc';
status?: string;
}
{
items: Array<{
uuid: string;
order_id: string;
amount: string;
currency: string;
status: string;
}>;
count: number;
}
payout.getServices()
Retrieves a list of available payout services and currencies.
{
services: Array<{
currency: string;
network: string;
is_available: boolean;
commission: string;
min_amount: string;
max_amount: string;
}>;
}
Webhook Handling
paymentWebhook.parseWebhook(payload, signature)
Generic method to parse and validate any webhook.
payload: string;
signature: string;
paymentWebhook.parsePaymentWebhook(payload, signature)
Parses and validates a payment webhook.
payload: string;
signature: string;
{
status: string;
uuid: string;
order_id: string;
amount: string;
payment_amount: string;
currency: string;
}
payoutWebhook.parsePayoutWebhook(payload, signature)
Parses and validates a payout webhook.
payload: string;
signature: string;
{
status: string;
uuid: string;
order_id: string;
amount: string;
currency: string;
}
Balance Operations
balance.getMerchantBalance()
Retrieves the current merchant account balance.
{
balances: Array<{
currency: string;
balance: string;
}>;
}
balance.getBusinessBalance()
Retrieves the business account balance.
{
balances: Array<{
currency: string;
balance: string;
}>;
}
Currency Operations
currency.getPaymentCurrencies()
Retrieves a list of available payment currencies.
{
currencies: Array<{
currency: string;
network: string;
is_available: boolean;
}>;
}
currency.getPayoutCurrencies()
Retrieves a list of available payout currencies.
{
currencies: Array<{
currency: string;
network: string;
is_available: boolean;
}>;
}
currency.getPaymentLimits(currency)
Retrieves payment limits for a specific currency.
currency: string;
{
currency: string;
min_amount: string;
max_amount: string;
}
License
MIT