fix(pos): clamp payment amount to total + allow 1c tolerance for rounding

This commit is contained in:
Deploy
2026-08-26 23:25:53 +02:00
parent be1f014260
commit 642fe037c2
4 changed files with 27 additions and 6 deletions

View File

@@ -1906,15 +1906,17 @@ export default function RegisterPage() {
key={method.id}
type="button"
onClick={() => {
// POS-SELFPAY-FLOW: no partial payments — directly add full payment and confirm
// POS-SELFPAY-FLOW: no partial payments — directly add full payment and confirm.
// Clamp to totals.total to avoid 1-cent rounding mismatches with the backend.
setShowSelfpayPaymentMethods(false);
const amountCents = Math.min(remainingCents, totals.total);
const allocation: PaymentAllocation = {
id: generateIdempotencyKey(),
methodCode: method.code,
methodLabel: method.label,
kind: method.kind,
amountCents: remainingCents,
...(method.kind === 'cash' ? { tenderedCents: remainingCents } : {}),
amountCents,
...(method.kind === 'cash' ? { tenderedCents: amountCents } : {}),
changeCents: 0,
};
void confirmSaleWith([allocation]);

View File

@@ -111,7 +111,10 @@ export function validatePaymentAllocations(
};
});
const allocatedCents = validated.reduce((sum, payment) => sum + payment.amountCents, 0);
if (allocatedCents > totalCents) {
// Allow up to 1 cent tolerance for rounding differences between the front-end
// POS calculation (which uses cached prices) and the back-end canonical total
// (which re-reads the catalogue under a transaction).
if (allocatedCents - totalCents > 1) {
throw new AppError(
400,
'POS_PAYMENT_OVERPAYMENT',