mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-01-19 05:33:47 +01:00
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:
parent
352fd23c0b
commit
d44339b018
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user