Quick Start
This guide walks you through a minimal Payme integration using aiopayme with FastAPI and aiogram.
Setup
Initialize the Payme instance and create a Dispatcher:
from aiopayme import Payme, Dispatcher
payme = Payme(
merchant_id="your_merchant_id",
secret_key="your_secret_key",
sandbox=True,
)
dp = Dispatcher()
Define a Router
from aiopayme import Router
from aiopayme.types import (
CheckPerformTransactionCtx,
CreateTransactionCtx,
PerformTransactionCtx,
CancelTransactionCtx,
CheckTransactionCtx,
GetStatementCtx,
)
router = Router()
@router.check_perform_transaction()
async def check_perform(ctx: CheckPerformTransactionCtx):
...
@router.create_transaction()
async def create_transaction(ctx: CreateTransactionCtx):
...
@router.perform_transaction()
async def perform_transaction(ctx: PerformTransactionCtx):
...
@router.cancel_transaction()
async def cancel_transaction(ctx: CancelTransactionCtx):
...
@router.check_transaction()
async def check_transaction(ctx: CheckTransactionCtx):
...
@router.get_statement()
async def get_statement(ctx: GetStatementCtx):
...
Mount to FastAPI
from fastapi import FastAPI, Request
from example.deps import get_payme
app = FastAPI()
dp.include_router(router)
payme.setup(dp)
@app.post("/payme")
async def payme_webhook(request: Request):
return await get_payme().handle(
data=await request.json(),
headers=dict(request.headers),
)
Payme sends all requests to a single endpoint — POST /payme. The handle method authenticates the request and routes it to the correct handler.
Generate a Pay Link
That's it! For a full working example see the example project.