invoice.py

 1#  An API wrapper for Bale written in Python
 2#  Copyright (c) 2022-2024
 3#  Kian Ahmadian <devs@python-bale-bot.ir>
 4#  All rights reserved.
 5#
 6#  This software is licensed under the GNU General Public License v2.0.
 7#  See the accompanying LICENSE file for details.
 8#
 9#  You should have received a copy of the GNU General Public License v2.0
10#  along with this program. If not, see <https://www.gnu.org/licenses/gpl-2.0.html>.
11
12from bale import Message, Bot, LabeledPrice
13from bale.handlers import CommandHandler, MessageHandler
14from bale.checks import ChatType, SUCCESSFUL_PAYMENT
15
16client = Bot(token="Your Token")
17
18@client.listen('on_ready')
19async def on_ready_handler():
20    print(client.user, "is Ready!")
21
22@client.handle(CommandHandler('invoice', check=~ChatType.CHANNEL))
23async def on_message(message: Message):
24    return await message.chat.send_invoice(
25        title="Example Donate",
26        description="Example Donate description",
27        provider_token="6037************",
28        payload=str(message.author.user_id),
29        prices=[LabeledPrice(label="Milk", amount=20000)]
30    )
31
32@client.handle(MessageHandler(SUCCESSFUL_PAYMENT))
33async def on_successful_payment(message: Message):
34    print("We Receive an payment From {}".format(message.successful_payment.payload))
35
36client.run()