API
The Torque API provides a powerful way to integrate multi-product checkout functionality into your applications.
Quick Start
Authentication
All API requests require authentication using API keys:
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Accept: application/json
Base URL
https://api.torque.fi/v1
Core Endpoints
Checkout
Generate Checkout Link
POST /checkout/generate-link
{
"cart": {
"items": [
{
"id": "product_123",
"name": "Product Name",
"price": 29.99,
"quantity": 2
}
],
"total": 59.98
},
"customer": {
"email": "customer@example.com",
"name": "John Doe"
},
"options": {
"expiresIn": 3600,
"redirectUrl": "https://yourdomain.com/thank-you"
}
}
Get Order
GET /orders/{orderId}
List Orders
GET /orders?status=paid&limit=50
Webhooks
Create Webhook
POST /webhooks
{
"url": "https://yourdomain.com/webhooks/torque",
"events": ["order.created", "order.paid", "order.completed"],
"secret": "your_webhook_secret"
}
Webhook Payload
{
"id": "evt_1234567890",
"type": "order.paid",
"data": {
"order": {
"id": "order_123",
"status": "paid",
"amount": 59.98,
"customer": {
"email": "customer@example.com"
}
}
},
"created": 1640995200
}
Analytics
Get Analytics
GET /analytics?startDate=2024-01-01&endDate=2024-12-31
{
"period": {
"startDate": "2024-01-01",
"endDate": "2024-12-31"
},
"metrics": {
"totalRevenue": 12500.00,
"totalOrders": 250,
"conversionRate": 3.2,
"averageOrderValue": 50.00
},
"dailyData": [
{
"date": "2024-01-01",
"revenue": 150.00,
"orders": 3,
"visitors": 95
}
]
}
Error Handling
Error Response Format
{
"error": {
"code": "INVALID_REQUEST",
"message": "The request is invalid",
"details": {
"field": "cart.items",
"reason": "Items array cannot be empty"
}
}
}
Common Error Codes
INVALID_REQUEST
- Request validation failedUNAUTHORIZED
- Invalid or missing API keyRATE_LIMITED
- Too many requestsORDER_NOT_FOUND
- Order doesn't existINSUFFICIENT_FUNDS
- Not enough balance
Rate Limits
- Standard: 100 requests per minute
- Burst: 200 requests per minute for 5 minutes
- Headers: Rate limit info included in response headers
Webhook Security
Signature Verification
const crypto = require('crypto');
function verifyWebhookSignature(payload, signature, secret) {
const expectedSignature = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return signature === `sha256=${expectedSignature}`;
}
SDK Integration
For easier integration, use our JavaScript SDK:
npm install torque-checkout
import { TorqueCheckout } from 'torque-checkout';
const torque = new TorqueCheckout({
businessId: 'your_business_id',
apiKey: 'your_api_key'
});
Support
Need help with the API? Contact our support team at hello@torque.fi.