Загрузить файлы в «/»

This commit is contained in:
2024-06-17 11:54:30 +00:00
parent fb734d3e55
commit 8069178d24
4 changed files with 181 additions and 0 deletions

36
payments.py Normal file
View File

@ -0,0 +1,36 @@
from config import db
import aiohttp
def api_crypto():
token = db.get_token('CRYPTO')
return token
async def getCoins():
async with aiohttp.ClientSession() as session:
async with session.get('https://api.nowpayments.io/v1/merchant/coins', headers={'x-api-key': api_crypto()}) as resp:
response = await resp.json()
return response['selectedCurrencies']
async def createPayment(amount, paycurrency):
headers = {
'x-api-key': api_crypto()
}
payload = {
"price_amount": float(amount),
"price_currency": "usd",
"pay_currency": paycurrency,
}
async with aiohttp.ClientSession() as session:
async with session.post('https://api.nowpayments.io/v1/payment', headers=headers, data=payload) as resp:
response = await resp.json()
return response
async def check_pay(payment_id):
headers = {
'x-api-key': api_crypto()
}
async with aiohttp.ClientSession() as session:
async with session.get(f'https://api.nowpayments.io/v1/payment/{payment_id}', headers=headers) as resp:
response = await resp.json()
return response['payment_status']