fix(lnpay): return checking_id from create_invoice (#4295)
What changed, and why it matters
This commit fixes a bug in the LNPay wallet integration where newly created Lightning invoices were not returning their internal tracking ID ('checking_id'). Without this ID, LNbits could not reliably match future payment updates to the correct invoice, which can lead to invoices being stuck as 'pending' indefinitely or being incorrectly tracked. The fix is a one-line addition that includes the invoice ID in the response, plus a new unit test to prevent regression.
Review other wallet backends in lnbits/wallets/ for similar omissions of checking_id in create_invoice responses, and ensure payment-status polling logic handles missing checking_id defensively.
Security signals we found
Missing correlation identifier in payment response
Potential invoice state desynchronization between LNbits and LNPay backend
Regression test added for payment identifier handling
Evidence from the diff
In lnbits/wallets/lnpay.py, the LNPayWallet.create_invoice method was returning an InvoiceResponse with ok=True and payment_request set, but omitted the checking_id field. The LNbits wallet abstraction expects create_invoice to return a stable checking_id so that downstream payment-status polling and webhook handling can correlate responses with pending invoices. The patch adds checking_id=data[‘id’] to the returned InvoiceResponse. A unit test verifies that the response now carries the checking_id and that the invoice ID is appended to pending_invoices.
Changed components
lnbits/wallets/lnpay.pyLNPayWallet.create_invoiceInvoiceResponse constructionInspect captured patch +22 / −0
### lnbits/wallets/lnpay.py
@@ -98,6 +98,7 @@ async def create_invoice(
self.pending_invoices.append(data["id"])
return InvoiceResponse(
ok=True,
+ checking_id=data["id"],
payment_request=data["payment_request"],
)
return InvoiceResponse(
### tests/unit/test_wallet_payment_ambiguity.py
@@ -353,6 +353,27 @@ async def test_lnpay_malformed_payment_response_is_pending(mocker: MockerFixture
assert response.ok is None
+@pytest.mark.anyio
+async def test_lnpay_create_invoice_returns_checking_id(mocker: MockerFixture):
+ wallet = object.__new__(LNPayWallet)
+ wallet.wallet_key = "wallet-key"
+ wallet.pending_invoices = []
+ cast(Any, wallet).client = SimpleNamespace(
+ post=mocker.AsyncMock(
+ return_value=_response(
+ 201, json={"id": "lntx_abc", "payment_request": "lnbc1"}
+ )
+ )
+ )
+
+ response = await wallet.create_invoice(1_000, memo="test")
+
+ assert response.ok is True
+ assert response.checking_id == "lntx_abc"
+ assert response.payment_request == "lnbc1"
+ assert wallet.pending_invoices == ["lntx_abc"]
+
+
@pytest.mark.anyio
@pytest.mark.parametrize("wallet_class", [LnTipsWallet, OpenNodeWallet, ZBDWallet])
@pytest.mark.parametrize(Why this scored 34/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.