from yookassa import Configuration, Webhook
Configuration.account_id = ""
Configuration.secret_key = ""
Webhook.add({
    "event": "payment.succeeded",
    "url": "https://ip/yookassa-webhook"
})
Webhook.add({
    "event": "payment.waiting_for_capture",
    "url": "https://ip/yookassa-webhook"
})
from fastapi import FastAPI, Request
from yookassa import Payment, Webhook
app = FastAPI()
@app.post('/yookassa-webhook')
async def handle_payment(request: Request):
    event_json = await request.json()
    payment_id = event_json['object']['id']
    user_id = event_json['object']['metadata']['user_id']
    
    if event_json['event'] == 'payment.succeeded':
        amount = event_json['object']['amount']['value']
        payment_method_id = event_json['object']['payment_method']['id']
        
        print(f"Платеж {payment_id} успешен! User: {user_id}, Amount: {amount}")
        
        
        await bot.send_message(user_id, f"✅ Платеж на {amount} руб. успешно завершен!")
    elif event_json['event'] == 'payment.waiting_for_capture':
        Payment.capture(payment_id)
        
    return {"status": "ok"}