Payments
Learn how to create and manage crypto payments. Understand the payment lifecycle and handle different scenarios.
How Payments Work
When you create a payment, PayHub generates a unique blockchain address for your customer. The customer sends crypto to this address, and our system monitors the blockchain for incoming transactions.
Create a Payment
Use the payments.create() method to create a new payment:
const payment = await client.payments.create({
// Required
amount: '100.00', // Amount in token units
currency: 'USDC', // Token symbol
network: 'polygon', // Blockchain network
// Optional
description: 'Order #12345',
expiresIn: 3600, // Expiry time in seconds (default: 1 hour)
confirmations: 12, // Required confirmations (default: network-specific)
metadata: {
orderId: '12345',
customerEmail: 'customer@example.com',
},
callbackUrl: 'https://your-site.com/webhooks',
redirectUrl: 'https://your-site.com/thank-you',
});Response
{
"id": "pay_abc123xyz",
"status": "pending",
"amount": "100.00",
"currency": "USDC",
"network": "polygon",
"address": "0x1234...abcd",
"checkoutUrl": "https://checkout.payhub.work/pay_abc123xyz",
"expiresAt": "2024-01-15T12:00:00Z",
"createdAt": "2024-01-15T11:00:00Z",
"metadata": {
"orderId": "12345"
}
}Idempotency
Pass an idempotencyKey to prevent duplicate payments. If you retry a request with the same key, you'll get the original payment instead of creating a new one.
Payment Statuses
Payments go through several statuses during their lifecycle:
Payment created, waiting for customer to send funds
Transaction detected on blockchain, waiting for confirmations
Transaction is being confirmed
Required confirmations reached
Payment fully processed and finalized
Payment expired before receiving funds
Received amount is less than expected
Received amount is more than expected
Retrieve Payments
Get a single payment by ID or list payments with filters:
// Get a single payment
const payment = await client.payments.get('pay_abc123xyz');
// List all payments
const payments = await client.payments.list({
limit: 20,
status: 'completed',
from: '2024-01-01',
to: '2024-01-31',
});Supported Currencies
We support major cryptocurrencies and stablecoins:
See Networks for currency availability per blockchain.