[Python] Aiogram: why does @router.message(F.successful_payment) not fire after Telegram test...

Discussão em 'Python' iniciado por Stack, Agosto 20, 2025.

  1. Stack

    Stack Membro Participativo

    I’m testing Telegram Payments in a bot built with Aiogram 3.x.
    Environment: Python 3.11, Aiogram 3.4, provider = Smart Glocal TEST token from BotFather.

    The invoice shows and the test payment completes (Telegram confirms payment), but the successful_payment handler never fires.

    from aiogram import Router, F
    from aiogram.types import Message, LabeledPrice, PreCheckoutQuery

    router = Router()

    @router.callback_query(F.data == "buy")
    async def subscribe(callback):
    price = [LabeledPrice(label="Test", amount=1000)]
    await callback.message.answer_invoice(
    title="Test Sub",
    description="Test invoice",
    payload="test_payload",
    provider_token="TEST:xxx",
    currency="USD",
    prices=price
    )

    @router.pre_checkout_query()
    async def pre_checkout(pre_checkout_query: PreCheckoutQuery):
    await pre_checkout_query.answer(ok=True)

    @router.message(F.successful_payment)
    async def success(message: Message):
    print("Payment successful")
    await message.answer("✅ Paid!")

    What I expect:


    After test payment, the success handler should run.

    What happens instead:
    Telegram shows “Payment successful”, but the handler is never called and nothing is printed.

    What I’ve tried:


    • Smart Glocal & Stripe TEST tokens from BotFather


    • USD and INR currencies


    • Pre-checkout handler works fine


    • Production token not tested (only test mode)

    Question:
    Is this a limitation of Telegram’s test mode, or is my Aiogram code incorrect?
    How can I properly test the F.successful_payment handler?

    Continue reading...

Compartilhe esta Página