Contexts
Every handler receives a context object as its first argument — ctx. The context contains all the data sent by Payme for that specific method.
CheckPerformTransactionCtx
ctx.amount # int — amount in tiyin
ctx.account # Account — parsed account object
ctx.account.order_id # any field you defined in your account
CreateTransactionCtx
ctx.payme_id # str — unique transaction ID from Payme
ctx.time # int — transaction creation time (unix ms)
ctx.amount # int — amount in tiyin
ctx.account # Account — parsed account object
PerformTransactionCtx
CancelTransactionCtx
Cancellation reason codes:
| Code | Description |
|---|---|
| 1 | Receiver not found |
| 2 | Transaction not settled |
| 3 | Transaction already cancelled |
| 4 | Bad debt |
| 5 | Other |
CheckTransactionCtx
GetStatementCtx
ctx.ok()
Every handler must return ctx.ok(...) with the appropriate fields. aiopayme builds the correct Payme response automatically.
# CheckPerformTransaction
return ctx.ok(allow=True)
# CreateTransaction
return ctx.ok(
transaction_id=tx.payme_id,
create_time=tx.create_time,
)
# PerformTransaction
return ctx.ok(
transaction_id=tx.payme_id,
perform_time=tx.perform_time,
state=2,
)
# CancelTransaction
return ctx.ok(
transaction=tx.payme_id,
state=tx.state,
cancel_time=tx.cancel_time,
reason=tx.reason,
)
# CheckTransaction
return ctx.ok(
state=tx.state,
create_time=tx.create_time,
perform_time=tx.perform_time,
cancel_time=tx.cancel_time,
reason=tx.reason,
)