Tasks — Agent → Shop
Spec: agent-to-shop · Mockup: sell-credit (modal), list, detail
Current status: creditDistributionBizService.distribute exists (debit agent, credit shop, PaymentTransaction provider agent_cash). UI: DistributeCreditsTrigger on Agent portal and Super Agent portal (amount only + shop select on SA portal). Does not write cash_transactions, form incomplete.
Dependencies: Backend Phase 1 from tasks Admin → SA + UI package UI.1–UI.7.
V1 scope: Modal from Shop detail (Agent portal). Status paid_full only. Detail view-only.
Shared UI: ui-package-cash-settlement — Agent portal only wires API.
Phase 1 — Backend
| # | Task | Notes |
|---|---|---|
| 1.1 | Add flow agent_shop to cash_transactions | |
| 1.2 | Refactor creditDistributionBizService.distribute | Create cash_transaction; full new payload fields |
| 1.3 | Cost rate snapshot = Shop buyer | expected = credits × shop.costRate |
| 1.4 | Validate agent has sufficient credit | Insufficient balance error |
| 1.5 | Validate shop belongs to agent | Keep shop.agentId check |
| 1.6 | Record performed_by = agent user id | |
| 1.7 | Link cash_transaction ↔ wallet txs ↔ payment_transaction | |
| 1.8 | API POST /agent/shops/:id/cash-credits (or extend /credits/distribute) | Shop id from URL — no shopId in body when opened from detail |
| 1.9 | GET /agent/cash-transactions + GET /agent/cash-transactions/:id | Scope to logged-in agent |
| 1.10 | Unit tests | Shop wrong agent, zero cost rate, balance |
Phase 2 — Agent portal wire
UI from
@kioskgaming/ui— do not duplicate components.
| # | Task | Notes |
|---|---|---|
| 2.1 | Shop detail: SellCreditsCashModal | flow=agent_shop, buyer = shop being viewed |
| 2.2 | API hook + extend distributeCredits | Replace DistributeCreditsTrigger logic |
| 2.3 | Route list/detail + menu | PortalCashTransactionsLedger / Detail |
| 2.4 | Submit → refresh shop + agent wallet |
Reference: kioskgaming_agent/.../DistributeCreditsTrigger.tsx
Phase 3 — Super Agent portal (distribution path)
Super Agent portal also has DistributeCreditsTrigger (select shop + amount) — V1 decision:
| # | Task | Notes |
|---|---|---|
| 3.1 | Option A: Only Agent portal sells Agent→Shop | Recommended |
| 3.2 | Option B: SA portal proxies shop distribute | Needs PM confirm |
| 3.3 | Option A: hide shop distribute on SA portal | Avoid duplicate |
Phase 4 — Admin visibility (optional V1)
| # | Task | Notes |
|---|---|---|
| 4.1 | Admin list/detail Agent→Shop flow | Generic UI package |
Phase 5 — QA
| # | Task | Notes |
|---|---|---|
| 5.1 | Agent sells → Shop wallet +, Agent wallet − | |
| 5.2 | Shop USD wallet unchanged | |
| 5.3 | List/detail Agent portal |
Related
- Previous: Tasks Super Agent → Agent
- Foundation: Tasks Admin → SA