Merge branch 'FastAPI' of https://github.com/arcbtc/lnbits into FastAPI

This commit is contained in:
Tiago vasconcelos
2021-11-03 10:30:48 +00:00
2 changed files with 17 additions and 13 deletions

View File

@@ -324,12 +324,14 @@ async def api_payments_sse(
@core_app.get("/api/v1/payments/{payment_hash}") @core_app.get("/api/v1/payments/{payment_hash}")
async def api_payment(payment_hash): async def api_payment(payment_hash):
payment = await get_standalone_payment(payment_hash) payment = await get_standalone_payment(payment_hash)
await check_invoice_status(payment.wallet_id, payment_hash) await check_invoice_status(payment.wallet_id, payment_hash)
payment = await get_standalone_payment(payment_hash) payment = await get_standalone_payment(payment_hash)
if not payment: if not payment:
return {"message": "Payment does not exist."} raise HTTPException(
status_code=HTTPStatus.NOT_FOUND,
detail="Payment does not exist.",
)
elif not payment.pending: elif not payment.pending:
return {"paid": True, "preimage": payment.preimage} return {"paid": True, "preimage": payment.preimage}

View File

@@ -45,7 +45,7 @@ class LNbitsWallet(Wallet):
) )
if r.is_error: if r.is_error:
return StatusResponse(data["message"], 0) return StatusResponse(data["detail"], 0)
return StatusResponse(None, data["balance"]) return StatusResponse(None, data["balance"])
@@ -73,7 +73,7 @@ class LNbitsWallet(Wallet):
) )
if r.is_error: if r.is_error:
error_message = r.json()["message"] error_message = r.json()["detail"]
else: else:
data = r.json() data = r.json()
checking_id, payment_request = data["checking_id"], data["payment_request"] checking_id, payment_request = data["checking_id"], data["payment_request"]
@@ -90,7 +90,7 @@ class LNbitsWallet(Wallet):
ok, checking_id, fee_msat, error_message = not r.is_error, None, 0, None ok, checking_id, fee_msat, error_message = not r.is_error, None, 0, None
if r.is_error: if r.is_error:
error_message = r.json()["message"] error_message = r.json()["detail"]
else: else:
data = r.json() data = r.json()
checking_id = data["checking_id"] checking_id = data["checking_id"]
@@ -98,15 +98,17 @@ class LNbitsWallet(Wallet):
return PaymentResponse(ok, checking_id, fee_msat, error_message) return PaymentResponse(ok, checking_id, fee_msat, error_message)
async def get_invoice_status(self, checking_id: str) -> PaymentStatus: async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
try:
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
r = await client.get( r = await client.get(
url=f"{self.endpoint}/api/v1/payments/{checking_id}", headers=self.key url=f"{self.endpoint}/api/v1/payments/{checking_id}",
headers=self.key,
) )
if r.is_error: if r.is_error:
return PaymentStatus(None) return PaymentStatus(None)
return PaymentStatus(r.json()["paid"]) return PaymentStatus(r.json()["paid"])
except:
return PaymentStatus(None)
async def get_payment_status(self, checking_id: str) -> PaymentStatus: async def get_payment_status(self, checking_id: str) -> PaymentStatus:
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client: