invoices, order handling, db updates

This commit is contained in:
2026-02-14 23:09:21 +07:00
parent a3aaafd7ac
commit 50b1a8f80c
28 changed files with 508 additions and 44 deletions

View File

@@ -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"))