Fix paymentid and success and fail urls

This commit is contained in:
Boris Kovalskii
2025-07-24 19:10:14 +10:00
committed by GitHub
parent 730c245163
commit 5ddeca9f27
2 changed files with 15 additions and 4 deletions
+6 -3
View File
@@ -12,7 +12,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from config import (
KASSAI_ENABLE, KASSAI_API_KEY, KASSAI_SECRET_KEY, KASSAI_DOMAIN, KASSAI_SHOP_ID,
REDIRECT_LINK, FAIL_REDIRECT_LINK, WEBHOOK_HOST, KASSAI_IP
REDIRECT_LINK, FAIL_REDIRECT_LINK, WEBHOOK_HOST, KASSAI_IP, KASSAI_SUCCESS_URL, KASSAI_FAILURE_URL
)
from handlers.buttons import BACK, PAY_2, KASSAI_CARDS, KASSAI_SBP
@@ -287,7 +287,7 @@ async def generate_kassai_payment_link(amount: int, tg_id: int, method: dict) ->
"""
nonce = int(time.time())
unique_payment_id = f"{nonce}_{tg_id}"
url = f"https://api.fk.life/v1/orders/create?paymentId={unique_payment_id}"
url = "https://api.fk.life/v1/orders/create"
headers = {
"Content-Type": "application/json",
@@ -303,7 +303,10 @@ async def generate_kassai_payment_link(amount: int, tg_id: int, method: dict) ->
"email": client_email,
"ip": client_ip,
"amount": int(amount),
"currency": "RUB"
"currency": "RUB",
"success_url": KASSAI_SUCCESS_URL,
"failure_url": KASSAI_FAILURE_URL,
"paymentId": unique_payment_id
}
sorted_keys = sorted(data_for_signature.keys())
+9 -1
View File
@@ -37,6 +37,8 @@ async def kassai_payment_webhook(request: web.Request):
p_email = data_dict.get("P_EMAIL")
intid = data_dict.get("intid")
logger.info(f"KassaAI payment: intid={intid}, MERCHANT_ORDER_ID={merchant_order_id}, amount={amount}")
if not amount or not intid:
logger.error(f"KassaAI: Missing AMOUNT or intid")
return web.Response(status=400, text="Missing required fields")
@@ -45,6 +47,10 @@ async def kassai_payment_webhook(request: web.Request):
logger.warning(f"KassaAI: Duplicate payment intid={intid}")
return web.Response(status=200, text="YES")
if merchant_order_id and merchant_order_id in processed_payments:
logger.warning(f"KassaAI: Duplicate payment MERCHANT_ORDER_ID={merchant_order_id}")
return web.Response(status=200, text="YES")
try:
if p_email and "@" in p_email:
tg_id = int(p_email.split("@")[0])
@@ -80,8 +86,10 @@ async def kassai_payment_webhook(request: web.Request):
logger.warning(f"Error handling payment message deletion: {e}")
processed_payments.add(intid)
if merchant_order_id:
processed_payments.add(merchant_order_id)
logger.info(f"✅ KassaAI: Payment processed for user {tg_id}, amount {amount_float}, intid={intid}")
logger.info(f"✅ KassaAI: Payment processed for user {tg_id}, amount {amount_float}, intid={intid}, MERCHANT_ORDER_ID={merchant_order_id}")
return web.Response(status=200, text="YES")
except Exception as e: