Invoices mark themselves paid

A verified payment event records the payment against the right invoice, once, with the money only counted when funds have actually cleared.

What it is

A thin route that hands the raw body and signature to the payments adapter for verification and interpretation, then records the payment. Verification tries every configured signing secret because the payload cannot be parsed for the account until after verification. Refunds and disputes are acknowledged and logged rather than acted on.

Also called: payment confirmation · invoice paid automatically · checkout webhook

See it
Invoices mark themselves paid
Prepared for
Ronan Petsch
1140 Ridge Line Rd · Fair Play
Shell package$26,623
Concrete & site$7,729
Doors & windows$5,153
Trim & finish$3,435
Total
$42,940
Signature
An invoice flipping from Sent to Paid with a payment row appearing, timestamped seconds after the customer's checkout. Sample data — no customer information appears here.
How it works
  1. 1The raw body is read (never parsed first, because the signature is over the raw bytes).
  2. 2The adapter verifies against each candidate signing secret: environment first, then every account's stored secret.
  3. 3Completed sessions are gated on payment_status being paid, so bank-debit methods that complete before funds clear do not mark an invoice paid.
  4. 4The invoice, account and amount are read from the session metadata and recorded idempotently.
  5. 5A database failure returns 500 so the provider retries; the reconcile sweep is the ultimate backstop.
Why we built it

The route calls itself 'the SOURCE OF TRUTH for marking an invoice paid'. The paid gate is called out in the adapter: 'async methods (ACH) fire completed before funds clear; only paid should mark the invoice.' The multi-secret loop exists because 'the Stripe webhook payload can't be parsed for the org until AFTER signature verification.'

The problem
  • Invoices had to be marked paid by hand.
  • Bank-debit payments were marked paid before funds cleared.
  • The account could not be identified before the signature was verified.
Sound familiar?
What you get
Paid invoices update themselves within seconds.
Only cleared funds change an invoice's status.
Duplicate deliveries cannot double-record a payment.

See it on your own jobs

Twenty minutes, your numbers, no slide deck. We’ll build one of your real buildings in front of you and send you the estimate link at the end — yours to keep either way.

or keep browsing features →