Add subcription feature
This commit is contained in:
@@ -199,9 +199,17 @@ class OnboardingRepository:
|
||||
self,
|
||||
user_id: str,
|
||||
step_name: str,
|
||||
step_data: Dict[str, Any]
|
||||
step_data: Dict[str, Any],
|
||||
auto_commit: bool = True
|
||||
) -> UserOnboardingProgress:
|
||||
"""Save data for a specific step without marking it as completed"""
|
||||
"""Save data for a specific step without marking it as completed
|
||||
|
||||
Args:
|
||||
user_id: User ID
|
||||
step_name: Name of the step
|
||||
step_data: Data to save
|
||||
auto_commit: Whether to auto-commit (set to False when used within UnitOfWork)
|
||||
"""
|
||||
try:
|
||||
# Get existing step or create new one
|
||||
existing_step = await self.get_user_step(user_id, step_name)
|
||||
@@ -221,7 +229,12 @@ class OnboardingRepository:
|
||||
).returning(UserOnboardingProgress)
|
||||
|
||||
result = await self.db.execute(stmt)
|
||||
await self.db.commit()
|
||||
|
||||
if auto_commit:
|
||||
await self.db.commit()
|
||||
else:
|
||||
await self.db.flush()
|
||||
|
||||
return result.scalars().first()
|
||||
else:
|
||||
# Create new step with data but not completed
|
||||
@@ -229,12 +242,14 @@ class OnboardingRepository:
|
||||
user_id=user_id,
|
||||
step_name=step_name,
|
||||
completed=False,
|
||||
step_data=step_data
|
||||
step_data=step_data,
|
||||
auto_commit=auto_commit
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error saving step data for {step_name}, user {user_id}: {e}")
|
||||
await self.db.rollback()
|
||||
if auto_commit:
|
||||
await self.db.rollback()
|
||||
raise
|
||||
|
||||
async def get_step_data(self, user_id: str, step_name: str) -> Optional[Dict[str, Any]]:
|
||||
@@ -246,6 +261,26 @@ class OnboardingRepository:
|
||||
logger.error(f"Error getting step data for {step_name}, user {user_id}: {e}")
|
||||
return None
|
||||
|
||||
async def get_subscription_parameters(self, user_id: str) -> Optional[Dict[str, Any]]:
|
||||
"""Get subscription parameters saved during onboarding for tenant creation"""
|
||||
try:
|
||||
step_data = await self.get_step_data(user_id, "user_registered")
|
||||
if step_data:
|
||||
# Extract subscription-related parameters
|
||||
subscription_params = {
|
||||
"subscription_plan": step_data.get("subscription_plan", "starter"),
|
||||
"billing_cycle": step_data.get("billing_cycle", "monthly"),
|
||||
"coupon_code": step_data.get("coupon_code"),
|
||||
"payment_method_id": step_data.get("payment_method_id"),
|
||||
"payment_customer_id": step_data.get("payment_customer_id"),
|
||||
"saved_at": step_data.get("saved_at")
|
||||
}
|
||||
return subscription_params
|
||||
return None
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting subscription parameters for user {user_id}: {e}")
|
||||
return None
|
||||
|
||||
async def get_completion_stats(self) -> Dict[str, Any]:
|
||||
"""Get completion statistics across all users"""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user