feat: implement billing system with Pally integration
- Added billing models and repository for handling bills. - Introduced BillingService to manage payment initiation and bill creation. - Updated user service to remove ticket-related functionality. - Refactored settings to include new billing-related fields. - Removed ticket-related handlers and schemas. - Added new billing handlers for processing payments. - Updated database schema with new bills table and status enum. - Enhanced utility functions to calculate prices considering discounts. - Introduced prehandling for non-private messages. - Updated main application to initialize new billing services and repositories.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from .tickets import Ticket
|
||||
from .bills import Bill
|
||||
from .users import User
|
||||
|
||||
__all__ = ["Ticket", "User"]
|
||||
__all__ = ["Bill", "User"]
|
||||
|
||||
28
db/models/bills.py
Normal file
28
db/models/bills.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import BIGINT, INTEGER, Enum, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from db.base import Base
|
||||
from misc.pally import BillStatus
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from db.models.users import User
|
||||
|
||||
|
||||
class Bill(Base):
|
||||
__tablename__ = "bills"
|
||||
|
||||
id: Mapped[int] = mapped_column(
|
||||
BIGINT, autoincrement=True, unique=True, nullable=False, primary_key=True
|
||||
)
|
||||
creator_id: Mapped[int] = mapped_column(BIGINT, ForeignKey("users.id"), nullable=False)
|
||||
amount: Mapped[int] = mapped_column(INTEGER, nullable=False)
|
||||
status: Mapped[BillStatus] = mapped_column(
|
||||
Enum(BillStatus), nullable=False, default=BillStatus.NEW
|
||||
)
|
||||
|
||||
user: Mapped["User"] = relationship(
|
||||
"User",
|
||||
back_populates="bills",
|
||||
)
|
||||
@@ -1,25 +0,0 @@
|
||||
from enum import Enum as VanillaEnum
|
||||
|
||||
from sqlalchemy import BIGINT, INTEGER, Enum
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from db.base import Base
|
||||
|
||||
|
||||
class TicketStatus(VanillaEnum):
|
||||
OPEN = "OPEN"
|
||||
CLOSED = "CLOSED"
|
||||
PENDING = "PENDING"
|
||||
|
||||
|
||||
class Ticket(Base):
|
||||
__tablename__ = "tickets"
|
||||
|
||||
id: Mapped[int] = mapped_column(
|
||||
INTEGER, autoincrement=True, unique=True, nullable=False, primary_key=True
|
||||
)
|
||||
creator_id: Mapped[int] = mapped_column(BIGINT, nullable=False)
|
||||
status: Mapped[TicketStatus] = mapped_column(
|
||||
Enum(TicketStatus), nullable=False, default=TicketStatus.PENDING
|
||||
)
|
||||
thread_id: Mapped[int] = mapped_column(BIGINT, nullable=True, unique=True)
|
||||
@@ -1,8 +1,13 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import BIGINT, INTEGER, TEXT
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from db.base import Base
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from db.models.bills import Bill
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
@@ -11,3 +16,9 @@ class User(Base):
|
||||
referal_id: Mapped[int] = mapped_column(BIGINT, nullable=True)
|
||||
subscription_link: Mapped[str] = mapped_column(TEXT, nullable=True, unique=True)
|
||||
balance: Mapped[int] = mapped_column(INTEGER, nullable=False, default=0)
|
||||
|
||||
bills: Mapped[list["Bill"]] = relationship(
|
||||
"Bill",
|
||||
back_populates="user",
|
||||
cascade="all, delete",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user