Aayco

Error

May 19th, 2025 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. def generate_invoice(price_label: str, price_amount: int, currency: str, title: str,
  2.                      description: str, payload: str, start_param: str) -> types.InputMediaInvoice:
  3.     price = types.LabeledPrice(label=price_label, amount=price_amount)  # label - just a text, amount=10000 means 100.00
  4.     invoice = types.Invoice(
  5.         currency=currency,  # currency like USD
  6.         prices=[price],  # there could be a couple of prices.
  7.         test=True,  # if you're working with test token, else set test=False.
  8.         name_requested=False,
  9.         phone_requested=False,
  10.         email_requested=False,
  11.         shipping_address_requested=False,
  12.  
  13.         flexible=False,
  14.  
  15.         phone_to_provider=False,
  16.         email_to_provider=False
  17.     )
  18.     return types.InputMediaInvoice(
  19.         title=title,
  20.         description=description,
  21.         invoice=invoice,
  22.         payload=payload.encode('UTF-8'),  # payload, which will be sent to next 2 handlers
  23.         provider=' ',
  24.  
  25.         provider_data=types.DataJSON('{}'),
  26.  
  27.         start_param=start_param,
  28.     )
  29.  
  30. @client.on(events.NewMessage(pattern='/pay'))
  31. async def handler(event):
  32.     invoice = generate_invoice(
  33.         price_label='10 Stars',
  34.         price_amount=500,
  35.         currency='USD',
  36.         title='Buy 10 Stars',
  37.         description='Get 10 stars added to your account.',
  38.         payload='buy_10_stars',
  39.         start_param='pay10'
  40.     )
  41.  
  42.     await client.send_message(
  43.         event.chat_id,
  44.         file=invoice,
  45.         message='Click below to pay:',
  46.     )
Advertisement
Add Comment
Please, Sign In to add comment