@TakeThisGear

Как подключить Telegram Wallet к проекту на питоне?

Делаю бота с оплатой Telegram Wallet, столкнулся с ошибкой: telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: PAYMENT_PROVIDER_INVALID.
API ключ верен. Пару раз пересоздавал. Код:
import telebot
from telebot import types

TOKEN = тут токен
bot = telebot.TeleBot(TOKEN)

@bot.message_handler(commands=['start'])
def send_welcome(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    item = types.KeyboardButton("Buy Pen for $1")
    markup.add(item)
    bot.send_message(message.chat.id, "Welcome to our store! How can I assist you today?", reply_markup=markup)

@bot.message_handler(content_types=['text'])
def process_message(message):
    if message.text == "Buy Pen for $1":
        bot.send_invoice(message.chat.id, title='Pen', description='A high-quality pen', provider_token=токен тоже,
            currency='USD', photo_url='', photo_height=512, photo_width=512,
            photo_size=512, is_flexible=False, prices=[types.LabeledPrice(label='Pen', amount=100)], invoice_payload="CustomPayload")
    else:
        bot.send_message(message.chat.id, "Sorry, I didn't understand that command. Please try again.")

if __name__ == '__main__':
    bot.polling(none_stop=True)


Так же пробовал такой код:
import telebot
from telebot import types

TOKEN = 'token'
PROVIDER_TOKEN = 'token'
bot = telebot.TeleBot(TOKEN)

@bot.message_handler(commands=['start'])
def send_welcome(message):
    bot.send_message(
        message.chat.id,
        "Hi. I am test",
    )

@bot.message_handler(commands=['buy'])
def send_invoice(message):
    start_parameter = "Example Start Parameter"
    title = "test payment"
    description = "Try to buy smth"
    payload = "CustomPayload"

    prices = [types.LabeledPrice("Test", 100)] 

    bot.send_invoice(
        message.chat.id,
        title=title,
        description=description,
        provider_token=PROVIDER_TOKEN,
        currency='USD',
        photo_url=None,
        photo_height=None,
        photo_width=None,
        photo_size=None,
        is_flexible=False, 
        prices=prices,
        start_parameter=start_parameter,
        invoice_payload=payload
    )

@bot.pre_checkout_query_handler(func=lambda call: True)
def checkout(pre_checkout_query):
    bot.answer_pre_checkout_query(pre_checkout_query.id, ok=True)

@bot.message_handler(content_types=['successful_payment'])
def got_payment(message):
    bot.send_message(
        message.chat.id,
        "Thx.",
        reply_markup=types.ReplyKeyboardRemove(),
    )

bot.polling()
  • Вопрос задан
  • 284 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы