mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-06 21:23:05 +02: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
|
@property
|
||||||
def pending(self) -> bool:
|
def pending(self) -> bool:
|
||||||
return self.paid is not True
|
return self.paid is None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def failed(self) -> bool:
|
def failed(self) -> bool:
|
||||||
|
@ -19,9 +19,11 @@ from lnbits.settings import settings
|
|||||||
|
|
||||||
from .base import (
|
from .base import (
|
||||||
InvoiceResponse,
|
InvoiceResponse,
|
||||||
|
PaymentFailedStatus,
|
||||||
PaymentPendingStatus,
|
PaymentPendingStatus,
|
||||||
PaymentResponse,
|
PaymentResponse,
|
||||||
PaymentStatus,
|
PaymentStatus,
|
||||||
|
PaymentSuccessStatus,
|
||||||
StatusResponse,
|
StatusResponse,
|
||||||
Wallet,
|
Wallet,
|
||||||
)
|
)
|
||||||
@ -118,8 +120,11 @@ class FakeWallet(Wallet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
||||||
paid = checking_id in self.paid_invoices
|
if checking_id in self.paid_invoices:
|
||||||
return PaymentStatus(paid)
|
return PaymentSuccessStatus()
|
||||||
|
if checking_id in list(self.payment_secrets.keys()):
|
||||||
|
return PaymentPendingStatus()
|
||||||
|
return PaymentFailedStatus()
|
||||||
|
|
||||||
async def get_payment_status(self, _: str) -> PaymentStatus:
|
async def get_payment_status(self, _: str) -> PaymentStatus:
|
||||||
return PaymentPendingStatus()
|
return PaymentPendingStatus()
|
||||||
|
@ -9,6 +9,7 @@ from lnbits.settings import settings
|
|||||||
|
|
||||||
from .base import (
|
from .base import (
|
||||||
InvoiceResponse,
|
InvoiceResponse,
|
||||||
|
PaymentFailedStatus,
|
||||||
PaymentPendingStatus,
|
PaymentPendingStatus,
|
||||||
PaymentResponse,
|
PaymentResponse,
|
||||||
PaymentStatus,
|
PaymentStatus,
|
||||||
@ -121,9 +122,16 @@ class LNbitsWallet(Wallet):
|
|||||||
r = await self.client.get(
|
r = await self.client.get(
|
||||||
url=f"/api/v1/payments/{checking_id}",
|
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 PaymentPendingStatus()
|
||||||
return PaymentStatus(r.json()["paid"])
|
if data.get("paid", False) is True:
|
||||||
|
return PaymentSuccessStatus()
|
||||||
|
return PaymentFailedStatus()
|
||||||
except Exception:
|
except Exception:
|
||||||
return PaymentPendingStatus()
|
return PaymentPendingStatus()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user