lnbits-legend/lnbits/extensions/satspay/models.py

54 lines
1.3 KiB
Python
Raw Normal View History

2021-12-30 16:21:44 +00:00
import time
2021-10-14 10:02:02 +01:00
from sqlite3 import Row
2021-10-14 22:30:29 +01:00
from typing import Optional
2021-12-30 16:21:44 +00:00
2021-10-14 11:45:56 +01:00
from fastapi.param_functions import Query
from pydantic import BaseModel
2021-10-14 10:02:02 +01:00
2021-10-17 18:33:29 +01:00
2021-10-14 11:45:56 +01:00
class CreateCharge(BaseModel):
onchainwallet: str = Query(None)
lnbitswallet: str = Query(None)
description: str = Query(...)
webhook: str = Query(None)
completelink: str = Query(None)
completelinktext: str = Query(None)
time: int = Query(..., ge=1)
amount: int = Query(..., ge=1)
2021-10-14 10:02:02 +01:00
2021-10-17 18:33:29 +01:00
2021-10-14 11:45:56 +01:00
class Charges(BaseModel):
2021-10-14 10:02:02 +01:00
id: str
user: str
2021-10-14 22:30:29 +01:00
description: Optional[str]
onchainwallet: Optional[str]
onchainaddress: Optional[str]
lnbitswallet: Optional[str]
2021-12-30 16:21:44 +00:00
payment_request: Optional[str]
payment_hash: Optional[str]
2021-10-14 22:30:29 +01:00
webhook: Optional[str]
completelink: Optional[str]
completelinktext: Optional[str] = "Back to Merchant"
2021-10-14 10:02:02 +01:00
time: int
amount: int
balance: int
timestamp: int
@classmethod
def from_row(cls, row: Row) -> "Charges":
return cls(**dict(row))
@property
def time_elapsed(self):
if (self.timestamp + (self.time * 60)) >= time.time():
return False
else:
return True
@property
def paid(self):
if self.balance >= self.amount:
return True
else:
return False