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:
+15
-24
@@ -174,39 +174,30 @@ class LndRestWallet(Wallet):
|
||||
timeout=None,
|
||||
)
|
||||
r.raise_for_status()
|
||||
except Exception as exc:
|
||||
logger.warning(f"LndRestWallet pay_invoice POST error: {exc}.")
|
||||
return PaymentResponse(
|
||||
False, None, None, None, f"Unable to connect to {self.endpoint}."
|
||||
)
|
||||
|
||||
try:
|
||||
data = r.json()
|
||||
|
||||
if data.get("payment_error"):
|
||||
error_message = r.json().get("payment_error") or r.text
|
||||
logger.warning(
|
||||
f"LndRestWallet pay_invoice payment_error: {error_message}."
|
||||
)
|
||||
return PaymentResponse(False, None, None, None, error_message)
|
||||
|
||||
if (
|
||||
"payment_hash" not in data
|
||||
or "payment_route" not in data
|
||||
or "total_fees_msat" not in data["payment_route"]
|
||||
or "payment_preimage" not in data
|
||||
):
|
||||
return PaymentResponse(
|
||||
False, None, None, None, "Server error: 'missing required fields'"
|
||||
)
|
||||
payment_error = data.get("payment_error")
|
||||
if payment_error:
|
||||
logger.warning(f"LndRestWallet payment_error: {payment_error}.")
|
||||
return PaymentResponse(False, None, None, None, payment_error)
|
||||
|
||||
checking_id = base64.b64decode(data["payment_hash"]).hex()
|
||||
fee_msat = int(data["payment_route"]["total_fees_msat"])
|
||||
preimage = base64.b64decode(data["payment_preimage"]).hex()
|
||||
return PaymentResponse(True, checking_id, fee_msat, preimage, None)
|
||||
except KeyError as exc:
|
||||
logger.warning(exc)
|
||||
return PaymentResponse(
|
||||
None, None, None, None, "Server error: 'missing required fields'"
|
||||
)
|
||||
except json.JSONDecodeError:
|
||||
return PaymentResponse(
|
||||
False, None, None, None, "Server error: 'invalid json response'"
|
||||
None, None, None, None, "Server error: 'invalid json response'"
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.warning(f"LndRestWallet pay_invoice POST error: {exc}.")
|
||||
return PaymentResponse(
|
||||
None, None, None, None, f"Unable to connect to {self.endpoint}."
|
||||
)
|
||||
|
||||
async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
||||
|
||||
Reference in New Issue
Block a user