Invoice polling

Polling is a method of receiving updates by periodically sending requests. Once invoice status is changed to PAID, polling manager will call the invoice_paid handler. Invoice polling uses the /getInvoices method.

Attention

Polling manager has configuration that defines the delay (between requests) and timeout for each invoice in the awaiting queue. After the timeout polling manager will stop polling that invoice and call the invoice_expired handler if it is declared.

Default is 2 seconds delay and 300 seconds (5 min) timeout.

You can change the polling configuration.

Usage example

import asyncio
from aiosend import CryptoPay
from aiosend.types import Invoice

cp = CryptoPay("TOKEN")

@cp.invoice_paid()
async def payment_handler(invoice: Invoice, payload: str) -> None:
    print("Received", invoice.amount, invoice.asset, payload)

@cp.invoice_expired()
async def expired_invoice_handler(invoice: Invoice, payload: str) -> None:
    print("Expired invoice", invoice.invoice_id, payload)

async def main() -> None:
    invoice = await cp.create_invoice(1, "USDT")
    print("invoice link:", invoice.bot_invoice_url)
    invoice.poll(payload="payload")
    await cp.start_polling()

if __name__ == "__main__":
    asyncio.run(main())