|
|
|
|
@ -0,0 +1,151 @@
|
|
|
|
|
import requests
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# https://api-ru.iiko.services/docs
|
|
|
|
|
# получение токена
|
|
|
|
|
def access_token(api_key):
|
|
|
|
|
url = "https://api-ru.iiko.services/api/1/access_token"
|
|
|
|
|
payload = json.dumps({
|
|
|
|
|
"apiLogin": api_key
|
|
|
|
|
})
|
|
|
|
|
headers = {
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = requests.request("POST", url, headers=headers, data=payload)
|
|
|
|
|
data = response.json()
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
|
return data['token']
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def iiko_organizations(api_key, organization_id):
|
|
|
|
|
url = "https://api-ru.iiko.services/api/1/organizations"
|
|
|
|
|
payload = json.dumps({
|
|
|
|
|
})
|
|
|
|
|
headers = {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Authorization': 'Bearer ' + access_token(api_key)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = requests.request("POST", url, headers=headers, data=payload)
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
|
data = response.json()
|
|
|
|
|
else:
|
|
|
|
|
data = False
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def customer_create(api_key, phone, name, organization_id):
|
|
|
|
|
url = "https://api-ru.iiko.services/api/1/loyalty/iiko/customer/create_or_update"
|
|
|
|
|
|
|
|
|
|
payload = json.dumps({
|
|
|
|
|
"organizationId": organization_id,
|
|
|
|
|
"phone": phone,
|
|
|
|
|
"name": name,
|
|
|
|
|
"sex": 0,
|
|
|
|
|
"userData": "telegram bot"
|
|
|
|
|
})
|
|
|
|
|
headers = {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Authorization': 'Bearer ' + access_token(api_key)
|
|
|
|
|
}
|
|
|
|
|
response = requests.request("POST", url, headers=headers, data=payload)
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
|
data = response.json()
|
|
|
|
|
else:
|
|
|
|
|
data = False
|
|
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def customer_info(api_key, phone, organization_id):
|
|
|
|
|
url = "https://api-ru.iiko.services/api/1/loyalty/iiko/customer/info"
|
|
|
|
|
payload = json.dumps({
|
|
|
|
|
"phone": phone,
|
|
|
|
|
"type": "phone",
|
|
|
|
|
"organizationId": organization_id
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
headers = {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Authorization': 'Bearer ' + access_token(api_key)
|
|
|
|
|
}
|
|
|
|
|
response = requests.request("POST", url, headers=headers, data=payload)
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
|
data = response.json()
|
|
|
|
|
else:
|
|
|
|
|
data = False
|
|
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# получение терминала
|
|
|
|
|
def iiko_wallet(api_key, organization_id):
|
|
|
|
|
url = "https://api-ru.iiko.services/api/1/terminal_groups"
|
|
|
|
|
payload = json.dumps({
|
|
|
|
|
"organizationIds": [organization_id]
|
|
|
|
|
})
|
|
|
|
|
headers = {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Authorization': 'Bearer ' + access_token(api_key)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = requests.request("POST", url, headers=headers, data=payload)
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
|
data = response.json()
|
|
|
|
|
else:
|
|
|
|
|
data = False
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# пополнение баланса клиента
|
|
|
|
|
def customer_wallet(api_key, iiko_wallet_id, customer_id, organization_id, bonus, comment="telegram balance"):
|
|
|
|
|
url = "https://api-ru.iiko.services/api/1/loyalty/iiko/customer/wallet/topup"
|
|
|
|
|
payload = json.dumps({
|
|
|
|
|
"customerId": customer_id,
|
|
|
|
|
"walletId": iiko_wallet_id,
|
|
|
|
|
"sum": bonus,
|
|
|
|
|
"comment": comment,
|
|
|
|
|
"organizationId": organization_id
|
|
|
|
|
})
|
|
|
|
|
headers = {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Authorization': 'Bearer ' + access_token(api_key)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = requests.request("POST", url, headers=headers, data=payload)
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
|
rs = response.json()
|
|
|
|
|
else:
|
|
|
|
|
print('Erorr customer_wallet:', response.status_code, response.text)
|
|
|
|
|
rs = False
|
|
|
|
|
|
|
|
|
|
return rs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# списание баланса у клиента
|
|
|
|
|
def chargeoff_wallet(api_key, iiko_wallet_id, customer_id, organization_id, bonus, comment="telegram balance delete"):
|
|
|
|
|
url = "https://api-ru.iiko.services/api/1/loyalty/iiko/customer/wallet/chargeoff"
|
|
|
|
|
payload = json.dumps({
|
|
|
|
|
"customerId": customer_id,
|
|
|
|
|
"walletId": iiko_wallet_id,
|
|
|
|
|
"sum": bonus,
|
|
|
|
|
"comment": comment,
|
|
|
|
|
"organizationId": organization_id
|
|
|
|
|
})
|
|
|
|
|
headers = {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Authorization': 'Bearer ' + access_token(api_key)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = requests.request("POST", url, headers=headers, data=payload)
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
|
rs = response.json()
|
|
|
|
|
else:
|
|
|
|
|
print('Erorr customer_wallet:', response.status_code, response.text)
|
|
|
|
|
rs = False
|
|
|
|
|
|
|
|
|
|
return rs
|