Skip to content

Split-tender: card/upi lines silently capped to remaining balance, corrupting reconciliation and receipts #214

Closed

Description

@silasfrostx

Split-tender: non-cash payment lines are silently capped, misattributing revenue between methods

Spent a while reading FloCafe today at 98a8db3. Context for the report: this is a notably well-hardened codebase for its size — the Master PIN gate fails closed when OS encryption is unavailable, discounts are clamped at both order and item level, the JWT secret has no static fallback, and every privileged route I checked is correctly gated against cashier/waiter/chef. I went looking for the usual POS problems and most of them are already handled. So this is one specific finding, not a list.

The bug

applyPayment in main/routes/bills.ts:331-352 caps every payment line at the balance remaining at the moment that line is processed, regardless of method:

const remainingBalance = Math.max(0, bill.total - bill.paid_amount);
...
paidAmount = Math.min(parsed, remainingBalance);

There's no branch on method. For cash that's exactly right — that's how change works — and for wallet it's reconciled by its own ledger. But card and upi represent money that already moved on a separate physical terminal, outside this software. Capping those doesn't prevent an overpayment; it just records a number that doesn't match what was charged.

Repro

Bill total 42. Cashier enters a normal split — cash 30, card 30 (customer puts 30 on the card, hands over 30 cash, expects 18 back). The batch endpoint at bills.ts:502-506 loops in array order:

line requested remaining at that point recorded
cash 30 42 30
card 30 12 12 — but 30 was charged on the terminal

Recorded total is 30 + 12 = 42, which matches the bill exactly, so nothing in the app looks wrong. But the method breakdown is now inverted against reality: true cash retained after change was 12, true card settlement was 30.

That breakdown isn't cosmetic — it's the record of truth for two things:

  • main/routes/reports.ts:61-68 and :257-262 aggregate it for sales-by-method and the daily cash-drawer reconciliation, so the owner's card-processor statement won't match the POS.
  • frontend/src/lib/printer/receipt-encoder.ts:229-231 prints payment_details verbatim, so the customer receipt shows a card line that doesn't match their card charge.

The frontend's change calculation (PaymentModal.tsx:154-161) assumes any overage is cash — hasCash && totalPayment > remaining — but nothing enforces that the overage actually sits on the cash line.

Why it isn't caught today

tests/integration-payments.test.ts and integration-discount-edge.test.ts only cover exact, non-overlapping splits. The one overpayment test (integration-loyalty-redemption.test.ts:445) is single-line wallet-only and asserts the intended capping behaviour. The multi-line cash+card interaction isn't covered.

Suggested fix

Only let cash (and wallet) absorb an overage; reject rather than truncate for external-terminal methods:

if (parsed > remainingBalance) {
  if (method !== 'cash') {
    // card/upi represent money already collected on an external terminal --
    // silently reducing the recorded amount corrupts reconciliation and the
    // printed receipt. Reject instead of truncating.
    throw Object.assign(
      new Error(`${method} amount (${parsed}) exceeds remaining balance (${remainingBalance}). Only cash may exceed the balance to make change.`),
      { statusCode: 400 },
    );
  }
  paidAmount = remainingBalance; // cash absorbs overpayment as change, as today
} else {
  paidAmount = parsed;
}

Worth mirroring the same rule in PaymentModal before submit, so the cashier gets an immediate error rather than a silently-wrong receipt.

One other thing, lower severity

main/routes/auth.ts:269-274 — the "Demo" setup profile seeds [email protected] / [email protected] / [email protected] with the fixed password demo12345, and there's no forced-rotation flag. Since main/server.ts:231 binds 0.0.0.0 (needed for KDS/mobile pairing), an owner who trials with the Demo profile and then starts taking real orders has a manager-role login — void, discount, reports, staff — reachable by anyone on the shop Wi-Fi, using credentials that are in this public repo. Marking those accounts inactive until a password is chosen, or generating a random one shown once during setup, would close it.

Happy to open a PR for the payment fix with a regression test for the cash+card case if that's useful — just say the word and I'll follow whatever contribution flow you prefer.

Activity

  1. self-assigned this
    on Aug 4, 2026
  2. khaira777 commented on Aug 4, 2026

    @khaira777
    Contributor

    Resolved in PR #215: #215. The split-payment accounting and demo-credential remediation fixes will ship in the next release.

  3. added
    area:backend
    area:frontend
    on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:backendarea:frontend

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions