fix: pending property for PaymentStatus (#2324)

* fix: pending property for PaymentStatus

* fix: invoice status

* fix: check pending status from the payment details

* refactor: make condition more explicit
This commit is contained in:
Vlad Stan 2024-03-14 14:38:10 +02:00 committed by GitHub
parent 352fd23c0b
commit d44339b018
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 5 deletions

View File

@ -35,7 +35,7 @@ class PaymentStatus(NamedTuple):
@property
def pending(self) -> bool:
return self.paid is not True
return self.paid is None
@property
def failed(self) -> bool:

View File

@ -19,9 +19,11 @@ from lnbits.settings import settings
from .base import (
InvoiceResponse,
PaymentFailedStatus,
PaymentPendingStatus,
PaymentResponse,
PaymentStatus,
PaymentSuccessStatus,
StatusResponse,
Wallet,
)
@ -118,8 +120,11 @@ class FakeWallet(Wallet):
)
async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
paid = checking_id in self.paid_invoices
return PaymentStatus(paid)
if checking_id in self.paid_invoices:
return PaymentSuccessStatus()
if checking_id in list(self.payment_secrets.keys()):
return PaymentPendingStatus()
return PaymentFailedStatus()
async def get_payment_status(self, _: str) -> PaymentStatus:
return PaymentPendingStatus()

View File

@ -9,6 +9,7 @@ from lnbits.settings import settings
from .base import (
InvoiceResponse,
PaymentFailedStatus,
PaymentPendingStatus,
PaymentResponse,
PaymentStatus,
@ -121,9 +122,16 @@ class LNbitsWallet(Wallet):
r = await self.client.get(
url=f"/api/v1/payments/{checking_id}",
)
if r.is_error:
r.raise_for_status()
data = r.json()
details = data.get("details", None)
if details and details.get("pending", False) is True:
return PaymentPendingStatus()
return PaymentStatus(r.json()["paid"])
if data.get("paid", False) is True:
return PaymentSuccessStatus()
return PaymentFailedStatus()
except Exception:
return PaymentPendingStatus()