From 09b91f9f795f18975896d044b7a8450528042572 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 4 Jul 2025 12:58:47 +0300 Subject: [PATCH] refactor: extract `create_payment_request` (#3240) --- lnbits/core/services/__init__.py | 2 ++ lnbits/core/services/payments.py | 12 ++++++++++++ lnbits/core/views/payment_api.py | 8 ++------ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lnbits/core/services/__init__.py b/lnbits/core/services/__init__.py index 63a8bf43..a95453df 100644 --- a/lnbits/core/services/__init__.py +++ b/lnbits/core/services/__init__.py @@ -10,6 +10,7 @@ from .payments import ( check_wallet_limits, create_fiat_invoice, create_invoice, + create_payment_request, create_wallet_invoice, fee_reserve, fee_reserve_total, @@ -41,6 +42,7 @@ __all__ = [ "check_webpush_settings", "create_fiat_invoice", "create_invoice", + "create_payment_request", "create_user_account", "create_user_account_no_ckeck", "create_wallet_invoice", diff --git a/lnbits/core/services/payments.py b/lnbits/core/services/payments.py index 434784d1..5687c0ad 100644 --- a/lnbits/core/services/payments.py +++ b/lnbits/core/services/payments.py @@ -99,6 +99,18 @@ async def pay_invoice( return payment +async def create_payment_request( + wallet_id: str, invoice_data: CreateInvoice +) -> Payment: + """ + Create a lightning invoice or a fiat payment request. + """ + if invoice_data.fiat_provider: + return await create_fiat_invoice(wallet_id, invoice_data) + + return await create_wallet_invoice(wallet_id, invoice_data) + + async def create_fiat_invoice( wallet_id: str, invoice_data: CreateInvoice, conn: Optional[Connection] = None ): diff --git a/lnbits/core/views/payment_api.py b/lnbits/core/views/payment_api.py index cf6654ba..eea74a42 100644 --- a/lnbits/core/views/payment_api.py +++ b/lnbits/core/views/payment_api.py @@ -62,8 +62,7 @@ from ..crud import ( get_wallet_for_key, ) from ..services import ( - create_fiat_invoice, - create_wallet_invoice, + create_payment_request, fee_reserve_total, get_payments_daily_stats, pay_invoice, @@ -261,10 +260,7 @@ async def api_payments_create( ) # If the payment is not outgoing, we can create a new invoice. - if invoice_data.fiat_provider: - return await create_fiat_invoice(wallet_id, invoice_data) - - return await create_wallet_invoice(wallet_id, invoice_data) + return await create_payment_request(wallet_id, invoice_data) @payment_router.get("/fee-reserve")