Dispatcher & Router
The architecture of aiopayme is inspired by aiogram — it uses a Dispatcher and Router pattern that should feel familiar to anyone who has worked with aiogram or FastAPI.
Dispatcher
Dispatcher is the core of aiopayme. It receives incoming requests from Payme, authenticates them, and routes them to the correct handler.
from aiopayme import Payme, Dispatcher
payme = Payme(
merchant_id="your_merchant_id",
secret_key="your_secret_key",
sandbox=True,
)
dp = Dispatcher()
payme.setup(dp)
Router
Router is used to define handlers for each Payme method. You can have multiple routers and include them into the Dispatcher — just like in aiogram.
Multiple Routers
You can include multiple routers at once using include_routers:
from aiopayme import Router
orders_router = Router()
transactions_router = Router()
# one by one
dp.include_router(orders_router)
dp.include_router(transactions_router)
# or all at once
dp.include_routers(orders_router, transactions_router)
Handler Registration
Each Payme method has a corresponding decorator on the Router:
| Method | Decorator |
|---|---|
CheckPerformTransaction |
@router.check_perform_transaction() |
CreateTransaction |
@router.create_transaction() |
PerformTransaction |
@router.perform_transaction() |
CancelTransaction |
@router.cancel_transaction() |
CheckTransaction |
@router.check_transaction() |
GetStatement |
@router.get_statement() |