Skip to content

Step-by-step guides

Invoices

Create an invoice with a hosted payment page, share the link, track payments and cancel, step by step.

What the invoice API does

An invoice is a request for a fixed amount from a named customer, with a due date and a hosted payment page. The customer pays on the page at payment_link, or by dialling payment_code on USSD, and the money settles into your wallet. The invoices you create through the API are the same invoices you see in the Moolre dashboard.

The API does not send the email, PDF or SMS that the dashboard sends when you create an invoice. You give the customer the payment_link yourself, by whatever channel you use: your own email, a WhatsApp or SMS message, or a screen in your app.

StepEndpointResult
CreateCreate invoiceinvoiceid, payment_link, payment_code
ShareYour own channel (SMS, WhatsApp, email)The customer receives the link
TrackInvoice status or List invoicesstatus: pending, partially_paid, overdue, paid, cancelled
CancelCancel invoiceAn unpaid invoice stops accepting payment

Before you start

  • The private key (a public key is refused), and a wallet that has a collection service (INV09 otherwise).
  • A unique reference per invoice, saved with your own record. It makes creation safe to retry.
  • A customer name and phone number (9 to 15 digits).
  • A due date: today or later, within 2 years.

Step by step: create and share an invoice

  1. Decide the amount. Send either a single amount, or 1 to 50 items of description, quantity and unit amount. Add tax as a percentage if needed: the total is the subtotal times (1 + tax / 100), rounded to the cent.
  2. Send Create invoice with accountnumber, currency, invoice_name, customer, the amount or items, due_date and your reference. Add an Idempotency-Key equal to the reference.
  3. Read the reply. INV01 is a new invoice; INV02 (with data.replayed true) means the same reference and body already created it. Store invoiceid and payment_link.
  4. Send the customer the payment_link (and the payment_code for USSD) in your own message.
  5. Wait for the customer to pay, then check the invoice with Invoice status (by invoiceid or reference).

curl https://api.moolre.com/open/invoice/create \  -H "Content-Type: application/json" \  -H "X-API-USER: $MOOLRE_USER" \  -H "X-API-KEY: $MOOLRE_KEY" \  -H "Idempotency-Key: INV-1001" \  -d '{    "accountnumber": "1000000000001",    "currency": "GHS",    "invoice_name": "Term 1 fees",    "customer": {      "name": "Ama Mensah",      "phone": "0240000001"    },    "items": [      {        "description": "Tuition",        "quantity": 1,        "amount": "450.00"      }    ],    "due_date": "2026-12-31",    "reference": "INV-1001",    "narration": "Term 1 school fees"  }'

Invoice states

statusMeaningWhat to do
pendingCreated, unpaidWait; remind the customer before the due date
partially_paidA payment smaller than the total has arrivedCheck amount_paid against total and ask for the rest
overdueThe due date has passed and the invoice is unpaid or part paid. It can still be paidChase the customer, or cancel it
paidFully paidMark the bill settled and issue your receipt
cancelledCancelled: the hosted link no longer worksCreate a new invoice with a new reference if needed

No webhook for invoices

Invoices send no webhook or callback of their own. Poll Invoice status (or List invoices with a status filter) to see paid, partially_paid and overdue.

Step by step: find out who has paid

  1. Run a job every few minutes that calls List invoices with status pending, partially_paid and overdue.
  2. For each invoice that now reads paid, mark your own record paid (once) and issue the receipt.
  3. For an invoice that reads partially_paid, store amount_paid and ask for the balance.
  4. Page through long lists with limit (1 to 100) and starting_after (send next_cursor from the previous page) until has_more is false.

curl https://api.moolre.com/open/invoice/list \  -H "Content-Type: application/json" \  -H "X-API-USER: $MOOLRE_USER" \  -H "X-API-KEY: $MOOLRE_KEY" \  -d '{    "accountnumber": "1000000000001",    "status": "pending",    "limit": 50  }'

Step by step: cancel an invoice

  1. Call Cancel invoice with the invoiceid. INV17 means it is cancelled (also when it was already cancelled).
  2. If the reply is INV18, the invoice is paid or has payments and cannot be cancelled. The reply carries the invoice so you can see how much was paid.

Cancelling does not return money

A cancelled invoice stops accepting new payments. Money already paid stays in your wallet. If you need to give a customer money back, send them a payout with Initiate Transfer and keep your own record linking it to the invoice.

Common errors and fixes

CodeMeaningFix
INV03A field is missing or invalid (accountnumber, invoice_name, narration, metadata, status filter, invoiceid)Read data: it names the failing field. Only the first failing field is reported
INV04Customer invalidSend name (required, at most 100 characters), phone (9 to 15 digits) and optional email
INV05Amount, items or tax invalidSend either amount or items, and tax from 0 to 100
INV06due_date missing, malformed, in the past or too farSend YYYY-MM-DD or YYYY-MM-DD HH:MM:SS (UTC), up to 2 years ahead
INV07reference reused for a different invoiceUse a new reference, or resend the original body to get the original invoice
INV08, INV09Currency does not match the wallet, or no collection service on the walletSend the wallet currency; create a collection service in the app
INV12Invoice not foundCheck invoiceid or reference
INV13A public key was usedUse the private key
INV18The invoice has payments and cannot be cancelledLeave it, or handle the refund yourself outside the invoice

Checklist

  • Every invoice has your own unique reference and an Idempotency-Key.
  • You send the payment_link yourself and store the invoiceid.
  • A polling job finds invoices that became paid, partially paid or overdue, and marks each bill paid once.
  • You cancel invoices you no longer want paid.
  • You reconcile paid invoices with the account statement.