forked from lnbits/tpos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
117 lines (95 loc) · 3.08 KB
/
models.py
File metadata and controls
117 lines (95 loc) · 3.08 KB
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
117
from time import time
from fastapi import Query
from pydantic import BaseModel, Field, validator
class PayLnurlWData(BaseModel):
lnurl: str
class CreateWithdrawPay(BaseModel):
pay_link: str
class CreateTposInvoice(BaseModel):
amount: int = Query(..., ge=1)
memo: str | None = Query(None)
exchange_rate: float | None = Query(None, ge=0.0)
details: dict | None = Query(None)
tip_amount: int | None = Query(None, ge=1)
user_lnaddress: str | None = Query(None)
internal_memo: str | None = Query(None, max_length=512)
pay_in_fiat: bool = Query(False)
amount_fiat: float | None = Query(None, ge=0.0)
tip_amount_fiat: float | None = Query(None, ge=0.0)
class CreateTposData(BaseModel):
wallet: str | None
name: str | None
currency: str | None
tax_inclusive: bool = Field(True)
tax_default: float = Field(0.0)
tip_options: str = Field("[]")
tip_wallet: str = Field("")
withdraw_time: int = Field(0)
withdraw_between: int = Field(10, ge=1)
withdraw_limit: int | None = Field(None, ge=1)
withdraw_time_option: str | None = Field(None)
withdraw_premium: float | None = Field(None)
lnaddress: bool = Field(False)
lnaddress_cut: int | None = Field(0)
enable_receipt_print: bool = Query(False)
business_name: str | None
business_address: str | None
business_vat_id: str | None
fiat_provider: str | None = Field(None)
class TposClean(BaseModel):
id: str
name: str
currency: str
tax_inclusive: bool
tax_default: float | None = None
withdraw_time: int
withdraw_between: int
withdraw_limit: int | None = None
withdraw_time_option: str | None = None
withdraw_premium: float | None = None
withdrawn_amount: int = 0
lnaddress: bool | None = None
lnaddress_cut: int = 0
items: str | None = None
tip_options: str | None = None
enable_receipt_print: bool
business_name: str | None = None
business_address: str | None = None
business_vat_id: str | None = None
fiat_provider: str | None = None
@property
def withdraw_maximum(self) -> int:
if not self.withdraw_limit:
return 0
return self.withdraw_limit - self.withdrawn_amount
@property
def can_withdraw(self) -> bool:
now = int(time())
seconds = (
self.withdraw_between * 60
if self.withdraw_time_option != "secs"
else self.withdraw_between
)
last_withdraw_time = self.withdraw_time - now
return last_withdraw_time < seconds
class Tpos(TposClean, BaseModel):
wallet: str
tip_wallet: str | None = None
class LnurlCharge(BaseModel):
id: str
tpos_id: str
amount: int = 0
claimed: bool = False
class Item(BaseModel):
image: str | None
price: float
title: str
description: str | None
tax: float | None = Field(0, ge=0.0)
disabled: bool = False
categories: list[str] | None = []
@validator("tax", pre=True, always=True)
def set_default_tax(cls, v):
return v or 0
class CreateUpdateItemData(BaseModel):
items: list[Item]