Skip to content
OnCharge.io
View as Markdown
Developer docs

Invoices

Bill a customer for work or goods and get paid online. An invoice is drafted, finalized (it gets your store's next number, such as INV-0001, and a payment link), and sent by email with a PDF. Your customer opens OnCharge's hosted invoice page and pays through OnCharge checkout, by card or crypto where your store has that rail on. Overdue invoices are reminded automatically.

You can do everything from the dashboard (Payments → Invoices) or with the API below. Every request is signed like the rest of the API: see Authentication & signing.

How an invoice moves#

StatusWhat it meansWhat you can do
draftBeing written. No number, no payment link.Edit, delete, finalize.
openFinalized: numbered, payable, emailed if you chose. Nothing on it can change.Send again, void (if nothing was paid), mark paid, credit note.
paidPaid in full: through OnCharge, outside OnCharge (marked paid), or by credit notes.Credit note (and refund it to the payment).
voidCancelled before anything was paid. Its number stays used.Nothing.

An open invoice past its due date shows as overdue (display_status). A finalized invoice is never edited: void it and create another, or issue a credit note.

Create and send an invoice#

Shell
POST /api/v1/invoices
Idempotency-Key: invoice-2026-11-ada
JSON
{
  "currency": "USD",
  "customer": {
    "name": "Ada Lovelace",
    "email": "ada@example.com",
    "address": { "line1": "1 Main St", "city": "Austin", "state": "TX", "postal_code": "78701", "country": "US" }
  },
  "lines": [
    { "description": "Consulting, November", "quantity": 10, "unit_amount": 15000, "tax_rate": 8.875 },
    { "description": "Returning-client discount", "quantity": 1, "unit_amount": -5000 }
  ],
  "days_until_due": 14,
  "memo": "Thank you for your business.",
  "reply_to": "billing@yourstore.com",
  "send": true
}
  • Amounts are integers in the currency's minor units (cents; JPY has none). A negative unit_amount is a discount line.
  • tax_rate is a percent with up to three decimals. Each line's tax is rounded half away from zero; the totals are worked out by OnCharge.
  • Without finalize or send the invoice stays a draft. finalize: true numbers it and opens it for payment; send: true also emails it.
  • A repeat with the same Idempotency-Key returns the first invoice with idempotent: true.

The answer is the invoice: its number, hosted_url (the page your customer pays on), total, amount_remaining, due_at and the rest.

Getting paid#

The customer pays on the hosted invoice page. Each payment is an ordinary OnCharge checkout for what is left to pay, so:

  • the usual payment.* webhooks arrive for it, with data.invoice_id set to the invoice's id (the session's order_id and reference are the invoice number);
  • the risk checks, fees and payouts are the same as any payment. Items with requires_shipping are paid out after the carrier confirms delivery to the invoice's shipping_address, as for any order; invoices for services are paid out 7 days after payment.

When the payment is captured, the invoice is marked paid once, and its payment_reference is the payment's OnCharge reference (ocpay_…).

Only one payment for an invoice is open at a time. Pressing Pay again reuses the checkout already opened, or closes it (cancelling its payment) before starting another; while a card payment is approved and being collected, the page says it is being confirmed instead of offering Pay. Voiding, marking paid and credit notes first close any open checkout the same way, and wait while a card payment is being collected (409 payment_in_progress).

If a payment still arrives for more than the invoice needs (it was already settled, voided or credited), the invoice takes only what was left: the rest shows in its history as an extra payment (payment_unapplied), you get a notice, and POST /api/v1/invoices/{id}/refund-extra with the payment's payment_reference refunds it, once.

A store that is not active (for example, suspended) takes no invoice payments: its hosted invoice pages say so, no reminders go out, and new invoices are not created, finalized or sent.

Card payments on stores paid out per delivered order are in USD only. payment_options on an invoice says how the customer can pay it and, when a rail is off, why.

Reminders and receipts#

While an invoice is open and send_reminders is on, OnCharge emails the customer 1, 7 and 14 days after the due date. When it is paid through OnCharge, the customer gets a receipt and you get a notice in the dashboard.

Other actions#

RequestWhat it does
GET /api/v1/invoices?status=overdueList invoices (draft, open, overdue, paid, void, all), newest first. Page with cursor.
GET /api/v1/invoices/{id}The invoice with its lines, history, payments and credit notes.
POST /api/v1/invoices/{id}Edit a draft (lines replaces every line).
DELETE /api/v1/invoices/{id}Delete a draft.
POST /api/v1/invoices/{id}/finalizeNumber it and open it for payment ({ "send": true } also emails it).
POST /api/v1/invoices/{id}/sendEmail it (again) with the PDF attached.
POST /api/v1/invoices/{id}/voidCancel an open invoice nothing was paid on.
POST /api/v1/invoices/{id}/mark-paidRecord it as paid outside OnCharge (bank transfer, cash).
POST /api/v1/invoices/{id}/credit-notesIssue a credit note (below).
POST /api/v1/invoices/{id}/refund-extraRefund an extra payment ({ "payment_reference": "ocpay_…" }), once.
GET /api/v1/invoices/{id}/pdfThe invoice or credit note as a PDF.

Credit notes#

JSON
POST /api/v1/invoices/{id}/credit-notes
{ "amount": 5000, "reason": "order_change", "memo": "Two hours fewer than quoted.", "refund": false }

A credit note is numbered on its own (CN-0001) and emailed to the customer. On an open invoice it lowers what is left to pay; a credit for all of it settles the invoice. On a paid invoice it records a credit, and "refund": true also refunds it to the customer's payment (only for an invoice paid through OnCharge). Send lines instead of amount to itemize it. reason is one of duplicate, fraudulent, order_change, product_unsatisfactory or other.

Errors#

StatuserrorMeaning
409invoice_lockedThe invoice is finalized and cannot be edited or deleted.
409invoice_not_draft, invalid_transitionNot possible in its status (for example voiding a paid invoice).
409invoice_partly_paidPart of it is paid: issue a credit note instead of voiding.
409payment_in_progressA payment for the invoice is under way. Try again in a few minutes.
409store_inactiveThe store is not taking payments.
422invoice_too_largeThe lines would total more than 100000000000 minor units.
422invoice_incompleteFinalizing needs a line, a total above zero and the customer's name; sending needs their email.
422credit_too_largeA credit note is at most what is left to pay (or, once paid, the invoice's total).
404not_foundNo such invoice in your store.

SDK#

TypeScript
import { OnCharge } from '@oncharge/node';

const oncharge = new OnCharge({ apiKey: process.env.ONCHARGE_API_KEY!, apiSecret: process.env.ONCHARGE_API_SECRET! });
const invoice = await oncharge.invoices.create(
  { customer: { name: 'Ada Lovelace', email: 'ada@example.com' }, lines: [{ description: 'Consulting', quantity: 10, unit_amount: 15000 }], send: true },
  { idempotencyKey: 'invoice-2026-11-ada' },
);
console.log(invoice.number, invoice.hosted_url);

See SDKs for every method.