Cryptofuse Integration Guide
This guide provides practical examples and best practices for integrating with the Cryptofuse API.
Table of Contents
- Authentication
- Payment Flow
- Webhook Integration
- Withdrawal Flow
- Common Integration Patterns
- Testing with Testnet
Authentication
Getting Started
- Obtain your OAuth2 credentials (client_id and client_secret)
- Request an access token
- Use the token in all API requests
# Get access token
curl -X POST https://api.cryptofuse.com/o/token/ \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&scope=read write"
# Response
{
"access_token": "your_access_token",
"token_type": "Bearer",
"expires_in": 36000,
"scope": "read write"
}
# Use token in requests
curl -H "Authorization: Bearer your_access_token" \
https://api.cryptofuse.com/currencies/
Payment Flow
Step 1: Check Available Currencies
# Get currencies with limits
GET /currencies/?full=true&min_max=true&include_usd=true
# Response shows available payment options
{
"currencies": [
{
"currency": "USDTTRC20",
"name": "Tether USD",
"token": "usdt",
"blockchain": "trx",
"min_amount": "10.00000000",
"max_amount": "100000.00000000",
"min_amount_usd": "10.00",
"max_amount_usd": "100000.00"
}
]
}
Step 2: Check Exchange Rates (Optional)
# Convert 100 USD to USDT
GET /rates/?amount=100¤cy_from=USD¤cy_to=USDTTRC20&full=true
# Response with fee details
{
"currency_from": "USD",
"currency_to": "USDTTRC20",
"amount": 100.0,
"estimated_amount": 99.0, # After 1% fee
"rate": 0.99,
"fee_percentage": 1.0,
"fee_amount": 1.0,
"timestamp": "2024-12-27T10:00:00Z"
}
Step 3: Create Payment
POST /payments/
{
"amount": 100.00,
"currency": "USDTTRC20",
"price_currency": "USD",
"callback_url": "https://your-site.com/cryptofuse-webhook",
"order_id": "order_12345",
"order_description": "Premium subscription payment",
"is_fixed_rate": true,
"is_fee_paid_by_user": false,
"expiry_minutes": 30
}
# Response
{
"transaction_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "waiting",
"blockchain_address": "TXYZabc123...",
"amount_usd": "100.00",
"amount_crypto": "100.00000000",
"blockchain": "TRX",
"token": "USDT",
"currency": "USDTTRC20",
"expiry_time": "2024-12-27T10:30:00Z",
"created_at": "2024-12-27T10:00:00Z"
}
Step 4: Display Payment Information
Show to your customer:
- Payment address:
TXYZabc123... - Amount to pay:
100.00000000 USDT (TRC20) - Time remaining: 30 minutes
- QR code with the address
Step 5: Monitor Payment Status
# Check status periodically or wait for webhook
POST /payments/status/
{
"transaction_id": "550e8400-e29b-41d4-a716-446655440000"
}
Webhook Integration
Webhook Flow for Payments
Your system will receive webhooks at different stages of the payment:
1. Payment Created (initial state)
No webhook sent - you already have the response from payment creation.
2. Payment Received - "confirming" status
{
"transaction_id": "550e8400-e29b-41d4-a716-446655440000",
"event": "payment_status_update",
"status": "confirming",
"timestamp": "2024-12-27T10:05:00Z",
"data": {
"transaction_id": "550e8400-e29b-41d4-a456-426614174000",
"status": "confirming",
"amount_usd": "100.00",
"amount_crypto": "100.00000000",
"blockchain": "TRX",
"token": "USDT",
"currency": "USDTTRC20",
"address": "TXYZabc123...",
"transaction_hash": "0xabc123...",
"confirmations": 1,
"payment_history": [
{
"deposit_id": "dep_123",
"amount": "100.00000000",
"transaction_hash": "0xabc123...",
"confirmations": 1,
"timestamp": "2024-12-27T10:05:00Z"
}
],
"total_paid_amount": "100.00000000"
}
}
3. Payment Completed - "completed" status
{
"transaction_id": "550e8400-e29b-41d4-a456-426614174000",
"event": "payment_status_update",
"status": "completed",
"timestamp": "2024-12-27T10:10:00Z",
"data": {
"transaction_id": "550e8400-e29b-41d4-a456-426614174000",
"status": "completed",
"amount_usd": "100.00",
"amount_crypto": "100.00000000",
"payment_type": "full",
"final_usd_value": 99.50, // Actual USD value after conversion
"transaction_hash": "0xabc123...",
"confirmations": 20,
"payment_history": [
{
"deposit_id": "dep_123",
"amount": "100.00000000",
"transaction_hash": "0xabc123...",
"confirmations": 20,
"timestamp": "2024-12-27T10:05:00Z"
}
],
"total_paid_amount": "100.00000000"
}
}