Add auto-renewal and cancellation handling for tribute subscriptions
- Implemented a new method to handle expired tribute subscriptions, automatically renewing them if no cancellation was received. - Added functionality to manage tribute subscription cancellations, setting a grace period and notifying users accordingly. - Updated localization files to include messages for auto-renewal and cancellation notifications in both English and Russian, enhancing user communication.
This commit is contained in:
@@ -170,3 +170,17 @@ async def get_financial_statistics(session: AsyncSession) -> Dict[str, Any]:
|
||||
"all_time_revenue": float(all_amount),
|
||||
"today_payments_count": today_payments_count
|
||||
}
|
||||
|
||||
|
||||
async def get_last_tribute_payment_duration(session: AsyncSession, user_id: int) -> Optional[int]:
|
||||
"""Get duration in months from the last successful tribute payment for a user."""
|
||||
stmt = select(Payment.subscription_duration_months).where(
|
||||
and_(
|
||||
Payment.user_id == user_id,
|
||||
Payment.provider == 'tribute',
|
||||
Payment.status == 'succeeded'
|
||||
)
|
||||
).order_by(Payment.created_at.desc()).limit(1)
|
||||
|
||||
result = await session.execute(stmt)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
@@ -31,6 +31,16 @@ async def get_subscription_by_panel_subscription_uuid(
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def get_active_subscriptions_for_user(session: AsyncSession, user_id: int) -> List[Subscription]:
|
||||
"""Get all active subscriptions for a user."""
|
||||
stmt = select(Subscription).where(
|
||||
Subscription.user_id == user_id,
|
||||
Subscription.is_active == True
|
||||
).order_by(Subscription.end_date.desc())
|
||||
result = await session.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
|
||||
async def update_subscription(
|
||||
session: AsyncSession, subscription_id: int,
|
||||
update_data: Dict[str, Any]) -> Optional[Subscription]:
|
||||
|
||||
Reference in New Issue
Block a user