Chat: AI assistant

Orbit assistant

Answers from your invoices, clients and settings

You said:
Write a webhook handler for paid invoices
Orbit assistantThought for 1 second

Here's a route handler that checks the signature, then marks the invoice as paid when Orbit sends an invoice.paid event:

app/api/orbit/webhook/route.ts
import { verifySignature } from './lib/orbit'

export async function POST(req: Request) {
  const body = await req.text()
  const signature = req.headers.get('orbit-signature')
  if (!verifySignature(body, signature, process.env.ORBIT_WEBHOOK_SECRET!)) {
    return new Response('Bad signature', { status: 401 })
  }

  const event = JSON.parse(body)
  if (event.type === 'invoice.paid') {
    await markPaid(event.data.invoice_id, event.data.amount_paid)
  }
  return new Response(null, { status: 204 })
}
  1. Add the endpoint in Settings → Developers → Webhooks and pick the invoice.paid event.
  2. Copy the signing secret into ORBIT_WEBHOOK_SECRET. Never commit it.
  3. Respond quickly with a success status. Orbit retries for 24 hours if your server doesn't answer within 10 seconds.

Want me to add the invoice.payment_failed event too?

Orbit assistant can make mistakes. Check totals before you send an invoice.