forked from NuraliSahatow/tegro_money_api
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtegro_money_python_documentation.py
More file actions
163 lines (134 loc) · 3.93 KB
/
Copy pathtegro_money_python_documentation.py
File metadata and controls
163 lines (134 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import json
import requests
import hashlib
import hmac
import time
#использовать текущее время в секундах для nonce
nonce = int(time.time())
#Извлечения значений из конфига
with open('config.json') as config_file:
config = json.load(config_file)
public_key = config("public_key")
sectet_key = config("secret_key")
api_key = config("api_key")
email = config("email")
phone = config("phone")
shop_id = config("shop_id")
def generate_signature(params, api_key):
body = json.dumps(params)
sign = hmac.new(api_key.encode(), body.encode(), hashlib.sha256).hexdigest()
return sign
def make_request(url, params, api_key):
body = json.dumps(params)
sign = generate_signature(params, api_key)
headers = {
"Authorization": f"Bearer {sign}",
"Content-Type": "application/json"
}
response = requests.post(url=url, headers=headers, params=params)
return response.json()
# Создание заказа
def create_order():
url = 'https://tegro.money/api/createOrder/'
params = {
"shop_id": shop_id,
"nonce": nonce,
"currency": "RUB",
"amount": 100,
"order_id": "1",
"payment_system": 1,
"fields": {
"email": email,
"phone": phone
},
"receipt": {
"items": [
{
"name": "test item 1",
"count": 1,
"price": 600
},
{
"name": "test item 2",
"count": 1,
"price": 600
}
]
}
}
response = make_request(url, params, api_key)
print(response)
# Получение списка магазинов
def list_shops():
url = "https://tegro.money/api/shops/"
params = {
"shop_id": shop_id,
"nonce": nonce
}
response = make_request(url, params, api_key)
print(response)
# Получение баланса
def get_balance():
url = "https://tegro.money/api/balance/"
params = {
"shop_id": shop_id,
"nonce": nonce
}
response = make_request(url, params, api_key)
print(response)
# Проверка заказа
def check_order():
url = 'https://tegro.money/api/order/'
params = {
"shop_id": shop_id,
"nonce": nonce,
"order_id": 755555,
"payment_id": "test order"
}
response = make_request(url, params, api_key)
print(response)
# Получение информации о заказах
def list_orders():
url = 'https://tegro.money/api/orders/'
params = {
"shop_id": shop_id,
"nonce": nonce,
"page": 1
}
response = make_request(url, params, api_key)
print(response)
# Создание выплаты
def create_withdrawal():
url = 'https://tegro.money/api/createWithdrawal/'
params = {
"shop_id": shop_id,
"nonce": nonce,
"currency": "RUB",
"account": "123",
"amount": 100,
"payment_id": 1124235,
"payment_system": 1
}
response = make_request(url, params, api_key)
print(response)
# Получение списка выплат
def list_withdrawals():
url = 'https://tegro.money/api/withdrawals/'
params = {
"shop_id": shop_id,
"nonce": nonce,
"page": 1
}
response = make_request(url, params, api_key)
print(response)
# Проверка выплаты
def check_withdrawal():
url = 'https://tegro.money/api/withdrawal/'
params = {
"shop_id": shop_id,
"nonce": nonce,
"order_id": 755555,
"payment_id": "test order"
}
response = make_request(url, params, api_key)
print(response)