Repository navigation
fix(main): persist customer attribution on zero-balance bill settlement - #1261
Conversation
Ensure single and batch zero-balance settlements bind newly selected customer_id on bills before reading freshBill, award eligible loyalty cashback once, cache the attributed bill in payment_idempotency, and preserve customer conflict/missing customer rejections. Fixes #1254
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@greptileai review this at apex |
[Medium impact] The PR appears safe to merge; no new actionable issue was found.
|
|
@greptileai review this at apex |
Fixes #1254
Intent
Fix finding N2 (GitHub issue #1254) in FreeOpenSourcePOS/FloCafe: when settling a bill whose remaining balance is zero (
prepared.length === 0inapplyPaymentBatchinmain/routes/bills.ts) viaPOST /api/bills/:id/paymentorPOST /api/bills/:id/paymentswith a newly selectedcustomer_id, persist the validatedeffectiveCustomerIdtobills.customer_idwhen!bill.customer_id && effectiveCustomerIdbefore re-readingfreshBilland computingcalculateCashback, matching the positive-payment branch. Ensure single and batch zero-balance settlements bindcustomer_idon the bill, award eligible loyalty cashback once whenfreshBill.total > 0, cache the attributed bill inpayment_idempotency, and preserve existing customer conflict (customer_mismatch) and missing-customer (customer_unavailable) rejections.What Changed
applyPaymentBatchinmain/routes/bills.tsto persisteffectiveCustomerIdtobills.customer_idduring zero-balance settlements (prepared.length === 0) when the bill does not already have a customer bound.docs/architecture/order-lifecycle.mdto document that single and batch zero-balance settlements bind newly selected customer IDs and award eligible loyalty cashback when the bill total is positive.tests/bills-settlement-idempotency.test.tsverifying customer binding, loyalty ledger accrual, idempotency replay caching, and customer mismatch/unavailability validation on zero-balance settlements.Risk Assessment
✅ Low: The change is a well-bounded, surgical fix that persists validated customer attribution during zero-balance bill settlement matching the positive-payment path, with complete test coverage and documentation.
Testing
Validated finding N2 zero-balance customer attribution and cashback remediation across 5 live end-to-end scenarios against a running FloCafe instance with full SQLite persistence, followed by regression execution of test:financial-safety-remediation and test:issue-zero-balance-settlement. Single and batch zero-balance settlements successfully bind newly selected customers to the bill, award loyalty cashback once on positive-total bills, replay idempotently with cached responses, and preserve customer conflict and missing-customer rejections.
Evidence: Live Scenarios Markdown Report
Evidence: Scenario 1 - Single Payment Customer Binding Evidence
Evidence: Scenario 2 - Batch Payment Customer Binding Evidence
Evidence: Scenario 3 - Loyalty Cashback & Idempotency Evidence
Evidence: Scenario 4 - Adversarial Customer Mismatch Evidence
Evidence: Scenario 5 - Adversarial Customer Unavailable Evidence
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
Live scenario 1: Single payment on zero-remaining-balance bill binds customer_id in response and SQLiteLive scenario 2: Batch payment on zero-remaining-balance bill binds customer_id in response and SQLiteLive scenario 3: Zero-balance settlement on bill with total > 0 awards cashback and supports idempotent replayLive scenario 4: Adversarial zero-balance settlement with conflicting customer_id is rejected with customer_mismatchLive scenario 5: Adversarial zero-balance settlement with non-existent customer_id is rejected with customer_unavailablenpm run test:financial-safety-remediation (tests/financial-safety-remediation.test.ts & tests/bills-settlement-idempotency.test.ts)node tests/run-electron-node-test.cjs tests/issue-zero-balance-settlement.test.ts✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.