· 5 years ago · Mar 17, 2020, 03:02 PM
1import requests
2
3
4def get_hook_id(ip_address, token):
5 url = 'https://edge.qiwi.com/payment-notifier/v1/hooks'
6 data = {
7 'hookType': 1,
8 'param': f'https://{ip_address}:443/qiwi',
9 'txnType': '0'
10 }
11 headers = {'Authorization': f'Bearer {token}'}
12 request = requests.put(url, data=data, headers=headers)
13 hook_id = requests.json().get('hookId')
14 return hook_id
15
16
17def get_secret_hook_key(ip_address, hook_id, token):
18 url = 'https://edge.qiwi.com/payment-notifier/v1/hooks/{hookId}/key'
19 headers = {'Authorization': f'Bearer {token}'}
20 data = {'hookId': hook_id}
21 request = requests.get(url, data=data, headers=headers)
22 secret_key = request.json().get('key')
23 return secret_key
24
25
26def register_hook(ip_address, token):
27 hook_id = get_hook_id(ip_address, token)
28 if hook_id:
29 secret_hook_key = get_secret_hook_key(ip_address, hook_id, token)
30 if secret_hook_key:
31 #database_func
32 return True
33 return False
34
35
36@bot.callback_query_handler(func=lambda call: call.data == 'new_requisites')