Недавно телеграм ввёл в ботах оплату только через
звёзды.
Решил попробовать.
Вот мой код:
from aiogram import Router, F, Bot, types
from aiogram.filters import Command
from aiogram.types import Message, PreCheckoutQuery
from aiogram import Dispatcher
import asyncio
import logging
from aiogram.types.message import ContentType
from aiogram.utils.callback_answer import CallbackAnswer, CallbackQuery
from typing import Optional
from aiogram.filters.callback_data import CallbackData
from aiogram.types.message import ContentType
from aiogram.methods.create_invoice_link import CreateInvoiceLink
from aiogram.utils.keyboard import InlineKeyboardBuilder, ReplyKeyboardBuilder
bot = Bot(token=TOKEN)
dp = Dispatcher()
logging.basicConfig(level=logging.INFO)
router = Router()
@dp.message(Command('start'))
async def create_invoice(msg: Message):
Upscale = types.LabeledPrice(label='Одна покупка', amount=1)
await bot.send_invoice(
msg.chat.id,
title="One little buy",
description="One little buy",
provider_token="",
currency="XTR",
photo_url="https://mihailgok.ru/upscale.jpg",
photo_width=3600,
photo_height=2338,
photo_size=262000,
is_flexible=False,
prices=[Upscale],
start_parameter="one-upscale",
payload="one-upscale"
)
@router.pre_checkout_query()
async def checkout_handler(checkout_query: PreCheckoutQuery):
await checkout_query.answer(ok=True)
@router.message(F.successful_payment)
async def star_payment(msg: Message, bot: Bot):
await bot.refund_star_payment(
msg.chat.id,
msg.successful_payment.telegram_payment_charge_id,
)
await msg.answer(f"Your transaction id: {msg.successful_payment.telegram_payment_charge_id}")
async def main():
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main(), debug=True)
Почему-то не проходит оплата через звёзды - ничего не приходит в:
pre_checkout_query
Идет бесконечная прогрузка и затем ошибка.