# Torbat Pay — Enterprise Payment Platform

Independent, tenant-isolated payment microservice (**Torbat Pay**) implementing phases **14.0–14.5** (MVP).

| Field | Value |
| --- | --- |
| Service | `payment-service` |
| Version | **0.14.5.0** |
| Port | **8012** |
| Database | `payment_db` |
| API prefix | `/api/v1` |
| OpenAPI | `/docs` (FastAPI auto-generated) |

## Capabilities (14.5)

- Foundation: workspaces, L2 bundles, L3 toggles, provider assignments, audit, outbox
- BYO-PSP: connections, routing, mock adapter + health test
- Torbat Pay Merchant: merchant account lifecycle
- Payment requests: idempotency, mock redirect, credit ref fields (nullable)
- Callbacks: signature verify, replay protection, verify API
- Ledger: immutable transactions + append-only ledger entries

## Reserved (not implemented)

- `CREDIT_PROVIDER` payment source → Torbat Credit (422 until bundle + service exist)
- Refunds, splits, connectors, reconciliation (phases 14.6+)

## Local development

```bash
cd backend/services/payment
pip install -e ../../shared-lib
pip install -r requirements.txt
pytest app/tests -q
```

## Migrations

Alembic head: `0006_phase_145_ledger`

```bash
python scripts/ensure_db.py && alembic upgrade head
```

## Documentation

- [payment-roadmap.md](../../docs/payment-roadmap.md)
- [payment-contracts.md](../../docs/reference/payment-contracts.md)
- [phase-14-5 handover](../../docs/phase-handover/phase-14-5.md)
