fix(billing): reject non-positive payment amounts with a 422 #269
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/PMS-373-reject-non-positive-payment-amount"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
POST /api/v1/payments accepted amount <= 0 and persisted it (e.g. -50.00), corrupting invoice balances and revenue reporting. The amount field used validate_money_amount, which intentionally bounded only the magnitude and left the sign unconstrained.
Add validate_payment_amount: a payment amount must be strictly positive, at most 2 decimal places, and within the DECIMAL(12, 2) column magnitude. CreatePaymentRequest::amount now uses it, so request.validate()? rejects amount <= 0 (and over-precise / oversized values) with a field-level 422 before any row is created.
Add migration 051: a payments_amount_positive CHECK (amount > 0) backstop, added NOT VALID so the migration does not fail on pre-existing dirty rows while still enforcing the rule on every new write. Any existing amount <= 0 rows are surfaced via a RAISE WARNING (not silently mutated) for deliberate finance cleanup.
Update the billing model tests to assert non-positive and over-precise amounts are rejected (replacing the old test that asserted negative amounts were allowed), and add validation unit tests.
#PMS-373