feat: update payment extra
This commit is contained in:
@@ -19,8 +19,13 @@ from ..models import (
|
||||
)
|
||||
|
||||
|
||||
def update_payment_extra():
|
||||
pass
|
||||
async def update_payment_extra(
|
||||
payment: Payment, conn: Optional[Connection] = None
|
||||
) -> Payment:
|
||||
return await (conn or db).execute(
|
||||
"UPDATE apipayments SET extra = :extra WHERE checking_id = :checking_id",
|
||||
{"extra": payment.extra, "checking_id": payment.checking_id},
|
||||
)
|
||||
|
||||
|
||||
async def get_payment(checking_id: str, conn: Optional[Connection] = None) -> Payment:
|
||||
@@ -380,7 +385,6 @@ async def get_payment_count_stats(
|
||||
user_id: Optional[str] = None,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> list[PaymentCountStat]:
|
||||
|
||||
if not filters:
|
||||
filters = Filters()
|
||||
extra_stmts = []
|
||||
@@ -413,7 +417,6 @@ async def get_daily_stats(
|
||||
user_id: Optional[str] = None,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> tuple[list[PaymentDailyStats], list[PaymentDailyStats]]:
|
||||
|
||||
if not filters:
|
||||
filters = Filters()
|
||||
|
||||
@@ -463,7 +466,6 @@ async def get_wallets_stats(
|
||||
user_id: Optional[str] = None,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> list[PaymentWalletStats]:
|
||||
|
||||
if not filters:
|
||||
filters = Filters()
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ from ..crud import (
|
||||
get_payments_paginated,
|
||||
get_standalone_payment,
|
||||
get_wallet_for_key,
|
||||
update_payment_extra,
|
||||
)
|
||||
from ..services import (
|
||||
create_payment_request,
|
||||
@@ -263,6 +264,38 @@ async def api_payments_create(
|
||||
return await create_payment_request(wallet_id, invoice_data)
|
||||
|
||||
|
||||
@payment_router.patch(
|
||||
"/extra/{payment_hash}", description="Update extra data for a payment"
|
||||
)
|
||||
async def api_payments_update_extra(
|
||||
payment_hash: str,
|
||||
extra: dict,
|
||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||
) -> Payment:
|
||||
payment = await get_standalone_payment(payment_hash, wallet_id=wallet.wallet.id)
|
||||
if payment is None:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Payment does not exist."
|
||||
)
|
||||
if not isinstance(extra, dict):
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST,
|
||||
detail="Extra data must be a dictionary.",
|
||||
)
|
||||
if payment.extra is None:
|
||||
payment.extra = {}
|
||||
|
||||
for key, value in extra.items():
|
||||
if key in payment.extra:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST,
|
||||
detail=f"Key '{key}' already exists in extra data.",
|
||||
)
|
||||
payment.extra[key] = value
|
||||
|
||||
return await update_payment_extra(payment)
|
||||
|
||||
|
||||
@payment_router.get("/fee-reserve")
|
||||
async def api_payments_fee_reserve(invoice: str = Query("invoice")) -> JSONResponse:
|
||||
invoice_obj = bolt11.decode(invoice)
|
||||
|
||||
Reference in New Issue
Block a user