Repository navigation
Open
Description
Summary
app/Controllers/Sales.php::postComplete() repeats the handling of integer results from Sale::save_value() across invoice, standard sale, work order, and quote flows.
Create a small result abstraction to remove the repeated sentinel checks while preserving the current HTTP behavior.
Required changes
- Add a
SaleSaveOutcomevalue object.- Represent successful saves with a sale ID.
- Represent
INSUFFICIENT_GIFTCARD_BALANCE. - Represent
INSUFFICIENT_REWARD_POINTS. - Represent generic failure, including the
NEW_ENTRYresult.
- Add a
SaleSaveStatusenum or an equivalent explicit status type. - Add a thin
SaleSaveServiceadapter aroundSale::save_value().- The adapter must convert the current integer result into
SaleSaveOutcome.
- The adapter must convert the current integer result into
- Update
Sales::postComplete()to use the outcome object.- Keep
reload(),clear_all(), session operations, and view selection inSales. - Preserve the existing error messages and success behavior.
- Keep
- Consider extracting shared work-order and quote behavior only if it remains small and clear.
Rationale
The current controller checks the same save-result sentinels in several branches. A typed outcome makes success and failure states explicit. It also reduces the risk that a new branch handles payment failures but omits NEW_ENTRY, which can otherwise produce a false success response.
Affected areas
app/Controllers/Sales.phpapp/Models/Sale.php- New classes under an appropriate application service or value-object namespace
- Tests for save-result mapping and controller behavior, as applicable
Acceptance criteria
Sale::save_value()result values map to explicit outcome states.- All existing
postComplete()flows show the same localized messages for insufficient gift-card balance, insufficient reward points, and generic transaction failure. - Work-order and quote flows do not set a suspended ID or render a success view when the save fails.
- The controller keeps HTTP rendering and session state management.
- Existing regression tests pass, and new tests cover the outcome mapping.
Backlinks
- Requested by @objecttothis
- Pull request: Bugfix: Resolve Race Condition in Rewards and Gift Card Spending #4640
- Review comment: Bugfix: Resolve Race Condition in Rewards and Gift Card Spending #4640 (comment)
Metadata
Metadata
Assignees
Labels
No labels
Activity
objecttothis commentedon Oct 22, 2026
Claude Issue Checker Agent (cc @objecttothis)
Investigated against current
master.Status: Still present (refactor not done).
No
SaleSaveOutcome,SaleSaveStatus, orSaleSaveServiceclasses exist anywhere in the codebase.Sales::postComplete()inapp/Controllers/Sales.phpstill repeats the same raw sentinel check against$data['sale_id_num'](INSUFFICIENT_GIFTCARD_BALANCE,INSUFFICIENT_REWARD_POINTS,NEW_ENTRY) independently in the invoice, work-order, quote, and POS/return branches — four duplicated copies of the same if/elseif chain, exactly as described in the issue.