Skip to main content

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

#TaskNotes
1.1Add flow super_agent_agent to cash_transactionsReuse model from Admin→SA flow
1.2Refactor superAgentCreditDistributionBizService.distributeCreate cash_transaction; payload: credits, cash_received, payment_method, received_at, external_ref?, note?
1.3Cost rate snapshot = Agent buyerexpected = credits × agent.costRate
1.4Validate SA has sufficient credit before transferClear error if insufficient balance
1.5Validate agent belongs to SA + agent not terminatedKeep assertManagedAgent
1.6Record performed_by = super agent user id
1.7Link cash_transaction ↔ wallet debit/credit tx ↔ payment_transaction
1.8API POST /super-agent/agents/:id/cash-credits (or extend /credits/distribute)Breaking change: need versioned body or new fields
1.9Extend GET /super-agent/cash-transactionsFilter flow=SA→Agent; scope to logged-in SA
1.10GET /super-agent/cash-transactions/:idView-only detail
1.11Unit testsInsufficient SA balance, wrong agent, snapshot rate

Phase 2 — Super Agent portal wire

UI: SellCreditsCashModal, PortalCashTransactionsLedger, PortalCashTransactionDetail from @kioskgaming/ui.

#TaskNotes
2.1Agent detail: SellCreditsCashModalflow=super_agent_agent, buyer = agent being viewed
2.2API hook + distributeCreditsToManagedAgent → new payloadReplace SuperAgentAgentCreditTrigger logic
2.3Route list/detail + Cash Transactions menuCompose package components
2.4Submit → refresh agent + SA wallet balance

Reference: SuperAgentAgentCreditTrigger.tsx


Phase 3 — Admin visibility (optional V1)

#TaskNotes
3.1Admin list shows SA→Agent flowFilter flow on Admin ledger (already generic)
3.2Admin detail views SA→Agent transactionsSame PortalCashTransactionDetail

Phase 4 — QA

#TaskNotes
4.1SA sells credit → Agent wallet +, SA wallet −
4.2Agent USD wallet does not increaseRegression
4.3List/detail SA portal + Admin
4.4Update spec if needed