(Python 3.11, Aiogram 3.3.0)
I want to add a subscription payment to the bot… I looked at a few examples and documentation, I don’t see any errors.
When I write to the bot /payment, I only get a message, but on send_invoice() there is complete silence, no errors or payments…
/
|- handlers
| |- bot_message.py
|- main.py
# bot_messages.py
from aiogram import Router,F,Bot
from aiogram.types import (
Message,
ContentType,
LabeledPrice,
PreCheckoutQuery
)
from aiogram.filters import (
Command
)
@router.message(Command(commands="payment"))
async def pay(message:Message,bot=Bot):
print("pay send")
await bot.send_message(message.chat.id,f"Your order payment") # get only this message
await bot.send_invoice(
chat_id= message.chat.id,
title="title",
description="desc_test",
payload=f'test-invoice-payload',
provider_token='TEST_TOKEN',
currency='USD',
prices=[
LabeledPrice(
label='Sub month',
amount=299*100
)
],
max_tip_amount=100*100,
suggested_tip_amounts=[100*100,300*100],
start_parameter=f'testpaymentbot',
provider_data=None,
need_email=True,
need_phone_number=True,
need_name=True,
need_shipping_address=False,
send_phone_number_to_provider=False,
send_email_to_provider=False,
is_flexible=False,
disable_notification=False,
protect_content=True,
reply_to_message_id=None,
allow_sending_without_reply=True,
reply_markup=None,
request_timeout=30
)
@router.pre_checkout_query()
async def process_pre_checkout_query(pre_checkout_query: PreCheckoutQuery, bot: Bot):
if pre_checkout_query.invoice_payload != "test_payload":
await bot.answer_pre_checkout_query(pre_checkout_query.id, ok=False, error_message="errors gere...")
else:
await bot.answer_pre_checkout_query(pre_checkout_query.id, ok=True)
@router.message(F.content_type == ContentType.SUCCESSFUL_PAYMENT)
async def succesfull_payment(message: Message):
print("succesfull_payment activate")
msg = f"Thank you for sub {message.successful_payment.total_amount // 100} {message.successful_payment.currency}!"
await message.answer(msg)
# main.py
from handlers import bot_messages
async def main() -> None:
try:
bot = Bot(token=f"{conf.bot_token}",parse_mode="HTML")
dp = Dispatcher()
dp.include_routers(
bot_messages.router
)
logger_bot.info("Bot initialization succesful!")
except (Exception,AiogramError) as _ex:
logger_bot.critical(f"Can't initilize bot! Error: {_ex}")
try:
await bot.delete_webhook(drop_pending_updates=True)
logger_bot.info(f"Bot start succesful! {bot.id}|{bot.get_my_name}")
await dp.start_polling(bot)
except (Exception,AiogramError) as _ex:
logger_bot.critical(f"Can't start bot! Error: {_ex}")
return None
if __name__ == "__main__":
asyncio.run(main())
Help me figure out why the payment is not sent… I’ve been struggling for a week…
just text message...
I tried different providers (PayMaster and other) the payment is not sent and there are no errors (maybe there are, but I literally don’t see what the error is).
try use create_invoice_link()
try multiply amount by 100
I found my mistake, this is suggested_tip_amounts=[100100,300100] in bot.send_invoice()
"A JSON-serialized array of suggested amounts of tips"
so suggested_tip_amounts=[10000,30000] works well