API Integration
Full control with our REST API. Best for custom checkout experiences.
Learn how to accept crypto payments in your application. This guide covers everything from creating your first payment to handling webhooks.
API Integration
Hosted Checkout
Full control over the payment experience.
curl -X POST https://api.sanpay.io/v1/payments \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"amount": "49.99",
"currency": "USD",
"cryptoCurrency": "BTC",
"description": "Pro Plan Subscription",
"orderId": "order_12345",
"redirectUrl": "https://your-app.com/thank-you",
"webhookUrl": "https://your-app.com/webhooks/sanpay"
}' const response = await fetch('https://api.sanpay.io/v1/payments', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
amount: '49.99',
currency: 'USD',
cryptoCurrency: 'BTC',
description: 'Pro Plan Subscription',
orderId: 'order_12345',
redirectUrl: 'https://your-app.com/thank-you',
webhookUrl: 'https://your-app.com/webhooks/sanpay',
}),
});
const payment = await response.json(); {
"id": "pay_abc123",
"status": "pending",
"amount": "49.99",
"currency": "USD",
"cryptoAmount": "0.00125000",
"cryptoCurrency": "BTC",
"address": "bc1qxy2kgdygjrsqvzq3rj...",
"qrCode": "data:image/png;base64,...",
"expiresAt": "2024-01-15T11:30:00Z"
} Show the payment address and QR code to your customer:
<div class="payment-container">
<h2>Pay with Bitcoin</h2>
<img src="${payment.qrCode}" alt="Payment QR Code" />
<p>Send exactly <strong>${payment.cryptoAmount} BTC</strong></p>
<code>${payment.address}</code>
<p>Payment expires in 30 minutes</p>
</div> Process the webhook when payment is confirmed:
app.post('/webhooks/sanpay', async (req, res) => {
const { type, data } = req.body;
if (type === 'payment.confirmed') {
const { orderId, status } = data;
// Update order status in your database
await db.orders.update({
where: { id: orderId },
data: { status: 'paid' }
});
// Send confirmation email
await sendOrderConfirmation(orderId);
}
res.status(200).send('OK');
}); After payment, we redirect the customer to your redirectUrl with payment status:
https://your-app.com/thank-you?payment_id=pay_abc123&status=confirmed The fastest way to start accepting payments. We handle the entire checkout UI.
curl -X POST https://api.sanpay.io/v1/checkout/sessions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"amount": "49.99",
"currency": "USD",
"description": "Pro Plan Subscription",
"orderId": "order_12345",
"successUrl": "https://your-app.com/thank-you",
"cancelUrl": "https://your-app.com/checkout"
}' {
"id": "cs_xyz789",
"url": "https://checkout.sanpay.io/cs_xyz789"
} Redirect your customer to the url:
window.location.href = session.url; Our hosted checkout handles:
After payment (or cancellation), we redirect to your success or cancel URL.
Enable test mode by using your test API key (starts with sk_test_):
curl -X POST https://api.sanpay.io/v1/payments \
-H "Authorization: Bearer sk_test_YOUR_TEST_KEY" \
... Test payments are processed on Bitcoin testnet and Ethereum Sepolia.