Private
Public Access
forked from FOSS/AutoShop-Djimbo-Simple
feat: add Lolzteam payment integration
This commit is contained in:
@@ -13,20 +13,31 @@ from tgbot.utils.misc.bot_models import ARS
|
||||
from tgbot.utils.misc_functions import send_admins
|
||||
|
||||
# Список поддерживаемых валют
|
||||
ALLOW_CURRENCIES = ['BTC', 'ETH', 'LTC', 'USDT', 'USDC', 'TRX', 'TON', 'BNB', 'SOL', 'DOGE']
|
||||
ALLOW_CURRENCIES = [
|
||||
"BTC",
|
||||
"ETH",
|
||||
"LTC",
|
||||
"USDT",
|
||||
"USDC",
|
||||
"TRX",
|
||||
"TON",
|
||||
"BNB",
|
||||
"SOL",
|
||||
"DOGE",
|
||||
]
|
||||
|
||||
|
||||
# АПИ для работы с CryptoBot
|
||||
class CryptobotAPI:
|
||||
# Настройка клиента CryptoBot
|
||||
def __init__(
|
||||
self,
|
||||
bot: Bot,
|
||||
arSession: ARS,
|
||||
update: Optional[Union[Message, CallbackQuery]] = None,
|
||||
token: str = "None",
|
||||
adding: bool = False,
|
||||
skipping_error: bool = False,
|
||||
self,
|
||||
bot: Bot,
|
||||
arSession: ARS,
|
||||
update: Optional[Union[Message, CallbackQuery]] = None,
|
||||
token: str = "None",
|
||||
adding: bool = False,
|
||||
skipping_error: bool = False,
|
||||
):
|
||||
self.bot = bot
|
||||
self.arSession = arSession
|
||||
@@ -38,12 +49,12 @@ class CryptobotAPI:
|
||||
# Инициализация данных
|
||||
@classmethod
|
||||
async def connect(
|
||||
cls,
|
||||
bot: Bot,
|
||||
arSession: ARS,
|
||||
update: Optional[Union[Message, CallbackQuery]] = None,
|
||||
token: Optional[str] = None,
|
||||
skipping_error: bool = False,
|
||||
cls,
|
||||
bot: Bot,
|
||||
arSession: ARS,
|
||||
update: Optional[Union[Message, CallbackQuery]] = None,
|
||||
token: Optional[str] = None,
|
||||
skipping_error: bool = False,
|
||||
) -> "CryptobotAPI":
|
||||
adding = token is not None
|
||||
|
||||
@@ -75,21 +86,23 @@ class CryptobotAPI:
|
||||
await send_admins(
|
||||
self.bot,
|
||||
f"<b>🔷 CryptoBot недоступен. Как можно быстрее его замените</b>\n"
|
||||
f"❗️ Ошибка: <code>{error_code}</code>"
|
||||
f"❗️ Ошибка: <code>{error_code}</code>",
|
||||
)
|
||||
|
||||
# Проверка кассы/кошелька
|
||||
async def check(self) -> Tuple[bool, str]:
|
||||
status, response = await self._request("getMe")
|
||||
|
||||
if status and response['ok']:
|
||||
return True, ded(f"""
|
||||
if status and response["ok"]:
|
||||
return True, ded(
|
||||
f"""
|
||||
<b>🔷 CryptoBot кошелёк полностью функционирует ✅</b>
|
||||
➖➖➖➖➖➖➖➖➖➖
|
||||
▪️ Токен: <code>{self.token}</code>
|
||||
▪️ Айди: <code>{response['result']['app_id']}</code>
|
||||
▪️ Имя: <code>{response['result']['name']}</code>
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
return False, "<b>🔷 Не удалось проверить CryptoBot кошелёк ❌</b>"
|
||||
|
||||
@@ -97,17 +110,17 @@ class CryptobotAPI:
|
||||
async def balance(self) -> str:
|
||||
status, response = await self._request("getBalance")
|
||||
|
||||
if status and response['ok']:
|
||||
if status and response["ok"]:
|
||||
save_currencies = []
|
||||
|
||||
response_balances = sorted(
|
||||
response['result'],
|
||||
response["result"],
|
||||
reverse=True,
|
||||
key=lambda balance: to_number(balance['available']),
|
||||
key=lambda balance: to_number(balance["available"]),
|
||||
)
|
||||
|
||||
for currency in response_balances:
|
||||
if currency['currency_code'] in ALLOW_CURRENCIES:
|
||||
if currency["currency_code"] in ALLOW_CURRENCIES:
|
||||
save_currencies.append(
|
||||
f"▪️ {currency['currency_code']}: <code>{currency['available']}</code>"
|
||||
)
|
||||
@@ -123,24 +136,26 @@ class CryptobotAPI:
|
||||
return "<b>🔷 Не удалось получить баланс CryptoBot кошелька ❌</b>"
|
||||
|
||||
# Создание счета на оплату
|
||||
async def bill(self, pay_amount: Union[float, int]) -> Tuple[Union[str, bool], str, str]:
|
||||
async def bill(
|
||||
self, pay_amount: Union[float, int]
|
||||
) -> Tuple[Union[str, bool], str, str]:
|
||||
assets_currencies = ",".join(ALLOW_CURRENCIES)
|
||||
|
||||
payload = {
|
||||
'currency_type': 'fiat',
|
||||
'fiat': 'RUB',
|
||||
'amount': str(pay_amount),
|
||||
'expires_in': 10800,
|
||||
'accepted_assets': assets_currencies
|
||||
"currency_type": "fiat",
|
||||
"fiat": "RUB",
|
||||
"amount": str(pay_amount),
|
||||
"expires_in": 10800,
|
||||
"accepted_assets": assets_currencies,
|
||||
}
|
||||
|
||||
status, response = await self._request("createInvoice", payload)
|
||||
|
||||
if status and response['ok']:
|
||||
if status and response["ok"]:
|
||||
bill_message = ded(f"""
|
||||
<b>💰 Пополнение баланса</b>
|
||||
➖➖➖➖➖➖➖➖➖➖
|
||||
▪️ Для пополнения баланса, нажмите на кнопку ниже
|
||||
▪️ Для пополнения баланса, нажмите на кнопку ниже
|
||||
<code>Перейти к оплате</code> и оплатите выставленный вам счёт
|
||||
▪️ У вас имеется 3 часа на оплату счета
|
||||
▪️ Сумма пополнения: <code>{pay_amount}₽</code>
|
||||
@@ -148,46 +163,52 @@ class CryptobotAPI:
|
||||
❗️ После оплаты, нажмите на <code>Проверить оплату</code>
|
||||
""")
|
||||
|
||||
return bill_message, response['result']['mini_app_invoice_url'], response['result']['invoice_id']
|
||||
return (
|
||||
bill_message,
|
||||
response["result"]["mini_app_invoice_url"],
|
||||
response["result"]["invoice_id"],
|
||||
)
|
||||
|
||||
return False, "", ""
|
||||
|
||||
# Проверка счета на оплату
|
||||
async def bill_check(self, bill_receipt: Optional[Union[str, int]] = None, records: int = 1) -> Tuple[int, float]:
|
||||
async def bill_check(
|
||||
self, bill_receipt: Optional[Union[str, int]] = None, records: int = 1
|
||||
) -> Tuple[int, float]:
|
||||
payload = {
|
||||
'invoice_ids': f'{bill_receipt}',
|
||||
'fiat': 'RUB',
|
||||
"invoice_ids": f"{bill_receipt}",
|
||||
"fiat": "RUB",
|
||||
}
|
||||
|
||||
status, response = await self._request("getInvoices", payload)
|
||||
|
||||
pay_status, pay_amount = 1, 0
|
||||
|
||||
if status and response['ok']:
|
||||
get_invoice = response['result']['items'][0]
|
||||
if status and response["ok"]:
|
||||
get_invoice = response["result"]["items"][0]
|
||||
|
||||
if get_invoice['status'] == "active":
|
||||
if get_invoice["status"] == "active":
|
||||
pay_status = 2
|
||||
elif get_invoice['status'] == "expired":
|
||||
elif get_invoice["status"] == "expired":
|
||||
pay_status = 3
|
||||
else:
|
||||
pay_status = 0
|
||||
pay_amount = to_number(get_invoice['amount'])
|
||||
pay_amount = to_number(get_invoice["amount"])
|
||||
|
||||
return pay_status, pay_amount
|
||||
|
||||
# Генерация запроса
|
||||
async def _request(
|
||||
self,
|
||||
method: str,
|
||||
data: Optional[Dict[str, Any]] = None,
|
||||
self,
|
||||
method: str,
|
||||
data: Optional[Dict[str, Any]] = None,
|
||||
) -> Tuple[bool, Any]:
|
||||
session = await self.arSession.get_session()
|
||||
|
||||
base_url = 'https://pay.crypt.bot/api/'
|
||||
base_url = "https://pay.crypt.bot/api/"
|
||||
headers = {
|
||||
'Crypto-Pay-API-Token': self.token,
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
"Crypto-Pay-API-Token": self.token,
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}
|
||||
|
||||
url = base_url + method
|
||||
@@ -204,7 +225,9 @@ class CryptobotAPI:
|
||||
if response.status == 200:
|
||||
return True, response_data
|
||||
else:
|
||||
await self.error_notification(f"{response.status} - {str(response_data)}")
|
||||
await self.error_notification(
|
||||
f"{response.status} - {str(response_data)}"
|
||||
)
|
||||
|
||||
return False, response_data
|
||||
except ClientConnectorCertificateError:
|
||||
|
||||
Reference in New Issue
Block a user