forked from HSE_team/BetterCallPraskovia
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
from decimal import Decimal
|
|
import uuid
|
|
from typing import Dict, Any
|
|
from yookassa import Configuration, Payment as YooPayment
|
|
from tg_bot.config.settings import settings
|
|
|
|
|
|
class YookassaClient:
|
|
|
|
def __init__(self):
|
|
Configuration.configure(
|
|
account_id=settings.YOOKASSA_SHOP_ID,
|
|
secret_key=settings.YOOKASSA_SECRET_KEY
|
|
)
|
|
|
|
async def create_payment(
|
|
self,
|
|
amount: Decimal,
|
|
description: str,
|
|
user_id: int
|
|
) -> Dict[str, Any]:
|
|
try:
|
|
payment = YooPayment.create({
|
|
"amount": {
|
|
"value": f"{amount:.2f}",
|
|
"currency": "RUB"
|
|
},
|
|
"payment_method_data": {
|
|
"type": "bank_card"
|
|
},
|
|
"confirmation": {
|
|
"type": "redirect",
|
|
"return_url": settings.YOOKASSA_RETURN_URL
|
|
},
|
|
"capture": True,
|
|
"description": description,
|
|
"metadata": {
|
|
"user_id": str(user_id),
|
|
"telegram_payment": "true"
|
|
},
|
|
"save_payment_method": False
|
|
})
|
|
return {
|
|
"id": payment.id,
|
|
"status": payment.status,
|
|
"confirmation_url": payment.confirmation.confirmation_url,
|
|
"amount": payment.amount.value,
|
|
"description": payment.description,
|
|
"metadata": payment.metadata
|
|
}
|
|
except Exception as e:
|
|
print(f"Error creating payment: {e}")
|
|
raise
|
|
|
|
yookassa_client = YookassaClient()
|