vacendak

Telegram Stripe Payment

Jun 17th, 2024 (edited)
1,612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. from telebot import types
  2. import settings
  3.  
  4.  
  5. def register_payments_command(bot):
  6.     @bot.message_handler(commands=["comprar"])
  7.     def show_buy_button(message):
  8.         keyboard = types.InlineKeyboardMarkup()
  9.         buy_button = types.InlineKeyboardButton("COMPRAR PARTICIPACIÓN", callback_data="comprar")
  10.         keyboard.add(buy_button)
  11.         bot.send_message(message.chat.id, "¿Quieres una participación?", reply_markup=keyboard)
  12.  
  13.     @bot.callback_query_handler(func=lambda call: call.data == "comprar")
  14.     def callback_buy(call):
  15.         product_price = types.LabeledPrice(label="Participación", amount=500)
  16.         bot.send_invoice(
  17.             chat_id=call.message.chat.id,
  18.             title="Participación",
  19.             description="Participación en el sorteo",
  20.             invoice_payload="custom-paylooad-buy-product",
  21.             provider_token=settings.STRIPE_TEST_TOKEN,
  22.             currency="eur",
  23.             prices=[product_price],
  24.             start_parameter="product-purchase",
  25.         )
  26.  
  27.     @bot.pre_checkout_query_handler(func=lambda query: True)
  28.     def checkout_process(pre_checkout_query):
  29.         bot.answer_pre_checkout_query(pre_checkout_query.id, ok=True)
  30.  
  31.     @bot.message_handler(content_types=["successful_payment"])
  32.     def got_payment(message):
  33.         bot.send_message(message.chat.id, "Gracias por participar y suerte en el sorteo!")
  34.  
Advertisement
Add Comment
Please, Sign In to add comment