fix: pay invoice status (#2481)
* fix: rest `pay_invoice` pending instead of failed * fix: rpc `pay_invoice` pending instead of failed * fix: return "failed" value for payment * fix: handle failed status for LNbits funding source * chore: `phoenixd` todo * test: fix condition * fix: wait for payment status to be updated * fix: fail payment when explicit status provided --------- Co-authored-by: dni ⚡ <office@dnilabs.com>
This commit is contained in:
@@ -171,7 +171,10 @@ async def api_payments_create_invoice(data: CreateInvoice, wallet: Wallet):
|
||||
assert payment_db is not None, "payment not found"
|
||||
checking_id = payment_db.checking_id
|
||||
except InvoiceError as exc:
|
||||
raise HTTPException(status_code=520, detail=str(exc)) from exc
|
||||
return JSONResponse(
|
||||
status_code=520,
|
||||
content={"detail": exc.message, "status": exc.status},
|
||||
)
|
||||
except Exception as exc:
|
||||
raise exc
|
||||
|
||||
@@ -217,14 +220,11 @@ async def api_payments_pay_invoice(
|
||||
payment_hash = await pay_invoice(
|
||||
wallet_id=wallet.id, payment_request=bolt11, extra=extra
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST, detail=str(exc)
|
||||
) from exc
|
||||
except PermissionError as exc:
|
||||
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail=str(exc)) from exc
|
||||
except PaymentError as exc:
|
||||
raise HTTPException(status_code=520, detail=str(exc)) from exc
|
||||
return JSONResponse(
|
||||
status_code=520,
|
||||
content={"detail": exc.message, "status": exc.status},
|
||||
)
|
||||
except Exception as exc:
|
||||
raise exc
|
||||
|
||||
@@ -434,7 +434,7 @@ async def api_payment(payment_hash, x_api_key: Optional[str] = Header(None)):
|
||||
return {"paid": True, "preimage": payment.preimage}
|
||||
|
||||
try:
|
||||
await payment.check_status()
|
||||
status = await payment.check_status()
|
||||
except Exception:
|
||||
if wallet and wallet.id == payment.wallet_id:
|
||||
return {"paid": False, "details": payment}
|
||||
@@ -443,6 +443,7 @@ async def api_payment(payment_hash, x_api_key: Optional[str] = Header(None)):
|
||||
if wallet and wallet.id == payment.wallet_id:
|
||||
return {
|
||||
"paid": not payment.pending,
|
||||
"status": f"{status!s}",
|
||||
"preimage": payment.preimage,
|
||||
"details": payment,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user