# Send Money Expansion Tracker

## Scope

This tracker covers the requested Send Money expansion:

- Wallet to Wallet (P2P) with recipient lookup by phone, email, and user ID.
- Wallet to Account (P2A).
- Wallet to Merchant (P2M), aligned to wallet-to-wallet style UX.
- Source funding selection with wallet-first behavior and payment-gateway fallback when balance is insufficient.

## Current Baseline

- Existing customer transfer flow supports account ID, phone lookup, and QR parsing.
- P2A domain command exists (`InitiateP2aTransfer`) but is not yet wired in customer UI.
- Transfer domain supports transfer type metadata (`:internal | :p2p | :external`).

## Delivery Plan

| Phase | Focus | Status | Notes |
|---|---|---|---|
| 1 | Tracker + foundation | In progress | This document and first code slice |
| 2 | Recipient lookup expansion | In progress | Add email and user ID resolution paths |
| 3 | Flow segmentation (P2P/P2A/P2M) | In progress | Add flow selection in `TransferLive` |
| 4 | Funding source model | Planned | Wallet only vs wallet+PG fallback policy |
| 5 | Dedicated P2A wiring | In progress | `TransferLive` now routes P2A through `InitiateP2aTransfer` with injectable adapters |
| 7 | Dedicated P2M wiring | In progress | `TransferLive` now routes P2M through transfer + `WalletIntegrations.Commands.InitiatePayment` hook |
| 6 | Validation + tests | Planned | Add/extend transfer and LiveView tests |

## Phase 1-3 Implementation Checklist

- [x] Create Send Money tracker document.
- [ ] Extend transfer target resolver for email and user ID.
- [ ] Add UI target modes for email and user ID.
- [ ] Add transfer flow selector: P2P, P2A, P2M.
- [ ] Map flow to transfer type metadata at submit time.
- [x] Add/adjust unit and LiveView tests for new paths.

## Phase 5 Progress Notes

- `TransferLive` now uses dedicated P2A execution when flow is `p2a`.
- Default runtime adapters:
	- Ledger debiter: `WalletLedger.Commands.AuthorizeDebit.execute/5`
	- Provider submitter: configurable function with safe default mock reference generation.
- Dependency injection hooks added for test/runtime override via app env:
	- `:p2a_transfer_executor`
	- `:p2a_ledger_debiter`
	- `:p2a_provider_submitter`

## Phase 7 Progress Notes

- P2M flow now uses integration command boundary from `wallet_integrations` README:
	- `WalletIntegrations.Commands.InitiatePayment.execute/5`
- Current sequence for P2M:
	1. Initiate internal transfer record in `wallet_transfers`.
	2. Trigger integration payment request for provider dispatch.
- Runtime hook available for override/testing:
	- `:p2m_payment_initiator`

## Funding Source Strategy (Planned)

- Default strategy: `wallet_first`.
- Optional strategy: `wallet_then_pg`.
- First implementation in this phase will carry funding source as transfer metadata.
- Later phase will enforce balance checks and trigger PG collection orchestration.

## Open Decisions

- P2A destination canonical input for MVP: `account_id` vs `iban` vs both.
- P2M merchant resolution source of truth: merchant user profile vs merchant directory API.
- PG fallback trigger policy: full top-up vs partial top-up.

## Change Log

- 2026-04-03: Tracker created; first implementation slice started.
