fix(pally): use InvId as primary bill identifier instead of custom field

This commit is contained in:
2026-05-31 15:17:48 +07:00
parent 936d1ad260
commit 18f994aed9
2 changed files with 21 additions and 14 deletions

View File

@@ -45,7 +45,10 @@ async def pally_callback(
bot: Bot = Depends(get_bot),
deps: APIDependenciesDTO = Depends(get_deps),
):
oid = custom or ""
# FIXED: Use InvId (which contains the order_id from bill creation) instead of custom field
# The InvId field contains the db_bill.id that was passed as order_id during bill creation
bill_id_str = InvId
logger.info(
"Pally webhook received - InvId: %s, OutSum: %s, Commission: %s, TrsId: %s, Status: %s, "
"CurrencyIn: %s, custom: %s, SignatureValue: %s",
@@ -80,16 +83,19 @@ async def pally_callback(
logger.info("Processing successfully paid bill %s", TrsId)
# Validate custom field (order ID)
if not oid or not oid.isdigit():
logger.critical("Invalid or missing custom field for TrsId %s: '%s'", TrsId, custom)
# Validate bill ID (from InvId field, which contains the order_id from bill creation)
if not bill_id_str or not bill_id_str.isdigit():
logger.critical(
"Invalid or non-numeric bill ID in InvId field for TrsId %s: '%s'",
TrsId, bill_id_str
)
return "OK"
# Find bill in database
bill = await deps.bills_repository.get_bill_by_id(session, int(oid))
bill = await deps.bills_repository.get_bill_by_id(session, int(bill_id_str))
if not bill:
logger.critical("Bill %s not found in database for TrsId %s", oid, TrsId)
logger.critical("Bill %s not found in database for TrsId %s", bill_id_str, TrsId)
return "OK"
# Check if already processed