WHMCS guide

How to find duplicate payments in WHMCS.

Searching for a repeated transaction ID is the obvious check, and it can come back empty while money is still booked twice. On one of our own installs it returns nothing, yet some invoices hold two payments: one keyed by hand with no transaction ID and one from the gateway.

DMS.S2 — Before you start

Before you run anything.

Read only

Every query below is a SELECT. It changes nothing. Run it in phpMyAdmin or the mysql client, on a copy of the database if you have one.

A row is a lead, not a verdict

A client may really have paid twice, or a gateway may split one payment. Check the gateway dashboard before you touch anything.

Do not just delete the row

If the money arrived twice, refund it or keep it as client credit. If it was only booked twice, back up the database before correcting the ledger.

DMS.S3 — The queries

Three ways to find them.

Same gateway transaction ID booked twice

The classic case: a callback that ran two times.

SELECT gateway, transid, COUNT(*) AS times, GROUP_CONCAT(invoiceid ORDER BY id) AS invoice_ids
FROM tblaccounts
WHERE amountin > 0 AND transid <> '' AND gateway <> ''
GROUP BY gateway, transid
HAVING COUNT(*) > 1;

More money than the invoice was worth

Catches the double that has no repeated ID. Late fees that WHMCS 9 adds as a debit note are counted as owed, so they do not show up here.

SELECT i.id AS invoice_id, i.userid AS client_id, i.total,
       SUM(IF(a.gateway NOT IN ('', 'credit'), a.amountin - a.amountout, 0)) AS received,
       SUM(IF(a.gateway = '' AND a.description NOT LIKE '%Overpayment%', a.amountout, 0)) AS added_later
FROM tblinvoices i
JOIN tblaccounts a ON a.invoiceid = i.id
WHERE i.total > 0
GROUP BY i.id, i.userid, i.total
HAVING received > i.total + added_later + 0.01;

One period billed on two invoices

Same service or domain and same due date on two invoices, at least one still open: the client is being asked to pay twice.

SELECT IF(ii.type LIKE 'Domain%', 'Domain', ii.type) AS kind, ii.relid, ii.duedate,
       GROUP_CONCAT(DISTINCT CONCAT('#', i.id, ' ', i.status) ORDER BY i.id) AS invoices
FROM tblinvoiceitems ii
JOIN tblinvoices i ON i.id = ii.invoiceid
WHERE ii.type IN ('Hosting', 'Addon', 'Domain', 'DomainRegister', 'DomainRenew', 'DomainTransfer')
  AND ii.relid > 0 AND ii.duedate > '1000-01-01' AND i.total > 0
  AND i.status IN ('Unpaid', 'Payment Pending', 'Overdue', 'Paid')
GROUP BY kind, ii.relid, ii.duedate
HAVING COUNT(DISTINCT i.id) > 1 AND SUM(i.status <> 'Paid') > 0;

DMS.S4 — The addon

Or get the list inside the WHMCS admin.

Brasa Billing Audit runs these comparisons and more, explains each finding with what to do next and e-mails admins when a new one appears. It never changes an invoice or a payment.

Brasa Billing Audit screen in the WHMCS admin, with sample data

Brasa Billing Audit

$39 per year

Finds the billing records that do not add up.

  • Payment booked twice, and more money than the invoice was worth
  • Credit with no money behind it, and invoices marked Paid with nothing allocated or with every payment refunded
  • Client billed twice for one period, and a period that will never be billed
  • Suspended but paid up, a domain set to renew at 0 on a paid extension, a next due date after the registrar expiry, a late fee charged before the due date, a payment booked to no invoice or to a deleted one, a payment dated before its invoice was created, 48 checks in all
First run in 16 seconds, on sample data: the summary, then each finding with what to do about it. Brasa Billing Audit on the WHMCS Marketplace
Buy for $39

DMS.S5 — Questions

Fixing a double payment.

A client really paid twice. What do I do?

Refund the second payment through the gateway, or leave it as client credit if the client agrees. WHMCS then applies the credit to a later invoice.

Why does the transaction ID query return nothing?

A payment added by hand often has an empty or typed transaction ID, so it never matches the gateway one. Compare the money received with the invoice total instead.

DMS.S6 — Start a project

Found money these queries miss?

Tell us how it was booked. If other hosts would hit it, it may become a check.