From 190a466c0ad47c889466f5a697961cada5adbae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 25 May 2026 13:29:39 +0200 Subject: [PATCH] fix: update_payment should return the updated payment (#3983) --- lnbits/core/crud/payments.py | 4 +++- lnbits/core/services/payments.py | 15 ++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lnbits/core/crud/payments.py b/lnbits/core/crud/payments.py index eba8c373a..05a9d341f 100644 --- a/lnbits/core/crud/payments.py +++ b/lnbits/core/crud/payments.py @@ -321,13 +321,15 @@ async def update_payment( payment: Payment, new_checking_id: str | None = None, conn: Connection | None = None, -) -> None: +) -> Payment: payment.updated_at = datetime.now(timezone.utc) await (conn or db).update( "apipayments", payment, "WHERE checking_id = :checking_id" ) if new_checking_id and new_checking_id != payment.checking_id: await update_payment_checking_id(payment.checking_id, new_checking_id, conn) + payment.checking_id = new_checking_id + return payment async def get_payments_history( diff --git a/lnbits/core/services/payments.py b/lnbits/core/services/payments.py index a0f241701..3374a0dd4 100644 --- a/lnbits/core/services/payments.py +++ b/lnbits/core/services/payments.py @@ -171,15 +171,15 @@ async def create_fiat_invoice( internal_payment.fiat_provider = fiat_provider_name internal_payment.extra["fiat_checking_id"] = fiat_invoice.checking_id - # todo: move to payent + # TODO: move to payment internal_payment.extra["fiat_payment_request"] = fiat_invoice.payment_request new_checking_id = ( f"fiat_{fiat_provider_name}_" f"{fiat_invoice.checking_id or internal_payment.checking_id}" ) - await update_payment(internal_payment, new_checking_id, conn=conn) - internal_payment.checking_id = new_checking_id - + internal_payment = await update_payment( + internal_payment, new_checking_id, conn=conn + ) return internal_payment @@ -374,7 +374,7 @@ async def update_pending_payment( status = await check_payment_status(payment) if status.failed: payment.status = PaymentState.FAILED - await update_payment(payment, conn=conn) + payment = await update_payment(payment, conn=conn) elif status.success: payment = await update_payment_success_status(payment, status, conn=conn) return payment @@ -876,7 +876,7 @@ async def update_payment_success_status( payment.status = PaymentState.SUCCESS payment.fee = -(abs(status.fee_msat or 0) + abs(service_fee_msat)) payment.preimage = payment.preimage or status.preimage - await update_payment(payment, conn=conn) + payment = await update_payment(payment, conn=conn) return payment @@ -1099,8 +1099,9 @@ async def update_invoice_callback(checking_id: str) -> Payment | None: payment.fee = status.fee_msat or payment.fee # only overwrite preimage if status.preimage provides it payment.preimage = status.preimage or payment.preimage + payment.status = PaymentState.SUCCESS - await update_payment(payment) + payment = await update_payment(payment) if payment.fiat_provider: await handle_fiat_payment_confirmation(payment) return payment