create backwards compatibility for <=v1.0 (#3041)

in v0.12.12, the key is "payment_request" instead of the new "bolt11"
This commit is contained in:
PatMulligan 2025-03-12 12:27:24 +01:00 committed by GitHub
parent f7b3444be4
commit d7f0f4da0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -87,13 +87,15 @@ class LNbitsWallet(Wallet):
r.raise_for_status()
data = r.json()
if r.is_error or "bolt11" not in data:
# Backwards compatibility for pre-v1 which used the key "payment_request"
payment_str = data.get("bolt11") or data.get("payment_request")
if r.is_error or not payment_str:
error_message = data["detail"] if "detail" in data else r.text
return InvoiceResponse(
False, None, None, f"Server error: '{error_message}'"
)
return InvoiceResponse(True, data["checking_id"], data["bolt11"], None)
return InvoiceResponse(True, data["checking_id"], payment_str, None)
except json.JSONDecodeError:
return InvoiceResponse(
False, None, None, "Server error: 'invalid json response'"