diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py index a63f52c4d..e9b28a558 100644 --- a/lnbits/core/crud.py +++ b/lnbits/core/crud.py @@ -180,13 +180,18 @@ async def get_wallet_for_key( async def get_standalone_payment( - checking_id_or_hash: str, conn: Optional[Connection] = None + checking_id_or_hash: str, + conn: Optional[Connection] = None, + incoming: Optional[bool] = False, ) -> Optional[Payment]: + clause: str = "checking_id = ? OR hash = ?" + if incoming: + clause = f"({clause}) AND amount > 0" row = await (conn or db).fetchone( - """ + f""" SELECT * FROM apipayments - WHERE checking_id = ? OR hash = ? + WHERE {clause} LIMIT 1 """, (checking_id_or_hash, checking_id_or_hash), diff --git a/lnbits/tasks.py b/lnbits/tasks.py index 4e73a0af6..34f37a394 100644 --- a/lnbits/tasks.py +++ b/lnbits/tasks.py @@ -114,7 +114,7 @@ async def perform_balance_checks(): async def invoice_callback_dispatcher(checking_id: str): - payment = await get_standalone_payment(checking_id) + payment = await get_standalone_payment(checking_id, incoming=True) if payment and payment.is_in: await payment.set_pending(False) for send_chan in invoice_listeners: