Private
Public Access
forked from FOSS/AutoShop-Djimbo-Simple
feat: add Lolzteam payment integration
This commit is contained in:
@@ -3,6 +3,7 @@ from typing import Any, Dict, Optional
|
||||
|
||||
from sqlalchemy import Integer, String, Float
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from tgbot.database.core import Base
|
||||
from tgbot.database.entities import Payments
|
||||
@@ -22,11 +23,81 @@ class PaymentsModel(Base):
|
||||
String(16), nullable=False, default="False"
|
||||
)
|
||||
|
||||
# Оплата через Lolzteam
|
||||
lolzteam_token: Mapped[str] = mapped_column(String, nullable=False, default="None")
|
||||
lolzteam_merchant_id: Mapped[Optional[int]] = mapped_column(
|
||||
Integer, nullable=True, default=None
|
||||
)
|
||||
status_lolzteam: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, default="False"
|
||||
)
|
||||
|
||||
|
||||
ModelBase = Payments
|
||||
BaseModel = Payments
|
||||
|
||||
|
||||
async def ensure_payments_schema(conn: AsyncConnection) -> None:
|
||||
columns = (
|
||||
await conn.exec_driver_sql("PRAGMA table_info(storage_payments)")
|
||||
).mappings().all()
|
||||
|
||||
if not columns:
|
||||
return
|
||||
|
||||
merchant_column = next(
|
||||
(column for column in columns if column["name"] == "lolzteam_merchant_id"),
|
||||
None,
|
||||
)
|
||||
|
||||
if merchant_column is None or merchant_column["notnull"] == 0:
|
||||
return
|
||||
|
||||
await conn.exec_driver_sql(
|
||||
"ALTER TABLE storage_payments RENAME TO storage_payments__legacy"
|
||||
)
|
||||
await conn.exec_driver_sql(
|
||||
"""
|
||||
CREATE TABLE storage_payments (
|
||||
id INTEGER NOT NULL,
|
||||
cryptobot_token VARCHAR NOT NULL,
|
||||
stars_course FLOAT NOT NULL,
|
||||
status_cryptobot VARCHAR(16) NOT NULL,
|
||||
status_stars VARCHAR(16) NOT NULL,
|
||||
lolzteam_token VARCHAR NOT NULL,
|
||||
lolzteam_merchant_id INTEGER,
|
||||
status_lolzteam VARCHAR(16) NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
)
|
||||
"""
|
||||
)
|
||||
await conn.exec_driver_sql(
|
||||
"""
|
||||
INSERT INTO storage_payments (
|
||||
id,
|
||||
cryptobot_token,
|
||||
stars_course,
|
||||
status_cryptobot,
|
||||
status_stars,
|
||||
lolzteam_token,
|
||||
lolzteam_merchant_id,
|
||||
status_lolzteam
|
||||
)
|
||||
SELECT
|
||||
id,
|
||||
cryptobot_token,
|
||||
stars_course,
|
||||
status_cryptobot,
|
||||
status_stars,
|
||||
lolzteam_token,
|
||||
lolzteam_merchant_id,
|
||||
status_lolzteam
|
||||
FROM storage_payments__legacy
|
||||
"""
|
||||
)
|
||||
await conn.exec_driver_sql("DROP TABLE storage_payments__legacy")
|
||||
|
||||
|
||||
class Paymentsx(BaseRepository[PaymentsModel, Payments]):
|
||||
# Подключение модели платежных настроек
|
||||
def __init__(self):
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# - *- coding: utf- 8 - *-
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -40,6 +41,12 @@ class Payments:
|
||||
status_cryptobot: str
|
||||
status_stars: str
|
||||
|
||||
# Оплата через Lolzteam
|
||||
lolzteam_token: str
|
||||
lolzteam_merchant_id: Optional[int]
|
||||
|
||||
status_lolzteam: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Purchase:
|
||||
|
||||
@@ -162,6 +162,10 @@ async def prepare_database() -> None:
|
||||
import tgbot.database.db_users # noqa: F401
|
||||
|
||||
async with engine.begin() as conn:
|
||||
from tgbot.database.db_payments import ensure_payments_schema
|
||||
|
||||
await ensure_payments_schema(conn)
|
||||
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
from tgbot.database.db_payments import Paymentsx
|
||||
|
||||
Reference in New Issue
Block a user