Webhooks

Caution

To correctly run the webhook you need a VPS server or configure the local machine for response to requests of QIWI API.

Using glQiwiApi you can use two types of handlers transaction_handler and bill_handler respectively. Also, you can pass lambda filters to miss unnecessary updates from webhook.

Usage of webhooks
 1from aiogram import Bot
 2
 3from glQiwiApi import QiwiWrapper, types
 4from glQiwiApi.core.web_hooks.config import Path
 5from glQiwiApi.utils import executor
 6
 7TOKEN = 'token from https://qiwi.com/api/'
 8QIWI_SECRET = 'secret token from https://qiwi.com/p2p-admin/'
 9
10wallet = QiwiWrapper(
11    api_access_token=TOKEN,
12    secret_p2p=QIWI_SECRET
13)
14
15bot = Bot(token="BOT_TOKEN")
16
17
18# There is a lambda expression for "cutting off" test payments
19@wallet.transaction_handler(lambda event: event.payment is not None)
20async def main(event: types.WebHook):
21    event.client.dispatcher.logger.info("New transaction: {}", event)
22    await bot.send_message(chat_id='1219185039', text=event.hook_id)
23
24
25@wallet.bill_handler()
26async def main2(event: types.Notification):
27    event.client.dispatcher.logger.info("P2P EVENT {}", event)
28
29
30# Also, you can specify a path for webhook
31# Example: http://127.0.0.1/your_path/
32# If you don't pass path in `start_webhook`
33# or dont pass on transaction_path or bill_path
34# Its ok, because it will take a default paths
35# default transaction_path = /web_hooks/qiwi/
36# default bill_path = /webhooks/qiwi/bills/
37# So, if you dont pass on paths
38# you need to register webhook with url like
39# on this example: http://your_ip:port/web_hooks/qiwi/ - for transactions
40# or http://your_ip:port/webhooks/qiwi/bills/ - for bills
41path = Path(
42    transaction_path="/web_hooks/qiwi",
43    bill_path="/my_webhook/"
44)
45
46executor.start_webhook(
47    wallet,
48    # You can pass on any port, but it must be open for web
49    # You can use any VPS server to catching webhook or
50    # your configured local machine
51    path=path
52)