Capabilities
Business features & tools
Complete documentation for Torque's business features including invoices, payment links, subscriptions, & team management.
Overview
Torque provides comprehensive business tools for managing payments, invoices, subscriptions, & customer relationships. Business accounts have access to advanced features for e-commerce integration & treasury management.
Create, send, & track invoices
Generate shareable payment links
Manage recurring payments & subscriptions
Create & manage product catalogs
Track sales, visitors, & performance metrics
RESTful API for programmatic access
Invoices
Torque's invoice system allows businesses to create professional invoices & send them to customers. Customers can pay invoices directly through a public invoice page.
Invoice Creation
// Convex Mutation: api.invoices.create
const { id, publicId } = await createInvoice({
title: "Invoice #12345",
issuerId: walletAddress, // Business wallet address
counterparty: {
name: "Customer Name",
email: "customer@example.com"
},
lineItems: [
{
id: "item-1",
name: "Product Name",
description: "Product description",
quantity: 2,
unitAmount: 5000, // $50.00 in cents
currency: "USD"
}
],
subtotal: 10000, // $100.00 in cents
total: 10000, // $100.00 in cents
currency: "USD",
fxCurrency: "USDC", // Optional: currency for payment
dueAt: Date.now() + (30 * 24 * 60 * 60 * 1000), // 30 days
notes: "Payment terms: Net 30" // Optional
})
// Response: { id: "invoice_id", publicId: "abc123xyz" }Invoice Schema
interface Invoice {
_id: string // Convex document ID
publicId: string // Public ID for URL
title: string
issuerId: string // Business wallet address
counterparty?: {
name?: string
email?: string
}
lineItems: Array<{
id: string
name: string
description?: string
quantity: number
unitAmount: number // In cents
currency: string
}>
subtotal: number // In cents
total: number // In cents
currency: string // Display currency
fxCurrency?: string // Payment currency (e.g., "USDC")
status: "draft" | "sent" | "viewed" | "paid" | "expired" | "canceled"
dueAt?: number // Due date timestamp
notes?: string
createdAt: number
updatedAt: number
}Invoice Status
draft- Invoice is being createdsent- Invoice has been sent to customerviewed- Customer has viewed the invoicepaid- Invoice has been paidexpired- Invoice has expiredcanceled- Invoice was canceledPublic Invoice Page
URL Format: /invoice/[public_id]
Example: https://app.torque.fi/invoice/abc123xyz
Features: Invoice details display, line items breakdown, payment method selection, due date display, issuer information, payment processing
Invoice Management
// Get invoice by public ID
const invoice = await getInvoiceByPublicId({
publicId: "abc123xyz"
})
// Get invoices by business
const invoices = await getInvoicesByBusiness({
businessId: "business_id"
})
// Update invoice status
await updateInvoiceStatus({
invoiceId: "invoice_id",
status: "paid"
})
// Mark invoice as viewed
await markInvoiceAsViewed({
publicId: "abc123xyz"
})
// Delete invoice
await deleteInvoice({
invoiceId: "invoice_id"
})Payment Links
Payment links allow businesses to generate shareable links for one-time payments. Customers can pay directly through the link without needing to create an account.
Creating Payment Links
// Endpoint: POST /api/checkout/generate-link
const response = await fetch('/api/checkout/generate-link', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
businessId: "business_id",
cart: {
items: [
{
productId: "product_id",
quantity: 1
}
]
},
customerData: {
email: "customer@example.com",
name: "Customer Name"
},
options: {
expiresIn: 24 * 60 * 60 * 1000, // 24 hours
metadata: {
orderId: "order_123"
}
}
})
})
const { checkoutUrl, expiresAt, cartSummary } = await response.json()Payment Link Features
- Shareable URLs: Generate unique checkout URLs
- Expiration: Links can expire after set time
- Multiple Products: Support for cart with multiple items
- Customer Data: Optional customer information
- Metadata: Custom metadata for tracking
Subscriptions
Torque's subscription system allows businesses to manage recurring payments. Subscriptions support multiple billing intervals, trial periods, & payment plans.
Subscription Schema
interface Subscription {
_id: string // Convex document ID
businessId: string // Business ID
productId: string // Product ID
customerId?: string // Contact ID (optional)
customerEmail: string
customerName: string
paymentPlanId: string // Payment plan ID
status: "active" | "cancelled" | "paused" | "expired" | "past_due"
currentPeriodStart: number
currentPeriodEnd: number
nextBillingDate: number
trialStart?: number
trialEnd?: number
totalCycles: number
maxCycles?: number
lastPaymentDate?: number
nextPaymentAmount: number
currency: string
billingHistory: Array<{
cycleNumber: number
amount: number
date: number
status: "paid" | "failed" | "pending"
transactionId?: string
}>
metadata: object
createdAt: number
updatedAt: number
}Subscription Status
active- Subscription is active & billingcancelled- Subscription has been cancelledpaused- Subscription is pausedexpired- Subscription has expiredpast_due- Payment is past dueCreating Subscriptions
// Convex Mutation: api.subscriptions.create
const subscriptionId = await createSubscription({
businessId: "business_id",
productId: "product_id",
customerId: "contact_id", // Optional
customerEmail: "customer@example.com",
customerName: "Customer Name",
paymentPlanId: "plan-monthly",
nextPaymentAmount: 5000, // $50.00 in cents
currency: "USD",
trialDays: 7, // Optional: 7-day trial
maxCycles: 12 // Optional: 12 months
})Payment Plans
interface PaymentPlan {
id: string
name: string
interval: "weekly" | "monthly" | "quarterly" | "yearly"
intervalCount: number
amount: number // In cents
currency: string
maxCycles?: number
trialDays?: number
}
// Example
{
id: "plan-monthly",
name: "Monthly Plan",
interval: "monthly",
intervalCount: 1,
amount: 5000, // $50.00
currency: "USD",
maxCycles: 12, // 12 months
trialDays: 7 // 7-day trial
}Subscription Management
// Get subscription
const subscription = await getSubscription({
id: "subscription_id"
})
// Get subscriptions by business
const subscriptions = await getSubscriptionsByBusiness({
businessId: "business_id",
status: "active" // Optional filter
})
// Get subscriptions by customer
const subscriptions = await getSubscriptionsByCustomer({
customerEmail: "customer@example.com"
})
// Process renewal
await processRenewal({
id: "subscription_id",
transactionId: "tx_hash" // Optional
})
// Cancel subscription
await cancelSubscription({
id: "subscription_id",
effectiveDate: Date.now() + (30 * 24 * 60 * 60 * 1000) // Optional
})
// Pause subscription
await pauseSubscription({
id: "subscription_id",
resumeDate: Date.now() + (30 * 24 * 60 * 60 * 1000) // Optional
})
// Resume subscription
await resumeSubscription({
id: "subscription_id"
})
// Get subscriptions due for renewal
const subscriptions = await getSubscriptionsDueForRenewal({
businessId: "business_id", // Optional
daysAhead: 7 // Default: 7 days
})Billing Intervals
Product Management
Product Schema
interface Product {
_id: string // Convex document ID
businessId: string // Business ID
name: string
description?: string
price: number // In cents
currency: string
isSubscription: boolean
paymentPlans?: PaymentPlan[]
subscriptionContract?: {
address: string
chainId: number
}
image?: string
images?: string[]
requiresShipping: boolean
shippingCost?: number
taxRate?: number
inventory?: number
status: "active" | "inactive" | "draft" | "archived"
sku?: string
category?: string
tags?: string[]
variants?: ProductVariant[]
metadata?: object
createdAt: number
updatedAt: number
}
interface ProductVariant {
id: string
name: string
price?: number // Override base price
sku?: string
inventory?: number
metadata?: object
}Product API
// Get products
// GET /api/products?businessId=ID&status=active
const products = await fetch('/api/products?businessId=business_id&status=active')
.then(res => res.json())
// Get product by ID
// GET /api/products/[productId]
const product = await fetch('/api/products/product_id')
.then(res => res.json())
// Get subscription products
// GET /api/products/subscriptions?businessId=ID
const subscriptions = await fetch('/api/products/subscriptions?businessId=business_id')
.then(res => res.json())Analytics
Businesses can track various metrics including total revenue, transaction count, active products, treasury balance, visitor analytics, & conversion rates.
Analytics API
// GET /api/business/analytics
// Query Parameters: businessId (required), timeframe (optional: '7d', '30d', '90d', '1y')
const analytics = await fetch('/api/business/analytics?businessId=business_id&timeframe=30d')
.then(res => res.json())
// Response:
{
"totalRevenue": 100000,
"transactionCount": 150,
"activeProducts": 25,
"treasuryBalance": 50000,
"visitors": {
"7d": 1000,
"30d": 5000
},
"conversionRate": 0.15
}API Integration
Authentication
All business APIs require Bearer token authentication:
Authorization: Bearer YOUR_API_KEYAPI Key Management
- Generate API Key: Navigate to Business Settings, click "Generate API Key", copy & store securely
- Regenerate API Key: Click "Regenerate API Key", old key is invalidated, new key is generated
Rate Limits
Default: 100 requests per minute per API key. Rate limit information included in response headers.
Webhooks
Webhook Events
order.created- New order createdorder.paid- Order payment completedorder.shipped- Order shippedorder.delivered- Order deliveredorder.cancelled- Order cancelledorder.refunded- Order refundedExamples
Complete Invoice Flow
// 1. Create invoice
const { id, publicId } = await createInvoice({
title: "Invoice #12345",
issuerId: businessWalletAddress,
counterparty: {
name: "Customer Name",
email: "customer@example.com"
},
lineItems: [
{
id: "item-1",
name: "Product Name",
quantity: 1,
unitAmount: 10000, // $100.00
currency: "USD"
}
],
subtotal: 10000,
total: 10000,
currency: "USD",
fxCurrency: "USDC",
dueAt: Date.now() + (30 * 24 * 60 * 60 * 1000)
})
// 2. Generate invoice link
const invoiceLink = `https://app.torque.fi/invoice/${publicId}`
// 3. Send invoice to customer (email, etc.)
// 4. Customer pays (on invoice page)
// 5. Update invoice status
await updateInvoiceStatus({
invoiceId: id,
status: "paid"
})Complete Subscription Flow
// 1. Create subscription
const subscriptionId = await createSubscription({
businessId: "business_id",
productId: "product_id",
customerEmail: "customer@example.com",
customerName: "Customer Name",
paymentPlanId: "plan-monthly",
nextPaymentAmount: 5000, // $50.00
currency: "USD",
trialDays: 7
})
// 2. Process renewal (after trial or billing period)
await processRenewal({
id: subscriptionId,
transactionId: "tx_hash"
})
// 3. Cancel subscription
await cancelSubscription({
id: subscriptionId
})Troubleshooting
Invoice Not Found
Problem: Invoice page shows "Invoice not found"
Solution: Verify public ID is correct, check if invoice was deleted
Payment Link Expired
Problem: Payment link has expired
Solution: Generate new payment link, increase expiration time
Subscription Not Renewing
Problem: Subscription not processing renewals
Solution: Check subscription status, verify payment plan configuration, check billing date