Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

The Stars were charged and on_paid never ran: where Telegram Stars payments get lost in aiogram

说明与用途

aiogram-stars 库处理 Telegram Stars 支付,但由于 asyncio 超时处理、路由器顺序和调度器关闭等错误,on_paid 处理程序未运行,导致支付丢失。修复九个错误后,库现在可靠地处理支付,创建数据库记录并正确处理退款。

问题

Telegram Stars payments are accepted but the bot’s on_paid handler never runs, causing lost payments and no database record.

结果

After identifying nine bugs, the library now reliably processes Stars payments, ensuring on_paid runs, database rows are created, and refunds are handled correctly.

工作流

  • 1. Buyer initiates a Stars payment, triggering a pre_checkout_query update.
  • 2. Bot answers the pre_checkout_query within a 10‑second deadline using asyncio.wait_for to enforce a timeout.
  • 3. If the check function succeeds, Telegram sends a successful_payment update.
  • 4. The on_paid handler is invoked to deliver goods and record the transaction.
  • 5. If any step fails (timeout, router conflict, dispatcher shutdown, or refund queue flood), the payment is lost or refunded.

证据

A buyer pays 100 Stars, Telegram takes them, and the bot replies to the payment message with "Sorry, I don't know this command".

来源

That bug never made it into a release. Before I published the first version, I went through it again with one question: where can a payment get lost here? I found nine bugs.

来源

The library does the rest. The invoice payload carries an HMAC over the order id and the amount, so a payload made elsewhere or paid with another amount is declined before check runs.

来源

The first version did this with asyncio.wait_for... If check holds a database connection and rolls back in finally on that same hung connection, wait_for waits for the rollback too.

来源

  • 记录日期: 2026-10-18T12:40:59.317Z