AApt Commerce
Sign inGet started
Show for

Invoices & Billing

Create, list, and track invoices in Worker D1. Send emails the payer via Resend when keyed; SENT only after mail succeeds.

Creating an Invoice

const invoice = await apt.invoices.create({
  customer_id: 'cus_abc123',
  items: [
    { description: 'Web Development', unit_price: 150000, quantity: 1 },
  ],
  due_date: '2026-04-15',
});
// Amounts are cents. customer_id must exist for your merchant.

Sending an Invoice

// Emails the snapshotted payer. Fails if RESEND_API_KEY is unset. SENT only after success.
await apt.invoices.send(invoice.id);

Invoice Lifecycle

draftInvoice created but not yet sent.
sentSENT means Resend accepted the email. Unkeyed Workers fail send and stay DRAFT.
paidPayment received in full.
overduePast due date without payment.
cancelledInvoice cancelled. No payment expected.

Mark paid

POST /v1/invoices/:id/mark-paid sets status PAID. It does not authorize, capture, or write a sandbox transaction. Collect money with the Transactions flow. Auto-collection and hosted payment pages are out of this slice.