REFACTOR ALL APIs fix 1
This commit is contained in:
@@ -587,16 +587,48 @@ async def upgrade_subscription_plan(
|
||||
detail=validation.get("reason", "Cannot upgrade to this plan")
|
||||
)
|
||||
|
||||
# TODO: Implement actual plan upgrade logic
|
||||
# This would involve:
|
||||
# 1. Update subscription in database
|
||||
# 2. Process payment changes
|
||||
# 3. Update billing cycle
|
||||
# 4. Send notifications
|
||||
# Actually update the subscription plan in the database
|
||||
from app.core.config import settings
|
||||
from app.repositories.subscription_repository import SubscriptionRepository
|
||||
from app.models.tenants import Subscription
|
||||
from shared.database.base import create_database_manager
|
||||
|
||||
database_manager = create_database_manager(settings.DATABASE_URL, "tenant-service")
|
||||
|
||||
async with database_manager.get_session() as session:
|
||||
subscription_repo = SubscriptionRepository(Subscription, session)
|
||||
|
||||
# Get the active subscription for this tenant
|
||||
active_subscription = await subscription_repo.get_active_subscription(str(tenant_id))
|
||||
|
||||
if not active_subscription:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="No active subscription found for this tenant"
|
||||
)
|
||||
|
||||
# Update the subscription plan
|
||||
updated_subscription = await subscription_repo.update_subscription_plan(
|
||||
str(active_subscription.id),
|
||||
new_plan
|
||||
)
|
||||
|
||||
# Commit the changes
|
||||
await session.commit()
|
||||
|
||||
logger.info("Subscription plan upgraded successfully",
|
||||
tenant_id=str(tenant_id),
|
||||
subscription_id=str(active_subscription.id),
|
||||
old_plan=active_subscription.plan,
|
||||
new_plan=new_plan,
|
||||
user_id=current_user["user_id"])
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"message": f"Plan upgrade to {new_plan} initiated",
|
||||
"message": f"Plan successfully upgraded to {new_plan}",
|
||||
"old_plan": active_subscription.plan,
|
||||
"new_plan": new_plan,
|
||||
"new_monthly_price": updated_subscription.monthly_price,
|
||||
"validation": validation
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user