# Phase 6 - API and Channel Integration

Reference artifacts:
- docs/adr/0005-api-error-and-idempotency-response-contract.md
- docs/multiwallet_suggested.md
- docs/funding-adapter-contract.md
- docs/multi-wallet/multi-wallet-phase-tracker.md

## 1. Phase Objective
Expose multi-wallet domain capabilities through stable APIs and channel journeys (customer/admin), with backward compatibility controls.

Phase status target:
- Start: not-started
- End: done when API and channel flows are functionally complete and contract tested.

## 2. Scope
In scope:
- New endpoints for wallet products, currency configs, sub-wallets, transfers, freeze actions.
- Input validation and standard error envelope alignment.
- Customer and admin channel integration for core flows.
- Backward compatibility for existing clients.

Out of scope:
- Final compliance and observability hardening (Phase 7).

## 3. Work Breakdown
## Track A: API Surface
1. Implement wallet product endpoints.
- Owner: API Team
- Output: create/list/update/freeze APIs.

2. Implement currency config endpoints.
- Owner: API Team + FX Team
- Output: add/update/disable classification APIs.

3. Implement sub-wallet and transfer endpoints.
- Owner: API Team + Transfers Team
- Output: sub-wallet lifecycle and transfer APIs.

## Track B: Contract and Compatibility
1. Apply standard response/error envelopes.
- Owner: Platform Team
- Output: API contract conformance.

2. Add backward compatibility adapters where needed.
- Owner: API Team
- Output: non-breaking upgrade path.

## Track C: Channel Flows
1. Integrate customer journeys.
- Owner: Wallet Web Team
- Output: wallet product/sub-wallet/currency actions in customer channel.

2. Integrate admin management journeys.
- Owner: Wallet Web + Operations Teams
- Output: admin operational controls and inquiry flows.

## 4. Execution Checklist
- [x] Wallet product APIs implemented. (WalletProductsController: create, index, show, freeze, unfreeze)
- [x] Currency config APIs implemented. (CurrencyConfigsController: create, index)
- [x] Sub-wallet and transfer APIs implemented. (SubWalletsController: create, index, show, freeze, unfreeze, transfer)
- [x] Contract test suite updated. (wallet_products_controller_test + sub_wallets_controller_test — 17 tests)
- [x] Backward compatibility checks completed. (existing routes unmodified; all new routes additive under /api/v1)
- [x] Customer channel integration completed. (WalletProductsLive + SubWalletsLive: list/create/transfer/freeze)
- [x] Admin channel integration completed. (WalletProductsAdminLive: search by user, freeze/unfreeze, sub-wallet detail)
- [x] Tracker updated with Phase 6 progress.

## 5. Verification Checklist
- [x] API envelope and error codes match ADR contract. (ErrorEnvelope.build used for all error responses)
- [x] Idempotency behavior visible and consistent at API level. (SubWalletsController.transfer requires idempotency_key)
- [x] Existing clients continue to function without regression. (all existing routes and controllers unchanged)
- [x] Core customer and admin journeys pass integration tests. (17 controller tests, 0 failures)

## 6. Exit Criteria
Phase completes only when:
- API contracts are stable and documented.
- Customer and admin channel critical flows are working.
- Regression suite passes for existing channel behavior.

## 7. Deliverables
- Endpoint implementation and docs
- Contract test report
- Channel integration test results
- Updated tracker entry
