Private
Public Access
forked from FOSS/AutoShop-Djimbo-Simple
refactor(api_lolzteam): improve merchant validation and request handling
This commit is contained in:
@@ -110,13 +110,20 @@ class LolzteamAPI:
|
|||||||
and "balances" in response["user"]
|
and "balances" in response["user"]
|
||||||
and self.merchant_id
|
and self.merchant_id
|
||||||
):
|
):
|
||||||
balances = response["user"]["balances"]
|
# ! Проверка этим способом не работает для мерчантов, у которых нет отдельного
|
||||||
|
# ! баланса на маркете, и поэтому используется способ ниже
|
||||||
|
# balances = response["user"]["balances"]
|
||||||
|
|
||||||
for balance in balances:
|
# for balance in balances:
|
||||||
if int(self.merchant_id) == balance["merchant_id"]:
|
# if int(self.merchant_id) == balance["merchant_id"]:
|
||||||
merchant_valid = True
|
# merchant_valid = True
|
||||||
|
|
||||||
if merchant_valid:
|
# ! Создание оплаты и проверка возвращаемого статуса (если статус положительный - то и мерчант валидный)
|
||||||
|
bill_message, bill_link, bill_receipt = await self.bill(
|
||||||
|
1, is_test=True
|
||||||
|
) # Тестовый инвойс
|
||||||
|
|
||||||
|
if bill_message:
|
||||||
return True, ded(
|
return True, ded(
|
||||||
f"""
|
f"""
|
||||||
<b>🟢 Lolzteam полностью функционирует ✅</b>
|
<b>🟢 Lolzteam полностью функционирует ✅</b>
|
||||||
@@ -173,7 +180,9 @@ class LolzteamAPI:
|
|||||||
|
|
||||||
# Создание счета на оплату
|
# Создание счета на оплату
|
||||||
async def bill(
|
async def bill(
|
||||||
self, pay_amount: Union[float, int]
|
self,
|
||||||
|
pay_amount: Union[float, int],
|
||||||
|
is_test: bool = False,
|
||||||
) -> Tuple[Union[str, bool], str, str]:
|
) -> Tuple[Union[str, bool], str, str]:
|
||||||
|
|
||||||
pro_payment_id = get_unix()
|
pro_payment_id = get_unix()
|
||||||
@@ -185,6 +194,8 @@ class LolzteamAPI:
|
|||||||
bot_username = bot_data.username
|
bot_username = bot_data.username
|
||||||
bot_url = f"https://telegram.me/{bot_username}"
|
bot_url = f"https://telegram.me/{bot_username}"
|
||||||
|
|
||||||
|
print(is_test)
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"currency": "rub",
|
"currency": "rub",
|
||||||
"amount": pay_amount,
|
"amount": pay_amount,
|
||||||
@@ -193,7 +204,7 @@ class LolzteamAPI:
|
|||||||
"url_success": bot_url,
|
"url_success": bot_url,
|
||||||
"merchant_id": self.merchant_id,
|
"merchant_id": self.merchant_id,
|
||||||
"lifetime": 10800,
|
"lifetime": 10800,
|
||||||
"is_test": True, # Тестовый режим для отладки
|
"is_test": is_test, # Тестовый режим для отладки
|
||||||
}
|
}
|
||||||
|
|
||||||
status, response = await self._request("invoice", payload)
|
status, response = await self._request("invoice", payload)
|
||||||
@@ -264,13 +275,14 @@ class LolzteamAPI:
|
|||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {self.token}",
|
"Authorization": f"Bearer {self.token}",
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
|
|
||||||
url = base_url + path
|
url = base_url + path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if method == "POST":
|
if method == "POST":
|
||||||
response = await session.post(url=url, headers=headers, data=data)
|
response = await session.post(url=url, headers=headers, json=data)
|
||||||
|
|
||||||
elif method == "GET":
|
elif method == "GET":
|
||||||
response = await session.get(url=url, headers=headers, params=data)
|
response = await session.get(url=url, headers=headers, params=data)
|
||||||
|
|||||||
Reference in New Issue
Block a user