- Add stripe_customer_id and stripe_subscription_id fields to User model - Add Stripe config settings (secret key, publishable key, price ID, webhook secret) - Create billing API endpoints: checkout session, webhook handler, portal, status - Add frontend Billing page with upgrade/manage subscription UI - Add billing route and Pro nav link - Add stripe dependency to requirements
37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy import String, Boolean, DateTime, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
email: Mapped[str] = mapped_column(String(255), unique=True, index=True)
|
|
name: Mapped[str] = mapped_column(String(255))
|
|
hashed_password: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
is_pro: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
|
|
)
|
|
|
|
# Stripe
|
|
stripe_customer_id: Mapped[str | None] = mapped_column(String(255), nullable=True, unique=True)
|
|
stripe_subscription_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
|
|
# Spotify OAuth
|
|
spotify_id: Mapped[str | None] = mapped_column(String(255), nullable=True, unique=True)
|
|
spotify_access_token: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
spotify_refresh_token: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
# Relationships
|
|
playlists: Mapped[list["Playlist"]] = relationship(back_populates="user", cascade="all, delete-orphan")
|
|
recommendations: Mapped[list["Recommendation"]] = relationship(back_populates="user", cascade="all, delete-orphan")
|
|
|
|
|
|
from app.models.playlist import Playlist # noqa: E402
|
|
from app.models.recommendation import Recommendation # noqa: E402
|