Enhance auto-renewal messaging and payment processing logic
- Introduced a new flag for auto-renew subscriptions to streamline messaging and avoid redundant configuration links. - Updated localization files to include a new message for auto-renewal notifications in both English and Russian. - Improved error handling and logging in the payment processing flow to ensure clarity and reliability during subscription renewals.
This commit is contained in:
@@ -58,6 +58,7 @@ async def process_successful_payment(session: AsyncSession, bot: Bot,
|
|||||||
subscription_months = int(subscription_months_str)
|
subscription_months = int(subscription_months_str)
|
||||||
payment_db_id = int(
|
payment_db_id = int(
|
||||||
payment_db_id_str) if payment_db_id_str and payment_db_id_str.isdigit() else None
|
payment_db_id_str) if payment_db_id_str and payment_db_id_str.isdigit() else None
|
||||||
|
is_auto_renew = bool(auto_renew_subscription_id_str and not payment_db_id)
|
||||||
promo_code_id = int(
|
promo_code_id = int(
|
||||||
promo_code_id_str
|
promo_code_id_str
|
||||||
) if promo_code_id_str and promo_code_id_str.isdigit() else None
|
) if promo_code_id_str and promo_code_id_str.isdigit() else None
|
||||||
@@ -199,6 +200,15 @@ async def process_successful_payment(session: AsyncSession, bot: Bot,
|
|||||||
user_lang = db_user.language_code if db_user and db_user.language_code else settings.DEFAULT_LANGUAGE
|
user_lang = db_user.language_code if db_user and db_user.language_code else settings.DEFAULT_LANGUAGE
|
||||||
_ = lambda key, **kwargs: i18n.gettext(user_lang, key, **kwargs)
|
_ = lambda key, **kwargs: i18n.gettext(user_lang, key, **kwargs)
|
||||||
|
|
||||||
|
# For auto-renew charges, avoid re-sending config link; send concise message
|
||||||
|
if is_auto_renew and final_end_date_for_user:
|
||||||
|
details_message = _(
|
||||||
|
"yookassa_auto_renewal",
|
||||||
|
months=subscription_months,
|
||||||
|
end_date=final_end_date_for_user.strftime('%Y-%m-%d'),
|
||||||
|
)
|
||||||
|
details_markup = None
|
||||||
|
else:
|
||||||
config_link = activation_details.get("subscription_url") or _(
|
config_link = activation_details.get("subscription_url") or _(
|
||||||
"config_link_not_available"
|
"config_link_not_available"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -196,8 +196,10 @@ class PanelWebhookService:
|
|||||||
if sub and sub.auto_renew_enabled and sub.provider != 'tribute':
|
if sub and sub.auto_renew_enabled and sub.provider != 'tribute':
|
||||||
try:
|
try:
|
||||||
ok = await subscription_service.charge_subscription_renewal(session, sub)
|
ok = await subscription_service.charge_subscription_renewal(session, sub)
|
||||||
|
# If initiation succeeded, suppress the 24h reminder by returning early
|
||||||
if ok:
|
if ok:
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
await session.rollback()
|
await session.rollback()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
@@ -211,6 +211,7 @@
|
|||||||
"subscription_expired_yesterday_notification": "👋 Hi, {user_name}!\n\n⏳ Your VPN subscription expired yesterday ({end_date}).\n\nPlease renew it using the button below.",
|
"subscription_expired_yesterday_notification": "👋 Hi, {user_name}!\n\n⏳ Your VPN subscription expired yesterday ({end_date}).\n\nPlease renew it using the button below.",
|
||||||
"tribute_subscription_cancelled": "🚨 <b>Subscription Cancelled</b>\n\nYour Tribute subscription has been cancelled. You have 24 hours to restore access, after which the subscription will be blocked.\n\nTo renew your subscription, press the button below.",
|
"tribute_subscription_cancelled": "🚨 <b>Subscription Cancelled</b>\n\nYour Tribute subscription has been cancelled. You have 24 hours to restore access, after which the subscription will be blocked.\n\nTo renew your subscription, press the button below.",
|
||||||
"tribute_auto_renewal": "🔄 <b>Subscription Auto-Renewed</b>\n\nYour Tribute subscription has been automatically renewed for {months} months.\nNew expiration date: {end_date}",
|
"tribute_auto_renewal": "🔄 <b>Subscription Auto-Renewed</b>\n\nYour Tribute subscription has been automatically renewed for {months} months.\nNew expiration date: {end_date}",
|
||||||
|
"yookassa_auto_renewal": "🔄 <b>Subscription Auto-Renewed</b>\n\nYour subscription was automatically renewed for {months} month(s).\nNew expiration date: {end_date}",
|
||||||
"admin_user_management_prompt": "👤 User Management\n\nEnter user ID or @username to search:",
|
"admin_user_management_prompt": "👤 User Management\n\nEnter user ID or @username to search:",
|
||||||
"admin_user_subscription_info": "Subscription Information:",
|
"admin_user_subscription_info": "Subscription Information:",
|
||||||
"admin_user_reset_trial_button": "🔄 Reset Trial",
|
"admin_user_reset_trial_button": "🔄 Reset Trial",
|
||||||
|
|||||||
@@ -140,6 +140,7 @@
|
|||||||
"subscription_expired_notification": "👋 Привет, {user_name}!\n\n⛔ Срок вашей подписки на VPN истек ({end_date}).\n\nПродлите её по кнопке ниже.",
|
"subscription_expired_notification": "👋 Привет, {user_name}!\n\n⛔ Срок вашей подписки на VPN истек ({end_date}).\n\nПродлите её по кнопке ниже.",
|
||||||
"subscription_expired_yesterday_notification": "👋 Привет, {user_name}!\n\n⏳ Ваша подписка на VPN истекла сутки назад ({end_date}).\n\nПродлите её по кнопке ниже.",
|
"subscription_expired_yesterday_notification": "👋 Привет, {user_name}!\n\n⏳ Ваша подписка на VPN истекла сутки назад ({end_date}).\n\nПродлите её по кнопке ниже.",
|
||||||
"tribute_subscription_cancelled": "🚨 <b>Подписка отменена</b>\n\nВаша подписка Tribute была отменена. У вас есть 24 часа для восстановления доступа, после чего подписка будет заблокирована.\n\nДля продления подписки нажмите кнопку ниже.",
|
"tribute_subscription_cancelled": "🚨 <b>Подписка отменена</b>\n\nВаша подписка Tribute была отменена. У вас есть 24 часа для восстановления доступа, после чего подписка будет заблокирована.\n\nДля продления подписки нажмите кнопку ниже.",
|
||||||
|
"yookassa_auto_renewal": "🔄 <b>Подписка автоматически продлена</b>\n\nВаша подписка была автоматически продлена на {months} мес.\nНовая дата окончания: {end_date}",
|
||||||
"admin_promo_set_validity_days": "⏰ Установить срок (дни)",
|
"admin_promo_set_validity_days": "⏰ Установить срок (дни)",
|
||||||
"admin_back_to_panel": "⬅️ В панель",
|
"admin_back_to_panel": "⬅️ В панель",
|
||||||
"admin_promo_unlimited": "♾️ Неограниченно",
|
"admin_promo_unlimited": "♾️ Неограниченно",
|
||||||
|
|||||||
Reference in New Issue
Block a user