Skip to content

fix(pos): enforce deferred-payment availability and order types - #1415

Merged
khaira777 merged 1 commit into
mainfrom
codex/audit-counter-flow
Oct 31, 2026
Merged

khaira777 merged 1 commit into
mainfrom
codex/audit-counter-flow

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Summary

Addresses release audit finding F-3 for counter workflow and deferred payment validation:

  • Restricts deferred-payment orders to supported order types (dine_in, takeaway, delivery, drive_thru), returning 400 for unsupported combinations.
  • Ensures the POS frontend disables or hides pay-later / deferred actions when the active counter configuration disallows deferred payment or when an incompatible order type is selected.

Changes

  • main/routes/orders.ts: Validate order type during deferred payment order creation, rejecting unsupported types.
  • CartPanel.tsx & pos/page.tsx: Respect counter configuration and order types for pay-later button availability and checkout workflows.
  • tests/multi-counter-ordering.test.ts & frontend/e2e/multi-counter-ordering.spec.ts: Add unit and E2E coverage for counter flow order types.
  • Documentation: Update counter ordering documentation in docs/architecture/order-lifecycle.md.

Stack

Verification

  • npm run test:multi-counter-ordering: Passed (271/271)
  • npm run test:pos-keyboard-shortcuts: Passed

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Gate deferred checkout by feature setting and order type

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Reject new deferred tickets when multi-counter ordering is disabled, without blocking existing
 tickets or replays.
• Route delivery and online POS orders through normal checkout, including keyboard shortcuts.
• Cover disabled-feature and checkout behavior in tests, and clarify the API contract.
Diagram

graph TD
  A["POS cart"] --> B{"Eligible type?"}
  B -->|yes| C["Deferred action"] --> D["Orders API"] --> E{"Feature enabled?"}
  B -->|no| F["Normal checkout"]
  E -->|yes| G["Deferred ticket"]
  E -->|no| H["409 response"]
Loading
High-Level Assessment

Keep the transactional API check as the authority and the POS checks for usability. A frontend-only restriction would not protect direct API requests; moving the API check ahead of idempotency handling would block valid committed replays.

Files changed (7) +226 / -18

Bug fix (3) +40 / -15
page.tsxAlign POS shortcuts and errors with deferred eligibility +21/-6

Align POS shortcuts and errors with deferred eligibility

• Routes ordering-counter shortcuts to deferred checkout only for takeaway and dine-in. Guards the deferred handler against other types and displays a localized message for MULTI_COUNTER_DISABLED.

frontend/src/app/(dashboard)/pos/page.tsx

CartPanel.tsxHide deferred actions for incompatible carts +4/-6

Hide deferred actions for incompatible carts

• Shows Send to payment at ordering and combined counters only for takeaway and dine-in carts, leaving other types on the normal Place Order path.

frontend/src/components/pos/CartPanel.tsx

orders.tsReject new deferred orders when multi-counter is disabled +15/-3

Reject new deferred orders when multi-counter is disabled

• Checks multi_counter_enabled inside the order-creation transaction before allocating an order number. Returns 409 with a stable MULTI_COUNTER_DISABLED code while preserving committed idempotent replays.

main/routes/orders.ts

Tests (2) +179 / -0
multi-counter-ordering.spec.tsExercise eligible and normal POS checkout flows +65/-0

Exercise eligible and normal POS checkout flows

• Checks that delivery and online carts lack the deferred action and complete immediate checkout through clicks and shortcuts. Verifies that a disabled-feature response preserves the cart and allows retry.

frontend/e2e/multi-counter-ordering.spec.ts

multi-counter-ordering.test.tsCover disabled-feature creation and existing-ticket behavior +114/-0

Cover disabled-feature creation and existing-ticket behavior

• Verifies rejected creation leaves orders, bills, idempotency records, stock, and sequences unchanged while ordinary orders remain available. Confirms existing tickets can be paid, refunded, and cancelled after disabling, and committed replays and hash conflicts retain their behavior.

tests/multi-counter-ordering.test.ts

Documentation (2) +7 / -3
order-lifecycle.mdClarify multi-counter eligibility and feature availability +6/-2

Clarify multi-counter eligibility and feature availability

• Specifies that delivery and online orders use normal checkout. Documents the disabled-feature rejection and continued availability of committed replays and existing deferred tickets.

docs/architecture/order-lifecycle.md

api.mdDocument deferred order creation responses +1/-1

Document deferred order creation responses

• Clarifies supported order types for on-payment creation and documents the 409 MULTI_COUNTER_DISABLED response when the feature is off.

docs/reference/api.md

@qodo-code-review

qodo-code-review Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Checkout test fails on postpaid stores ✓ Resolved
Description
The new delivery and online test step expects handlePlaceOrder to open a Confirm Payment modal
without first setting prepaid billing. When the store uses its default postpaid setting, checkout
creates the order directly, so the modal assertion times out before the test records the order ID
for cleanup.
Code

frontend/e2e/multi-counter-ordering.spec.ts[R291-294]

+          await page.evaluate(() => (document.activeElement as HTMLElement | null)?.blur());
+          await page.keyboard.press(action);
+        }
+        await expect(page.getByRole('button', { name: /Confirm Payment/ })).toBeVisible();
Relevance

●●● Strong

The test unconditionally expects a prepaid modal although default billing is postpaid, causing
checkout timeout and cleanup failure.

PR-#1412

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The added step waits for a payment modal before recording the created order. The POS handler opens
that modal only for prepaid billing; the database default is postpaid, and this test does not read
or change billing settings until a later step.

frontend/e2e/multi-counter-ordering.spec.ts[271-305]
frontend/src/app/(dashboard)/pos/page.tsx[1627-1652]
main/db.ts[11008-11013]
frontend/e2e/multi-counter-ordering.spec.ts[423-434]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The added checkout test assumes prepaid billing, but a postpaid store creates the order without opening the modal and leaves that order untracked when the assertion fails.
## Fix Focus Areas
- frontend/e2e/multi-counter-ordering.spec.ts[271-303]
- frontend/e2e/multi-counter-ordering.spec.ts[427-434]
- frontend/e2e/multi-counter-ordering.spec.ts[1410-1424]
## Recommended Fix
Capture the prior business billing settings and explicitly enable prepaid billing before the new checkout step. Restore the prior settings in the existing cleanup path, and preserve the later step’s explicit switch to postpaid.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #1414
✅ Compliance rules (platform): 5 rules
✅ Cross-repo context — repo relationships
  Explored: repo: FreeOpenSourcePOS/docs.flopos.com (sha: abe7cff3) — View relationship
Review mode: Auto: ⚖️ Balanced: Behavioral changes span API validation, POS workflows, settings, and tests.

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@khaira777
khaira777 force-pushed the codex/audit-counter-flow branch from cb3a24b to b0ab06b Compare October 31, 2026 21:26
@khaira777
khaira777 force-pushed the codex/audit-scheduled-release branch 2 times, most recently from 631ee15 to 7129ecf Compare October 31, 2026 22:43
@khaira777
khaira777 changed the base branch from codex/audit-scheduled-release to main October 31, 2026 22:55
@khaira777
khaira777 force-pushed the codex/audit-counter-flow branch from b0ab06b to b5970ba Compare October 31, 2026 22:55
@khaira777
khaira777 merged commit bcdcce5 into main Oct 31, 2026
23 checks passed
@khaira777
khaira777 deleted the codex/audit-counter-flow branch October 31, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant