refactor: extract create_payment_request (#3240)

This commit is contained in:
Vlad Stan 2025-07-04 12:58:47 +03:00 committed by dni ⚡
parent 90ab642dcd
commit 09b91f9f79
No known key found for this signature in database
GPG key ID: D1F416F29AD26E87
3 changed files with 16 additions and 6 deletions

View file

@ -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",

View file

@ -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
):

View file

@ -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")