Routers¶
Router is an object for routing updates. There are two types of routers:
PollingRouter and
WebhookRouter.
CryptoPay is the root router for both of them.
One router can include another router, but in the end,
the parent router must be included in the root router via
include_router or
include_routers methods.
Usage example
from aiosend import PollingRouter
from aiosend.types import Invoice
router = PollingRouter(name=__name__)
@router.invoice_paid()
def invoice_paid(invoice: Invoice) -> None:
print(f"invoice_paid: {invoice.invoice_id}")
- class aiosend._events.BaseRouter(*, name=None)¶
Base router for handling and propagate events.
- include_router(router)¶
Include another router to this one.
- Return type:
None
- include_routers(*routers)¶
Include multiple routers to this one.
- Return type:
None
- class aiosend.polling.PollingRouter(*, name=None)¶
Bases:
BaseRouterRouter for polling events.
- class aiosend.webhook.WebhookRouter(*, name=None)¶
Bases:
BaseRouterRouter for webhook updates.
Event observers¶
Event observer is an object that stores event handlers.
You can attach a new event handler to event observer using a
@router.<event type>(...) decorator or a router.<event type>.register(...) method.
- class aiosend._events.EventObserver¶
Event observer for storing handlers and propagating events.
- register(handler, *filters)¶
Register event handler.
- Return type:
None
- async trigger(event, **kwargs)¶
Trigger event observer.
- Return type:
bool
Polling Router¶
Available observers for PollingRouter are listed here.
Paid invoice¶
@router.invoice_paid()
def invoice_paid(invoice: Invoice) -> None: ...
Expired invoice¶
@router.invoice_expired()
def invoice_expired(invoice: Invoice) -> None: ...
Activated check¶
@router.check_activated()
def check_activated(check: Check) -> None: ...
Expired check¶
@router.check_expired()
def check_expired(check: Check) -> None: ...
Webhook Router¶
Available observers for WebhookRouter are listed here.
Paid invoice¶
@router.invoice_paid()
def invoice_paid(invoice: Invoice) -> None: ...