-
Notifications
You must be signed in to change notification settings - Fork 14
/
models.py
116 lines (90 loc) · 2.85 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from typing import Optional
from fastapi import Query, Request
from lnurl import Lnurl
from lnurl import encode as lnurl_encode
from pydantic import BaseModel, Field, validator
class CreateWithdrawPay(BaseModel):
pay_link: str
class CreateTposInvoice(BaseModel):
amount: int = Query(..., ge=1)
memo: Optional[str] = Query(None)
details: Optional[dict] = Query(None)
tip_amount: Optional[int] = Query(None, ge=1)
user_lnaddress: Optional[str] = Query(None)
class CreateTposData(BaseModel):
wallet: Optional[str]
name: Optional[str]
currency: Optional[str]
tax_inclusive: bool = Field(True)
tax_default: float = Field(None)
tip_options: str = Field("[]")
tip_wallet: str = Field("")
withdraw_time: int = Field(0)
withdraw_between: int = Field(10, ge=1)
withdraw_limit: Optional[int] = Field(None, ge=1)
withdraw_pin: Optional[int] = Field(None, ge=1)
withdraw_time_option: Optional[str] = Field(None)
withdraw_premium: Optional[float] = Field(None)
withdraw_pin_disabled: bool = Field(False)
lnaddress: bool = Field(False)
lnaddress_cut: Optional[int] = Field(0)
class TposClean(BaseModel):
id: str
name: str
currency: str
tax_inclusive: bool
tax_default: Optional[float] = None
withdraw_time: int
withdraw_between: int
withdraw_limit: Optional[int] = None
withdraw_time_option: Optional[str] = None
withdraw_premium: Optional[float] = None
withdraw_pin_disabled: Optional[bool] = None
withdrawn_amount: int = 0
lnaddress: Optional[bool] = None
lnaddress_cut: int = 0
items: Optional[str] = None
tip_options: Optional[str] = None
@property
def withdraw_maximum(self) -> int:
if not self.withdraw_limit:
return 0
return self.withdraw_limit - self.withdrawn_amount
class Tpos(TposClean, BaseModel):
wallet: str
tip_wallet: Optional[str] = None
withdraw_pin: Optional[int] = None
class LnurlCharge(BaseModel):
id: str
tpos_id: str
amount: int = Field(None)
claimed: bool = Field(False)
def lnurl(self, req: Request) -> Lnurl:
url = str(
req.url_for(
"tpos.tposlnurlcharge",
lnurlcharge_id=self.id,
amount=self.amount,
)
)
return lnurl_encode(url)
class HashCheck(BaseModel):
hash: bool
lnurl: bool
class PayLnurlWData(BaseModel):
lnurl: str
class LNaddress(BaseModel):
lnaddress: str
class Item(BaseModel):
image: Optional[str]
price: float
title: str
description: Optional[str]
tax: Optional[float] = Field(0, ge=0.0)
disabled: bool = False
categories: Optional[list[str]] = []
@validator("tax", pre=True, always=True)
def set_default_tax(cls, v):
return v or 0
class CreateUpdateItemData(BaseModel):
items: list[Item]