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.

Invoice Management
Invoice Management

Create, send, & track invoices

Payment Links
Payment Links

Generate shareable payment links

Subscriptions
Subscriptions

Manage recurring payments & subscriptions

Product Management
Product Management

Create & manage product catalogs

Analytics
Analytics

Track sales, visitors, & performance metrics

API Integration
API Integration

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

create-invoice.ts
// 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

invoice-schema.ts
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 created
sent- Invoice has been sent to customer
viewed- Customer has viewed the invoice
paid- Invoice has been paid
expired- Invoice has expired
canceled- Invoice was canceled

Public 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

invoice-management.ts
// 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

create-payment-link.ts
// 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

subscription-schema.ts
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 & billing
cancelled- Subscription has been cancelled
paused- Subscription is paused
expired- Subscription has expired
past_due- Payment is past due

Creating Subscriptions

create-subscription.ts
// 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

payment-plan.ts
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

subscription-management.ts
// 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

Weekly:Every 7 days
Monthly:Every 30 days (approximate)
Quarterly:Every 90 days (approximate)
Yearly:Every 365 days (approximate)

Product Management

Product Schema

product-schema.ts
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

product-api.ts
// 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

analytics-api.ts
// 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_KEY

API 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 created
order.paid- Order payment completed
order.shipped- Order shipped
order.delivered- Order delivered
order.cancelled- Order cancelled
order.refunded- Order refunded

Examples

Complete Invoice Flow

invoice-flow.ts
// 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

subscription-flow.ts
// 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

Was this helpful?