invoices, order handling, db updates
This commit is contained in:
9
misc/filters.py
Normal file
9
misc/filters.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from aiogram.filters import BaseFilter
|
||||
from aiogram.types import InlineQuery
|
||||
|
||||
from config import VERIFIED_ACCOUNTS
|
||||
|
||||
|
||||
class IsVerified(BaseFilter):
|
||||
async def __call__(self, inline_query: InlineQuery) -> bool:
|
||||
return inline_query.from_user.id in VERIFIED_ACCOUNTS
|
||||
@@ -0,0 +1,34 @@
|
||||
from typing import Optional
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
placeholder_kb = InlineKeyboardBuilder(
|
||||
[[InlineKeyboardButton(text="🍃", callback_data="...")]]
|
||||
).as_markup()
|
||||
|
||||
|
||||
def customer_contacts(
|
||||
user_id: int, has_mention: bool, mention: Optional[str] = None
|
||||
) -> InlineKeyboardMarkup:
|
||||
btns: list[list[InlineKeyboardButton]] = []
|
||||
(
|
||||
btns.append(
|
||||
[InlineKeyboardButton(text="👤 Перейти", url=f"https://t.me/{mention}")]
|
||||
)
|
||||
if has_mention
|
||||
else None
|
||||
)
|
||||
btns.append(
|
||||
[
|
||||
InlineKeyboardButton(text="✍️", url=f"tg://openmessage?user_id={user_id}"),
|
||||
InlineKeyboardButton(text="✍️", url=f"tg://user?id={user_id}"),
|
||||
]
|
||||
)
|
||||
|
||||
return InlineKeyboardBuilder(btns).as_markup()
|
||||
|
||||
|
||||
def payment_link(url: str) -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardBuilder(
|
||||
[[InlineKeyboardButton(text="💸 Оплатить", url=url)]]
|
||||
).as_markup()
|
||||
|
||||
@@ -214,7 +214,7 @@ def order_specs_confirmation(order_id: int) -> InlineKeyboardMarkup:
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="🟢 Перейти к оплате",
|
||||
text="🟢 Подтвердить",
|
||||
callback_data=f"payment:{order_id}",
|
||||
)
|
||||
],
|
||||
|
||||
@@ -5,3 +5,8 @@ class CheckoutStorage(StatesGroup):
|
||||
name = State()
|
||||
phone = State()
|
||||
address = State()
|
||||
confirmation = State()
|
||||
|
||||
|
||||
class PaymentStorage(StatesGroup):
|
||||
refresh = State()
|
||||
|
||||
@@ -18,8 +18,3 @@ def get_order_item_list(cart: CartDTO):
|
||||
text += f"\n━━━━━━━━━━━━━━\n💰 Итого: {cart.total}₽"
|
||||
|
||||
return text
|
||||
|
||||
|
||||
# def get_order_notification(cart: CartDTO):
|
||||
# text
|
||||
# FIXME
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import base64
|
||||
import json
|
||||
from typing import Any
|
||||
import phonenumbers
|
||||
from phonenumbers import NumberParseException
|
||||
|
||||
@@ -8,3 +11,17 @@ def is_valid_phone(phone: str, region="RU") -> bool:
|
||||
return phonenumbers.is_valid_number(parsed)
|
||||
except NumberParseException:
|
||||
return False
|
||||
|
||||
|
||||
def dict_to_b64(payload: dict) -> str:
|
||||
json_str = json.dumps(payload, separators=(",", ":"))
|
||||
json_bytes = json_str.encode("utf-8")
|
||||
b64 = base64.urlsafe_b64encode(json_bytes).decode("ascii")
|
||||
return b64.rstrip("=")
|
||||
|
||||
|
||||
def b64_to_dict(payload: str) -> dict["str", Any]:
|
||||
padding = "=" * (-len(payload) % 4)
|
||||
payload += padding
|
||||
json_bytes = base64.urlsafe_b64decode(payload)
|
||||
return json.loads(json_bytes.decode("utf-8"))
|
||||
|
||||
Reference in New Issue
Block a user