From ad028b303c6a4496dd700107f59562f7fc1414e2 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Mon, 2 Feb 2026 15:13:37 +0200 Subject: [PATCH] refactor: extract private method --- lnbits/core/services/payments.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lnbits/core/services/payments.py b/lnbits/core/services/payments.py index 488a44529..8a551ce3b 100644 --- a/lnbits/core/services/payments.py +++ b/lnbits/core/services/payments.py @@ -776,12 +776,7 @@ async def _pay_internal_invoice( await update_payment(internal_payment, conn=conn) logger.success(f"internal payment successful {internal_payment.checking_id}") - # fetch balance again - _wallet = await get_wallet(wallet.id, conn=conn) - if not _wallet: - raise PaymentError(f"Could not fetch wallet '{wallet.id}'.", status="failed") - - send_payment_notification_in_background(_wallet, payment) + await _send_payment_notification_in_background(wallet.id, payment, conn=conn) # notify receiver asynchronously from lnbits.tasks import internal_invoice_queue @@ -863,7 +858,7 @@ async def _pay_external_invoice( status="failed", ) - send_payment_notification_in_background(_wallet, payment) + await _send_payment_notification_in_background(wallet.id, payment, conn=conn) logger.success(f"payment successful {payment_response.checking_id}") payment.checking_id = payment_response.checking_id @@ -1071,3 +1066,13 @@ async def cancel_hold_invoice(payment: Payment) -> InvoiceResponse: await update_payment(payment) return response + + +async def _send_payment_notification_in_background( + wallet_id: str, payment: Payment, conn: Connection | None = None +): + # fetch balance again + wallet = await get_wallet(wallet_id, conn=conn) + if not wallet: + raise PaymentError(f"Could not fetch wallet '{wallet_id}'.", status="failed") + send_payment_notification_in_background(wallet, payment)