Skip to main content

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

#TaskNotes
1.1Add flow agent_shop to cash_transactions
1.2Refactor creditDistributionBizService.distributeCreate cash_transaction; full new payload fields
1.3Cost rate snapshot = Shop buyerexpected = credits × shop.costRate
1.4Validate agent has sufficient creditInsufficient balance error
1.5Validate shop belongs to agentKeep shop.agentId check
1.6Record performed_by = agent user id
1.7Link cash_transaction ↔ wallet txs ↔ payment_transaction
1.8API POST /agent/shops/:id/cash-credits (or extend /credits/distribute)Shop id from URL — no shopId in body when opened from detail
1.9GET /agent/cash-transactions + GET /agent/cash-transactions/:idScope to logged-in agent
1.10Unit testsShop wrong agent, zero cost rate, balance

Phase 2 — Agent portal wire

UI from @kioskgaming/ui — do not duplicate components.

#TaskNotes
2.1Shop detail: SellCreditsCashModalflow=agent_shop, buyer = shop being viewed
2.2API hook + extend distributeCreditsReplace DistributeCreditsTrigger logic
2.3Route list/detail + menuPortalCashTransactionsLedger / Detail
2.4Submit → 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:

#TaskNotes
3.1Option A: Only Agent portal sells Agent→ShopRecommended
3.2Option B: SA portal proxies shop distributeNeeds PM confirm
3.3Option A: hide shop distribute on SA portalAvoid duplicate

Phase 4 — Admin visibility (optional V1)

#TaskNotes
4.1Admin list/detail Agent→Shop flowGeneric UI package

Phase 5 — QA

#TaskNotes
5.1Agent sells → Shop wallet +, Agent wallet −
5.2Shop USD wallet unchanged
5.3List/detail Agent portal