Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def generate_invoice(price_label: str, price_amount: int, currency: str, title: str,
- description: str, payload: str, start_param: str) -> types.InputMediaInvoice:
- price = types.LabeledPrice(label=price_label, amount=price_amount) # label - just a text, amount=10000 means 100.00
- invoice = types.Invoice(
- currency=currency, # currency like USD
- prices=[price], # there could be a couple of prices.
- test=True, # if you're working with test token, else set test=False.
- name_requested=False,
- phone_requested=False,
- email_requested=False,
- shipping_address_requested=False,
- flexible=False,
- phone_to_provider=False,
- email_to_provider=False
- )
- return types.InputMediaInvoice(
- title=title,
- description=description,
- invoice=invoice,
- payload=payload.encode('UTF-8'), # payload, which will be sent to next 2 handlers
- provider=' ',
- provider_data=types.DataJSON('{}'),
- start_param=start_param,
- )
- @client.on(events.NewMessage(pattern='/pay'))
- async def handler(event):
- invoice = generate_invoice(
- price_label='10 Stars',
- price_amount=500,
- currency='USD',
- title='Buy 10 Stars',
- description='Get 10 stars added to your account.',
- payload='buy_10_stars',
- start_param='pay10'
- )
- await client.send_message(
- event.chat_id,
- file=invoice,
- message='Click below to pay:',
- )
Advertisement
Add Comment
Please, Sign In to add comment