Skip to content

feat(refunds): add configurable manager policy - #1529

Merged
khaira777 merged 6 commits into
mainfrom
fm/flocafe-configurable-refund-policy
Nov 9, 2026
Merged

khaira777 merged 6 commits into
mainfrom
fm/flocafe-configurable-refund-policy

Conversation

@khaira777

@khaira777 khaira777 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1519

Intent

For the refunding for an order, we have a hard limit of one hour if it is anyone other than the owner. Make that a configurable option in the settings (30 minutes, 1 hour, 2 hours, 4 hours, or same business day; default 1 hour), with an owner-controlled enable/disable toggle for manager approval. For the owner level, remove the 1-day / same-business-day hard limit so the owner can refund any eligible paid order backdated (Staff Approval PIN still required). Cashiers may initiate when granted permission and always require eligible Manager/Owner approval.

What Changed

  • Added owner-configurable refund_manager_enabled (default true) and refund_manager_window (30m, 1h, 2h, 4h, or same_business_day; default 1h) settings exposed via GET/PUT /api/settings/refunds and the POS Settings tab, restricting modifications to the owner role.
  • Updated checkIsLateRefund and validateRefundPreconditions in main/services/refund.ts so manager Staff Approval PINs are accepted only when manager approval is enabled and the order is within both the configured window and its anchor business day, while removing the same-business-day expiration cutoff so owners can approve refunds on eligible paid orders from any past business day.
  • Updated RefundModal and locale translations across all 32 supported languages to load the active refund policy and business day settings, filter eligible approvers dynamically by window/day cutoff, and refresh policy state before submission.

Risk Assessment

✅ Low: The configurable manager refund approval window, owner toggle, and removal of the owner-level same-business-day refund cutoff are cleanly enforced in the backend and frontend with comprehensive behavioral test coverage.

Testing

