invoices, order handling, db updates
This commit is contained in:
@@ -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