Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions app/api/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
)
from app.db.models import DBTeam, DBSystemSecret, DBProduct, DBTeamProduct
from app.schemas.models import (
PricingTableSession,
SubscriptionCreate,
SubscriptionResponse,
PortalRequest,
Expand All @@ -27,7 +26,6 @@
decode_stripe_event,
create_portal_session,
create_stripe_customer,
get_pricing_table_secret,
create_zero_rated_stripe_subscription,
get_subscribed_products_for_customer,
cancel_subscription,
Expand Down Expand Up @@ -161,50 +159,6 @@ async def get_portal(
)


@router.get(
"/teams/{team_id}/pricing-table-session",
dependencies=[Depends(get_role_min_specific_team_admin)],
response_model=PricingTableSession,
)
async def get_pricing_table_session(team_id: int, db: Session = Depends(get_db)):
"""
Create a Stripe Customer Session client secret for team subscription management.
If the team doesn't have a Stripe customer ID, one will be created first.

Args:
team_id: The ID of the team to create the customer session for

Returns:
JSON response containing the client secret
"""
# Get the team
team = db.query(DBTeam).filter(DBTeam.id == team_id).first()
if not team:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Team not found"
)

try:
# Create Stripe customer if one doesn't exist
if not team.stripe_customer_id:
logger.info(f"Creating Stripe customer for team {team.id}")
team.stripe_customer_id = await create_stripe_customer(team)
db.add(team)
db.commit()

logger.info(f"Stripe ID is {team.stripe_customer_id}")
# Create customer session using the service
client_secret = await get_pricing_table_secret(team.stripe_customer_id)

return PricingTableSession(client_secret=client_secret)
except Exception as e:
logger.error(f"Error creating customer session: {str(e)}")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Error creating customer session",
)


@router.post(
"/teams/{team_id}/subscriptions",
dependencies=[Depends(get_role_min_system_admin)],
Comment on lines 160 to 164

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in commit 45f20c4: removed the obsolete /billing/teams/{id}/pricing-table-session tests from tests/test_billing.py and deleted tests/test_pricing_tables.py.

Expand Down
208 changes: 0 additions & 208 deletions app/api/pricing_tables.py

This file was deleted.

4 changes: 0 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
billing,
budgets,
limits,
pricing_tables,
private_ai_keys,
products,
public,
Expand Down Expand Up @@ -176,9 +175,6 @@ async def get_version():
app.include_router(teams.router, prefix="/teams", tags=["teams"])
app.include_router(billing.router, prefix="/billing", tags=["billing"])
app.include_router(products.router, prefix="/products", tags=["products"])
app.include_router(
pricing_tables.router, prefix="/pricing-tables", tags=["pricing-tables"]
)
app.include_router(limits.router, prefix="/limits", tags=["limits"])
app.include_router(budgets.router, prefix="/budgets", tags=["budgets"])
app.include_router(spend.router, prefix="/spend", tags=["spend"])
Comment on lines 175 to 180

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already implemented in commit 45f20c4: deleted tests/test_pricing_tables.py entirely (777 lines) which tested the removed /pricing-tables router.

Expand Down
25 changes: 0 additions & 25 deletions app/schemas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,31 +575,6 @@ class CheckoutSessionCreate(BaseModel):
price_lookup_token: str


class PricingTableSession(BaseModel):
client_secret: str
model_config = ConfigDict(from_attributes=True)


class PricingTableCreate(BaseModel):
pricing_table_id: str
table_type: Literal["standard", "always_free", "gpt"] = "standard"
stripe_publishable_key: Optional[str] = (
None # Optional on create, defaults to system config
)
model_config = ConfigDict(from_attributes=True)


class PricingTableResponse(BaseModel):
pricing_table_id: str
stripe_publishable_key: str # Always included in response
updated_at: datetime
model_config = ConfigDict(from_attributes=True)


class PricingTablesResponse(BaseModel):
tables: Dict[str, PricingTableResponse | None]
model_config = ConfigDict(from_attributes=True)


class SubscriptionCreate(BaseModel):
product_id: str # Stripe product ID
Expand Down
23 changes: 0 additions & 23 deletions app/services/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,26 +357,3 @@ async def get_customer_from_pi(payment_intent: str) -> str:
return payment_intent.customer


async def get_pricing_table_secret(customer_id: str) -> str:
"""
Create a Stripe Customer Session client secret for a customer.

Args:
customer_id: The Stripe customer ID to create the session for

Returns:
str: The customer session client secret
"""
try:
# Create the customer session
session = stripe.CustomerSession.create(
customer=customer_id, components={"pricing_table": {"enabled": True}}
)

return session.client_secret
except Exception as e:
logger.error(f"Error creating customer session: {str(e)}")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Error creating customer session",
)
Loading
Loading