Tasks — Super Agent → Agent
Spec: superagent-to-agent · Mockup: sell-credit (modal), list, detail
Current status: superAgentCreditDistributionBizService.distribute exists (debit SA wallet, credit agent, PaymentTransaction provider super_agent_cash). UI: SuperAgentAgentCreditTrigger on Super Agent portal (amount only). 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 Agent detail (Super Agent portal). Status paid_full only. Detail view-only.
Shared UI: ui-package-cash-settlement — Super Agent portal only wires API.
Phase 1 — Backend
| # | Task | Notes |
|---|---|---|
| 1.1 | Add flow super_agent_agent to cash_transactions | Reuse model from Admin→SA flow |
| 1.2 | Refactor superAgentCreditDistributionBizService.distribute | Create cash_transaction; payload: credits, cash_received, payment_method, received_at, external_ref?, note? |
| 1.3 | Cost rate snapshot = Agent buyer | expected = credits × agent.costRate |
| 1.4 | Validate SA has sufficient credit before transfer | Clear error if insufficient balance |
| 1.5 | Validate agent belongs to SA + agent not terminated | Keep assertManagedAgent |
| 1.6 | Record performed_by = super agent user id | |
| 1.7 | Link cash_transaction ↔ wallet debit/credit tx ↔ payment_transaction | |
| 1.8 | API POST /super-agent/agents/:id/cash-credits (or extend /credits/distribute) | Breaking change: need versioned body or new fields |
| 1.9 | Extend GET /super-agent/cash-transactions | Filter flow=SA→Agent; scope to logged-in SA |
| 1.10 | GET /super-agent/cash-transactions/:id | View-only detail |
| 1.11 | Unit tests | Insufficient SA balance, wrong agent, snapshot rate |
Phase 2 — Super Agent portal wire
UI:
SellCreditsCashModal,PortalCashTransactionsLedger,PortalCashTransactionDetailfrom@kioskgaming/ui.
| # | Task | Notes |
|---|---|---|
| 2.1 | Agent detail: SellCreditsCashModal | flow=super_agent_agent, buyer = agent being viewed |
| 2.2 | API hook + distributeCreditsToManagedAgent → new payload | Replace SuperAgentAgentCreditTrigger logic |
| 2.3 | Route list/detail + Cash Transactions menu | Compose package components |
| 2.4 | Submit → refresh agent + SA wallet balance |
Reference: SuperAgentAgentCreditTrigger.tsx
Phase 3 — Admin visibility (optional V1)
| # | Task | Notes |
|---|---|---|
| 3.1 | Admin list shows SA→Agent flow | Filter flow on Admin ledger (already generic) |
| 3.2 | Admin detail views SA→Agent transactions | Same PortalCashTransactionDetail |
Phase 4 — QA
| # | Task | Notes |
|---|---|---|
| 4.1 | SA sells credit → Agent wallet +, SA wallet − | |
| 4.2 | Agent USD wallet does not increase | Regression |
| 4.3 | List/detail SA portal + Admin | |
| 4.4 | Update spec if needed |
Related
- Previous: Tasks Admin → SA
- Next: Tasks Agent → Shop