Ran the targeted refund and translation suites (npm run test:refund-completed-orders with 50/50 assertions passing, npm run test:refunds with 83/83 and 40/40 assertions passing, and npm run test:translations across all 32 locales) and stood up an isolated FloCafe server and SQLite database driven end-to-end via headless Chromium with Playwright to exercise all five user-intent scenarios and adversarial guards, capturing seven UI screenshots and structured API/DB verification evidence.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Owner configures Refund Policy in Settings > POS Workflow (default 1h, options 30m/1h/2h/4h/same_business_day, and manager enable toggle) while Managers see read-only controls and receive HTTP 403 on… ✅ pass live ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/scenario-1-owner-settings-refund-policy.png, ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/scenario-1-ma…
Configurable manager refund approval window (30m, 1h, 2h, 4h, same_business_day) allows Manager PIN within the configured window (e.g. 90m order under 2h window returns 201) and rejects Manager PIN on… ✅ pass live ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/scenario-2a-manager-approves-90m-order-under-2h-window.png, ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8…
Disabling Allow Manager Refund Approvals (refund_manager_enabled = false) immediately restricts RefundModal approvers to Store Owner with owner-only notice on a newly paid order, rejects Manager PIN w… ✅ pass live ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/scenario-3-manager-disabled-owner-pin-required.png, ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/live-r…
Store Owner refunds backdated paid orders (45 days old in live UI and 1 year old in API suite) with Owner Staff Approval PIN (201 Created, bill marked refunded, audit log records lateRefund: true), wh… ✅ pass live ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/scenario-4-owner-backdated-45d-order-refund.png, ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/live-refu…
Cashier without refunds.initiate is rejected with 403, and Cashier granted refunds.initiate initiates a refund in the UI and completes it with an eligible Manager Staff Approval PIN (201 Created, crea… ✅ pass live ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/scenario-5-cashier-initiates-refund-with-manager-approval.png, ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA…

Owner Settings > POS Workflow: Refund Policy card with toggle and window selector (2 hours selected)
Manager Settings > POS Workflow: Refund Policy controls rendered read-only/disabled for non-owner staff
RefundModal: Manager approves a 90-minute-old order under the configured 2-hour manager window
RefundModal: 40-minute-old order under 30-minute manager window requires Store Owner PIN with outside-window notice
RefundModal: Freshly paid order when Manager Refund Approvals toggle is disabled requires Store Owner PIN with owner-only notice
RefundModal: Store Owner refunds a 45-day backdated paid order with Staff Approval PIN
RefundModal: Cashier with refunds.initiate permission initiates refund and completes it with Manager PIN approval

Evidence: Live Playwright + API + SQLite verification results across all 5 refund policy scenarios
{
  "scenarios": {
    "scenario1_settings_and_rbac": {
      "defaultVal": "1h",
      "optionValues": [
        {
          "value": "30m",
          "label": "30 minutes"
        },
        {
          "value": "1h",
          "label": "1 hour"
        },
        {
          "value": "2h",
          "label": "2 hours"
        },
        {
          "value": "4h",
          "label": "4 hours"
        },
        {
          "value": "same_business_day",
          "label": "Same business day"
        }
      ],
      "ownerPutStatus": 200,
      "ownerPutResponse": {
        "refund_manager_enabled": true,
        "refund_manager_window": "2h"
      },
      "mgrToggleDisabled": true,
      "mgrSelectDisabled": true,
      "mgrSelectedValue": "1h",
      "mgrApiWriteStatus": 403,
      "mgrApiWriteBody": {
        "error": "Only the store owner can modify refund policy"
      },
      "invalidWindowWriteStatus": 400,
      "invalidWindowWriteBody": {
        "error": "refund_manager_window must be 30m, 1h, 2h, 4h, or same_business_day"
      }
    },
    "scenario2_configurable_windows": {
      "order90mNumber": "ORD-20261108-0001",
      "order90mCreatedAt": "2026-11-08 22:17:41",
      "refund90mUnder2hStatus": 201,
      "refund90mApprovedBy": "e2e-manager",
      "order40mNumber": "ORD-20261108-0002",
      "order40mCreatedAt": "2026-11-08 23:07:43",
      "outsideWindowNoticeVisible": true,
      "mgrDirectAttempt40mStatus": 403,
      "mgrDirectAttempt40mError": "Invalid owner PIN"
    },
    "scenario3_manager_toggle_disabled": {
      "freshOrderNumber": "ORD-20261108-0003",
      "mgrDisabledAttemptStatus": 403,
      "mgrDisabledAttemptError": "Invalid owner PIN",
      "ownerOnlyNoticeVisible": true,
      "singleApproverText": "Approved by: Store Owner",
      "ownerApprovedStatus": 201,
      "ownerApprovedBy": "e2e-owner"
    },
    "scenario4_owner_unlimited_backdated": {
      "oldOrderNumber": "ORD-20261108-0004",
      "backdatedCreatedAt": "2026-09-24 23:47:48",
      "mgrBackdatedAttemptStatus": 403,
      "mgrBackdatedAttemptError": "Invalid owner PIN",
      "ownerWrongPinAttemptStatus": 403,
      "ownerWrongPinAttemptError": "Invalid owner PIN",
      "ownerBackdatedRefundStatus": 201,
      "ownerBackdatedPaymentStatus": "refunded",
      "ownerBackdatedApprovedBy": "e2e-owner",
      "dbAuditDetails": {
        "refundId": 3,
        "billId": 4,
        "amountCents": 6420,
        "method": "cash",
        "lateRefund": true,
        "approvedBy": "e2e-owner",
        "reason": null
      }
    },
    "scenario5_cashier_initiation": {
      "cashierOrderNumber": "ORD-20261108-0005",
      "cashierUnpermittedStatus": 403,
      "cashierPermittedRefundStatus": 201,
      "refundCreatedBy": "e2e-cashier",
      "refundApprovedBy": "e2e-manager",
      "auditActorUserId": "e2e-cashier"
    }
  }
}
- Outcome: 🔧 1 issue found ✅ across 2 runs (41m2s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ No issues found.

🔧 **Test** - 1 issue found ✅
  • ⚠️ The Test agent did not finish within its invocation budget. Reported: agent run tests timed out after 30m0s: agent last produced output 467ms ago (72 observed); agent reported: antigravity parse events: context deadline exceeded. This is a budget or provider-slowness cut, not a code failure. Re-running the same request costs another full budget, so no further attempt is made automatically. If this repository's targeted tests or evidence gathering routinely approach the default 30m0s, raise test_agent_timeout in global config. Respond with fix to spend another budget: a repair turn runs only for selected findings other than this budget cut, then validation re-runs. Or abort and retry after raising the budget.

✅ No issues found.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Owner configures Refund Policy in Settings > POS Workflow (default 1h, options 30m/1h/2h/4h/same_business_day, and manager enable toggle) while Managers see read-only controls and receive HTTP 403 on… ✅ pass live ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/scenario-1-owner-settings-refund-policy.png, ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/scenario-1-ma…
Configurable manager refund approval window (30m, 1h, 2h, 4h, same_business_day) allows Manager PIN within the configured window (e.g. 90m order under 2h window returns 201) and rejects Manager PIN on… ✅ pass live ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/scenario-2a-manager-approves-90m-order-under-2h-window.png, ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8…
Disabling Allow Manager Refund Approvals (refund_manager_enabled = false) immediately restricts RefundModal approvers to Store Owner with owner-only notice on a newly paid order, rejects Manager PIN w… ✅ pass live ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/scenario-3-manager-disabled-owner-pin-required.png, ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/live-r…
Store Owner refunds backdated paid orders (45 days old in live UI and 1 year old in API suite) with Owner Staff Approval PIN (201 Created, bill marked refunded, audit log records lateRefund: true), wh… ✅ pass live ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/scenario-4-owner-backdated-45d-order-refund.png, ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/live-refu…
Cashier without refunds.initiate is rejected with 403, and Cashier granted refunds.initiate initiates a refund in the UI and completes it with an eligible Manager Staff Approval PIN (201 Created, crea… ✅ pass live ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA8Q8K/scenario-5-cashier-initiates-refund-with-manager-approval.png, ~/.no-mistakes/evidence/01M6YMM4C800YWG9E4ZRJA…
  • npm run test:refund-completed-orders
  • npm run test:refunds
  • npm run test:translations
  • node tests/run-electron-node-test.cjs /tmp/run-live-refund-scenarios.cjs (live Playwright Chromium browser + FloCafe Express/SQLite server verification across all 5 scenarios)
✅ **Document** - passed

✅ No issues found.

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

✅ No issues found.

@coderabbitai

coderabbitai Bot commented Nov 8, 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

ⓘ Your Qodo trial ends soon. Ask your workspace admin to set up billing to keep reviews running after the trial. Manage billing

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Configure manager refund approvals and remove the owner age cutoff

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Let owners enable manager approvals and choose a refund window in POS settings.
• Allow active owners to approve eligible paid-order refunds regardless of order age, using their
 Staff Approval PIN.
• Align refund prompts, translations, tests, and documentation with the new approval tiers.
Diagram

graph TD
  A["POS settings"] --> B["Settings API"] --> C["Settings store"] --> F["Policy evaluator"] --> G{"Approval tier"} --> H["Staff PIN"]
  D["Refund modal"] --> E["Refund API"] --> F
  B -->|policy read| D
  G -->|manager or owner| H
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Share a pure approval-policy evaluator
  • ➕ Keeps frontend approver hints and backend eligibility calculations aligned as policy options evolve.
  • ➖ Requires a shared contract for timestamps, tenant timezone, and business-day settings; the backend must still independently enforce authorization.

Recommendation: Keep the backend authoritative and the current API-based policy loading for this PR. Consider extracting the duplicated time-window calculation into a shared pure function later if the approval rules expand; the added modal submission tests mitigate immediate drift risk.

Files changed (44) +1828 / -190

Enhancement (4) +395 / -37
page.tsxAdd owner-controlled refund policy settings +119/-1

Add owner-controlled refund policy settings

• Loads refund settings in the POS tab and adds an enable toggle and five-option manager window selector. Saves changes through the policy API and disables editing for non-owners.

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

RefundModal.tsxMatch refund approvers and PIN notices to policy +123/-16

Match refund approvers and PIN notices to policy

• Loads the refund policy and evaluates the configured window against tenant business time to filter approvers and show the appropriate notice. Rechecks eligibility during submission and while the modal remains open.

frontend/src/components/orders/RefundModal.tsx

settings.tsExpose owner-controlled refund policy API +88/-1

Expose owner-controlled refund policy API

• Adds authenticated policy reads and validated owner-only writes through named refund settings endpoints. Applies the same owner checks and value validation to wildcard writes.

main/routes/settings.ts

refund.tsEnforce configurable manager eligibility without owner expiry +65/-19

Enforce configurable manager eligibility without owner expiry

• Reads the manager policy and evaluates its duration and the order anchor's business-day end. Returns an owner-only approval tier instead of rejecting otherwise eligible paid orders from past business days.

main/services/refund.ts

Tests (2) +874 / -54
refund-completed-orders.test.tsCover policy tiers, settings access, and modal submission +849/-46

Cover policy tiers, settings access, and modal submission

• Tests default settings, owner-only writes, disabled manager approval, each configurable window, business-day boundaries, cashier initiation, and year-old owner-approved refunds. Adds modal submission checks for a two-hour window and a tenant-timezone same-day case.

tests/refund-completed-orders.test.ts

refunds.test.tsVerify prior-day owner refunds and manager rejection +25/-8

Verify prior-day owner refunds and manager rejection

• Changes the prior-business-day expectation to reject a manager PIN while accepting and recording an owner-approved refund.

tests/refunds.test.ts

Documentation (5) +45 / -35
authentication-and-authorization.mdIdentify owner-only refund policy authorization +1/-1

Identify owner-only refund policy authorization

• Adds refund policy settings to the documented owner-only context checks.

docs/architecture/authentication-and-authorization.md

business-time.mdDocument configurable refund business-time rules +9/-6

Document configurable refund business-time rules

• Explains manager windows, scheduled-order anchoring, business-day boundaries, and owner approval without an age cutoff.

docs/architecture/business-time.md

order-lifecycle.mdAlign refund lifecycle references with approval tiers +3/-2

Align refund lifecycle references with approval tiers

• Replaces references to a refund cutoff with references to the configurable manager window and approval rules.

docs/architecture/order-lifecycle.md

api.mdDocument refund policy endpoints and route inventory +8/-6

Document refund policy endpoints and route inventory

• Adds the authenticated policy read and owner-only write contracts, describes wildcard-key restrictions, and adjusts route counts.

docs/reference/api.md

product-invariants.mdDefine configurable refund approval invariants +24/-20

Define configurable refund approval invariants

• Specifies manager eligibility, owner-only approval after the window, unrestricted owner backdating, and the distinction between initiation permission and approval.

docs/reference/product-invariants.md

Other (33) +514 / -64
ar.jsonLocalize refund policy controls in Arabic +16/-2

Localize refund policy controls in Arabic

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/ar.json

bn.jsonLocalize refund policy controls in Bengali +16/-2

Localize refund policy controls in Bengali

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/bn.json

de.jsonLocalize refund policy controls in German +16/-2

Localize refund policy controls in German

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/de.json

en.jsonAdd English refund policy interface text +16/-2

Add English refund policy interface text

• Adds labels and explanations for policy settings, manager window choices, owner backdating, and owner-PIN notices.

frontend/src/lib/i18n/messages/en.json

es.jsonLocalize refund policy controls in Spanish +16/-2

Localize refund policy controls in Spanish

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/es.json

fa.jsonLocalize refund policy controls in Persian +16/-2

Localize refund policy controls in Persian

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/fa.json

fil.jsonLocalize refund policy controls in Filipino +16/-2

Localize refund policy controls in Filipino

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/fil.json

fr.jsonLocalize refund policy controls in French +16/-2

Localize refund policy controls in French

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/fr.json

ha.jsonLocalize refund policy controls in Hausa +16/-2

Localize refund policy controls in Hausa

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/ha.json

hi.jsonLocalize refund policy controls in Hindi +16/-2

Localize refund policy controls in Hindi

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/hi.json

id.jsonLocalize refund policy controls in Indonesian +16/-2

Localize refund policy controls in Indonesian

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/id.json

it.jsonLocalize refund policy controls in Italian +16/-2

Localize refund policy controls in Italian

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/it.json

ja.jsonLocalize refund policy controls in Japanese +16/-2

Localize refund policy controls in Japanese

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/ja.json

jv.jsonLocalize refund policy controls in Javanese +16/-2

Localize refund policy controls in Javanese

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/jv.json

ko.jsonLocalize refund policy controls in Korean +16/-2

Localize refund policy controls in Korean

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/ko.json

mr.jsonLocalize refund policy controls in Marathi +16/-2

Localize refund policy controls in Marathi

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/mr.json

ne.jsonLocalize refund policy controls in Nepali +16/-2

Localize refund policy controls in Nepali

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/ne.json

nl.jsonLocalize refund policy controls in Dutch +16/-2

Localize refund policy controls in Dutch

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/nl.json

pa.jsonLocalize refund policy controls in Punjabi +16/-2

Localize refund policy controls in Punjabi

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/pa.json

pt.jsonLocalize refund policy controls in Portuguese +16/-2

Localize refund policy controls in Portuguese

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/pt.json

ru.jsonLocalize refund policy controls in Russian +16/-2

Localize refund policy controls in Russian

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/ru.json

sq.jsonLocalize refund policy controls in Albanian +16/-2

Localize refund policy controls in Albanian

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/sq.json

sw.jsonLocalize refund policy controls in Swahili +16/-2

Localize refund policy controls in Swahili

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/sw.json

ta.jsonLocalize refund policy controls in Tamil +16/-2

Localize refund policy controls in Tamil

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/ta.json

te.jsonLocalize refund policy controls in Telugu +16/-2

Localize refund policy controls in Telugu

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/te.json

th.jsonLocalize refund policy controls in Thai +16/-2

Localize refund policy controls in Thai

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/th.json

tr.jsonLocalize refund policy controls in Turkish +16/-2

Localize refund policy controls in Turkish

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/tr.json

uk.jsonLocalize refund policy controls in Ukrainian +16/-2

Localize refund policy controls in Ukrainian

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/uk.json

ur.jsonLocalize refund policy controls in Urdu +16/-2

Localize refund policy controls in Urdu

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/ur.json

vi.jsonLocalize refund policy controls in Vietnamese +16/-2

Localize refund policy controls in Vietnamese

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/vi.json

zh-tw.jsonLocalize refund policy controls in Traditional Chinese +16/-2

Localize refund policy controls in Traditional Chinese

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/zh-tw.json

zh.jsonLocalize refund policy controls in Simplified Chinese +16/-2

Localize refund policy controls in Simplified Chinese

• Adds translated POS policy settings, window choices, owner backdating guidance, and owner-PIN notices.

frontend/src/lib/i18n/messages/zh.json

db.tsSeed default manager refund policy +2/-0

Seed default manager refund policy

• Seeds manager approval as enabled with a one-hour window on new installations.

main/db.ts

@khaira777 khaira777 changed the title feat: add configurable manager refund policy and remove owner age cutoff feat(refunds): add configurable manager policy Nov 8, 2026
@qodo-code-review

qodo-code-review Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Some managers can edit controls but not save 🐞 Bug ≡ Correctness
Description
The new refund controls use isOwner, which is derived from the configurable cloud.account.manage
permission, rather than the caller's owner role. A manager granted that permission can operate both
controls, but PUT /settings/refunds rejects the save because it requires `req.user.role ===
'owner'`.
Code

frontend/src/app/(dashboard)/settings/page.tsx[4550]

+                      disabled={!isOwner || savingRefundPolicy}
Relevance

●●● Strong

Accepted precedents gate controls on the permission the endpoint enforces (PR 988, PR 1452); the
mismatch fits that pattern. No close rejection.

PR-#988
PR-#1452

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
isOwner checks a permission that can be configured for roles, and the controls use it as their
write gate. The endpoint separately requires settings.manage and an exact owner role, producing a
403 for a manager whom the controls permit to click.

frontend/src/app/(dashboard)/settings/page.tsx[375-381]
frontend/src/lib/permissions.ts[5-9]
shared/permissions.ts[543-549]
frontend/src/app/(dashboard)/settings/page.tsx[4546-4568]
main/routes/settings.ts[1936-1945]

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

## Issue description
Permission-based control enablement does not match the refund policy endpoint's owner-role requirement.
## Fix Focus Areas
- frontend/src/app/(dashboard)/settings/page.tsx[4546-4568]
- frontend/src/app/(dashboard)/settings/page.tsx[375-381]
## Recommended Fix
Gate both refund-policy controls on the authenticated user's actual owner role and required settings permission, matching the endpoint authorization, instead of relying on the configurable cloud-account permission.

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

Dismiss ↗ | View ↗


2. A saved refund choice can appear undone 🐞 Bug ≡ Correctness
Description
The POS tab's policy loader unconditionally applies its GET response to refundManagerEnabled and
refundManagerWindow, even after a save handler has optimistically changed either value. If an
owner uses the controls before the initial GET finishes, that older response can arrive after a
successful PUT and replace the displayed choice while the server retains the new one.
Code

frontend/src/app/(dashboard)/settings/page.tsx[R2763-2765]

          setScheduledOrdersEnabled(res?.data?.setting?.value === 'true');
+          if (refundsRes?.data) {
+            setRefundManagerEnabled(refundsRes.data.refund_manager_enabled !== false);
Relevance

●●● Strong

Close precedent: a stale settings GET overwriting pending-save state was accepted in PR 1138; no
close rejection found.

PR-#1138

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The controls begin with interactive default values, the tab load is asynchronous, its response
assigns both values without checking for intervening saves, and each save independently changes
local state before issuing a PUT.

frontend/src/app/(dashboard)/settings/page.tsx[1773-1777]
frontend/src/app/(dashboard)/settings/page.tsx[2758-2775]
frontend/src/app/(dashboard)/settings/page.tsx[3586-3620]
frontend/src/app/(dashboard)/settings/page.tsx[4546-4568]

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

## Issue description
An outstanding POS settings load can overwrite the UI value of a successfully saved refund-policy change.
## Fix Focus Areas
- frontend/src/app/(dashboard)/settings/page.tsx[2758-2775]
- frontend/src/app/(dashboard)/settings/page.tsx[3586-3620]
- frontend/src/app/(dashboard)/settings/page.tsx[4546-4568]
## Recommended Fix
Keep the refund controls disabled until policy hydration completes, or track local edits and ignore an older GET response for fields changed since the request began. Ensure save responses leave the displayed values consistent with the persisted policy.

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

Dismiss ↗ | View ↗


3. Policy changes leave refund staff misled ✓ Resolved

Resolving commit: 257bd57

Resolution reason
Policy load failure now blocks approver-dependent submission (approversLoadFailed), and submit
refreshes the refund policy and approvers, recomputes eligibility, and clears the PIN if the
approver became ineligible.
Description
RefundModal treats a failed policy request as the enabled one-hour default and reuses the loaded
refundPolicy at submission without refreshing it. If an owner disables manager approvals or
changes the window while the modal is open, or the policy request fails, the modal can offer a
manager whom the backend rejects or withhold a manager whom the backend would accept.

Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #39
✅ Compliance rules (platform): 5 rules
✅ Cross-repo context — repo relationships
✅ REVIEW.md
Review mode: Auto: ⚖️ Balanced: Security-sensitive refund authorization and settings, but logic is concentrated; hunks are mostly i18n.

Grey Divider

Tip of the day
💡 Did you know, you can see how risky a PR is at a glance with blast radius labels

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@khaira777
khaira777 force-pushed the fm/flocafe-configurable-refund-policy branch from b347260 to 257bd57 Compare November 8, 2026 23:17
@khaira777 khaira777 changed the title feat(refunds): add configurable manager policy feat: add configurable manager refund policy and remove owner refund age limit Nov 8, 2026
@khaira777 khaira777 changed the title feat: add configurable manager refund policy and remove owner refund age limit feat(refunds): add configurable manager policy Nov 8, 2026
Add owner-controlled refund_manager_enabled and refund_manager_window settings (30m, 1h, 2h, 4h, same_business_day; default 1h) via /api/settings/refunds, remove the post-business-day 409 cutoff for Owner Staff Approval PIN refunds, and expose Refund Policy controls in POS Workflow settings and RefundModal.
Keep POS refund policy controls disabled until hydrated and ignore stale GET responses after local edits, gate refund policy controls on owner role plus settings.manage, and treat failed /settings/refunds reads in RefundModal as load errors while refreshing the policy alongside approvers before submission.
@khaira777
khaira777 force-pushed the fm/flocafe-configurable-refund-policy branch from 257bd57 to 4c5d81b Compare November 8, 2026 23:51
@khaira777 khaira777 changed the title feat(refunds): add configurable manager policy feat: add configurable manager refund policy and remove owner age cutoff Nov 8, 2026
@khaira777 khaira777 changed the title feat: add configurable manager refund policy and remove owner age cutoff feat(refunds): add configurable manager policy Nov 8, 2026
@khaira777
khaira777 merged commit 938e305 into main Nov 9, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-configurable-refund-policy branch November 9, 2026 03:21
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.

feat(refunds): configurable manager refund window and unlimited owner window

1 participant