# techhaha/mpay_v2 architecture

> Architecture diagram of the GitHub repository techhaha/mpay_v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/techhaha/mpay_v2
- Repository: https://github.com/techhaha/mpay_v2

## Overview

MPAY V2 is a multi-merchant payment platform. A business system submits a payment through the ePay or cashier APIs; the backend creates and routes payment orders to configured channels and plugins, then handles callbacks or queries, merchant notification, and—where applicable—settlement and account posting. Separate branches cover merchant/admin operations, refunds and transfers, receipt-watcher notifications, files, and recovery. The README documents these capabilities and the principal flow; sampled source confirms selected query, account, and storage behavior, but does not expose every runtime call path.

Main entry points: [`app/http/admin/controller`](https://github.com/techhaha/mpay_v2/tree/master/app/http/admin/controller) (Admin API), [`app/service/payment/order/PayOrderService.php`](https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/order/PayOrderService.php) (Order Runtime), [`app/service/payment/order/PayOrderCallbackService.php`](https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/order/PayOrderCallbackService.php) (Callback Lifecycle), [`app/http/mer/controller`](https://github.com/techhaha/mpay_v2/tree/master/app/http/mer/controller) (Merchant Portal)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API and Portals"]
  node_payment_api["Payment APIs"]
  node_cashier["Cashier API"]
  node_admin["Admin API"]
  node_merchant_portal["Merchant Portal"]
end

subgraph group_payment["Payment Runtime"]
  node_order_service["Order Runtime"]
  node_routing["Channel Routing"]
  node_plugins["Payment Plugins"]
  node_epay["ePay Protocols"]
  node_callback["Callback Lifecycle"]
end

subgraph group_money["Funds and Orders"]
  node_orders[("Order Records")]
  node_refunds["Refund Processing"]
  node_settlement["Settlement"]
  node_accounts["Merchant Accounts"]
end

subgraph group_async["Async Operations"]
  node_notify["Merchant Notifications"]
  node_queues["Redis Queue"]
  node_receipt["Receipt Watcher"]
end

subgraph group_platform["Platform Services"]
  node_merchant["Merchant Records"]
  node_channel_config["Channel Configuration"]
  node_files["File Assets"]
  node_storage["Storage Drivers<br/>[StorageManager.php]"]
end

node_business(("Business System"))
node_admin_user(("Platform Operator"))
node_merchant_user(("Merchant User"))
node_provider(("Payment Providers"))
node_storage_services(("Object Storage"))

node_business -->|"submits payment"| node_payment_api
node_payment_api -->|"handles protocol"| node_epay
node_epay -->|"creates orders"| node_order_service
node_merchant_user -->|"uses cashier"| node_cashier
node_cashier -->|"confirms payment"| node_order_service
node_order_service -->|"persists orders"| node_orders
node_order_service -->|"dispatches payment"| node_routing
node_routing -->|"resolves channels"| node_channel_config
node_routing -->|"invokes plugin"| node_plugins
node_plugins -->|"requests payment"| node_provider
node_provider -.->|"sends callback"| node_callback
node_order_service -->|"handles status"| node_callback
node_callback -->|"updates orders"| node_orders
node_callback -->|"queues notification"| node_queues
node_queues -->|"dispatches job"| node_notify
node_callback -->|"triggers settlement"| node_settlement
node_settlement -->|"posts funds"| node_accounts
node_admin_user -->|"manages platform"| node_admin
node_admin -->|"manages merchants"| node_merchant
node_admin -->|"configures channels"| node_channel_config
node_merchant_user -->|"manages account"| node_merchant_portal
node_merchant_portal -->|"reads merchant data"| node_merchant
node_merchant_portal -->|"views funds"| node_accounts
node_admin -->|"manages refunds"| node_refunds
node_merchant_portal -->|"requests refunds"| node_refunds
node_refunds -->|"queues dispatch"| node_queues
node_admin -->|"views settlement"| node_settlement
node_admin -->|"manages files"| node_files
node_files -->|"stores and retrieves"| node_storage
node_storage -.->|"uses remote storage"| node_storage_services
node_receipt -->|"queues receipt events"| node_queues

click node_payment_api "https://github.com/techhaha/mpay_v2/blob/master/app/http/api/controller/epay/EpayV2Controller.php"
click node_cashier "https://github.com/techhaha/mpay_v2/blob/master/app/http/api/controller/cashier/CashierController.php"
click node_admin "https://github.com/techhaha/mpay_v2/tree/master/app/http/admin/controller"
click node_merchant_portal "https://github.com/techhaha/mpay_v2/tree/master/app/http/mer/controller"
click node_order_service "https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/order/PayOrderService.php"
click node_routing "https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/order/PayOrderChannelDispatchService.php"
click node_plugins "https://github.com/techhaha/mpay_v2/tree/master/app/common/payment"
click node_epay "https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/epay/EpayV2ProtocolService.php"
click node_callback "https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/order/PayOrderCallbackService.php"
click node_orders "https://github.com/techhaha/mpay_v2/blob/master/app/repository/payment/trade/PayOrderRepository.php"
click node_refunds "https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/order/RefundDispatchService.php"
click node_settlement "https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/settlement/SettlementOrderQueryService.php"
click node_accounts "https://github.com/techhaha/mpay_v2/blob/master/app/service/account/funds/MerchantAccountCommandService.php"
click node_notify "https://github.com/techhaha/mpay_v2/blob/master/app/queue/job/MerchantNotifyJob.php"
click node_queues "https://github.com/techhaha/mpay_v2/tree/master/app/queue/redis"
click node_receipt "https://github.com/techhaha/mpay_v2/blob/master/app/process/ReceiptWatcherProcess.php"
click node_merchant "https://github.com/techhaha/mpay_v2/blob/master/app/service/merchant/MerchantQueryService.php"
click node_channel_config "https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/config/PaymentChannelQueryService.php"
click node_files "https://github.com/techhaha/mpay_v2/blob/master/app/service/file/FileRecordService.php"
click node_storage "https://github.com/techhaha/mpay_v2/blob/master/app/service/file/storage/StorageManager.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_payment_api,node_cashier,node_admin,node_merchant_portal,node_merchant_user toneBlue
class node_order_service,node_routing,node_plugins,node_epay,node_callback,node_storage_services toneAmber
class node_orders,node_refunds,node_settlement,node_accounts toneMint
class node_notify,node_queues,node_receipt toneRose
class node_merchant,node_channel_config,node_files,node_storage,node_business,node_admin_user,node_provider toneIndigo
```

## Components

### API and Portals

- [Payment APIs](https://github.com/techhaha/mpay_v2/blob/master/app/http/api/controller/epay/EpayV2Controller.php): `app/http/api/controller/epay/EpayV2Controller.php`
- [Cashier API](https://github.com/techhaha/mpay_v2/blob/master/app/http/api/controller/cashier/CashierController.php): `app/http/api/controller/cashier/CashierController.php`
- [Admin API](https://github.com/techhaha/mpay_v2/tree/master/app/http/admin/controller): `app/http/admin/controller`
- [Merchant Portal](https://github.com/techhaha/mpay_v2/tree/master/app/http/mer/controller): `app/http/mer/controller`

### Payment Runtime

- [Order Runtime](https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/order/PayOrderService.php): `app/service/payment/order/PayOrderService.php`
- [Channel Routing](https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/order/PayOrderChannelDispatchService.php): `app/service/payment/order/PayOrderChannelDispatchService.php`
- [Payment Plugins](https://github.com/techhaha/mpay_v2/tree/master/app/common/payment): `app/common/payment`
- [ePay Protocols](https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/epay/EpayV2ProtocolService.php): `app/service/payment/epay/EpayV2ProtocolService.php`
- [Callback Lifecycle](https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/order/PayOrderCallbackService.php): `app/service/payment/order/PayOrderCallbackService.php`

### Funds and Orders

- [Order Records](https://github.com/techhaha/mpay_v2/blob/master/app/repository/payment/trade/PayOrderRepository.php): `app/repository/payment/trade/PayOrderRepository.php`
- [Refund Processing](https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/order/RefundDispatchService.php): `app/service/payment/order/RefundDispatchService.php`
- [Settlement](https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/settlement/SettlementOrderQueryService.php): `app/service/payment/settlement/SettlementOrderQueryService.php`
- [Merchant Accounts](https://github.com/techhaha/mpay_v2/blob/master/app/service/account/funds/MerchantAccountCommandService.php): `app/service/account/funds/MerchantAccountCommandService.php`

### Async Operations

- [Merchant Notifications](https://github.com/techhaha/mpay_v2/blob/master/app/queue/job/MerchantNotifyJob.php): `app/queue/job/MerchantNotifyJob.php`
- [Redis Queue](https://github.com/techhaha/mpay_v2/tree/master/app/queue/redis): `app/queue/redis`
- [Receipt Watcher](https://github.com/techhaha/mpay_v2/blob/master/app/process/ReceiptWatcherProcess.php): `app/process/ReceiptWatcherProcess.php`

### Platform Services

- [Merchant Records](https://github.com/techhaha/mpay_v2/blob/master/app/service/merchant/MerchantQueryService.php): `app/service/merchant/MerchantQueryService.php`
- [Channel Configuration](https://github.com/techhaha/mpay_v2/blob/master/app/service/payment/config/PaymentChannelQueryService.php): `app/service/payment/config/PaymentChannelQueryService.php`
- [File Assets](https://github.com/techhaha/mpay_v2/blob/master/app/service/file/FileRecordService.php): `app/service/file/FileRecordService.php`
- [Storage Drivers](https://github.com/techhaha/mpay_v2/blob/master/app/service/file/storage/StorageManager.php): `app/service/file/storage/StorageManager.php`

### Other components

- **Business System**
- **Platform Operator**
- **Merchant User**
- **Payment Providers**
- **Object Storage**

## Connections

- Business System → Payment APIs: submits payment
- Payment APIs → ePay Protocols: handles protocol
- ePay Protocols → Order Runtime: creates orders
- Merchant User → Cashier API: uses cashier
- Cashier API → Order Runtime: confirms payment
- Order Runtime → Order Records: persists orders
- Order Runtime → Channel Routing: dispatches payment
- Channel Routing → Channel Configuration: resolves channels
- Channel Routing → Payment Plugins: invokes plugin
- Payment Plugins → Payment Providers: requests payment
- Payment Providers → Callback Lifecycle: sends callback
- Order Runtime → Callback Lifecycle: handles status
- Callback Lifecycle → Order Records: updates orders
- Callback Lifecycle → Redis Queue: queues notification
- Redis Queue → Merchant Notifications: dispatches job
- Callback Lifecycle → Settlement: triggers settlement
- Settlement → Merchant Accounts: posts funds
- Platform Operator → Admin API: manages platform
- Admin API → Merchant Records: manages merchants
- Admin API → Channel Configuration: configures channels
- Merchant User → Merchant Portal: manages account
- Merchant Portal → Merchant Records: reads merchant data
- Merchant Portal → Merchant Accounts: views funds
- Admin API → Refund Processing: manages refunds
- Merchant Portal → Refund Processing: requests refunds
- Refund Processing → Redis Queue: queues dispatch
- Admin API → Settlement: views settlement
- Admin API → File Assets: manages files
- File Assets → Storage Drivers: stores and retrieves
- Storage Drivers → Object Storage: uses remote storage
- Receipt Watcher → Redis Queue: queues receipt events
