fix(promocode): correct activation UX, error mapping and validity dates

Map promocode errors by stable backend code (detail.code) instead of brittle English
substring matching, so previously-unmapped codes (active_discount_exists, daily_limit,
no_subscription_for_days, trial_*, etc.) show the right message instead of 'server error';
added the missing keys to all 4 locales.

valid_until now anchors to end-of-day in the admin's LOCAL timezone on both create AND
edit read-back, so codes no longer expire at the start of the day and editing no longer
drifts the date forward for negative-offset admins.

Allow 0-hour discount ('until first purchase'). Route user-facing discount deactivation
to the endpoint that rolls back promocode usage when the discount came from a promocode,
and parse the structured {code,message} error.
This commit is contained in:
c0mrade
2026-06-08 00:23:31 +03:00
parent 1a3236f650
commit 35428cc27d
7 changed files with 97 additions and 24 deletions

View File

@@ -787,6 +787,13 @@
"not_yet_valid": "Promo code is not yet active",
"used": "Promo code has already been used",
"already_used_by_user": "You have already used this promo code",
"active_discount_exists": "You already have an active discount. Deactivate it first.",
"no_subscription_for_days": "This promo code requires an active or expired subscription",
"subscription_not_found": "Subscription not found",
"not_first_purchase": "This promo code is only available for your first purchase",
"daily_limit": "Too many promo code activations today",
"trial_subscription_exists": "You already have a subscription, so this trial code can't be applied",
"trial_provisioning_failed": "Couldn't provision the trial right now, please try again later",
"user_not_found": "User not found",
"server_error": "Server error"
},

View File

@@ -674,6 +674,13 @@
"not_yet_valid": "کد تخفیف هنوز فعال نشده",
"used": "کد تخفیف قبلاً استفاده شده",
"already_used_by_user": "شما قبلاً از این کد استفاده کرده‌اید",
"active_discount_exists": "شما در حال حاضر یک تخفیف فعال دارید. ابتدا آن را غیرفعال کنید.",
"no_subscription_for_days": "این کد تخفیف به اشتراک فعال یا منقضی‌شده نیاز دارد",
"subscription_not_found": "اشتراک یافت نشد",
"not_first_purchase": "این کد تخفیف فقط برای اولین خرید در دسترس است",
"daily_limit": "تعداد فعال‌سازی کد تخفیف امروز بیش از حد است",
"trial_subscription_exists": "شما در حال حاضر اشتراک دارید، بنابراین این کد آزمایشی قابل اعمال نیست",
"trial_provisioning_failed": "در حال حاضر امکان فعال‌سازی نسخه آزمایشی نیست، لطفاً بعداً تلاش کنید",
"user_not_found": "کاربر یافت نشد",
"server_error": "خطای سرور"
},

View File

@@ -816,6 +816,13 @@
"not_yet_valid": "Промокод ещё не начал действовать",
"used": "Промокод уже использован",
"already_used_by_user": "Вы уже использовали этот промокод",
"active_discount_exists": "У вас уже есть активная скидка. Сначала отключите её.",
"no_subscription_for_days": "Для этого промокода нужна активная или истёкшая подписка",
"subscription_not_found": "Подписка не найдена",
"not_first_purchase": "Промокод доступен только для первой покупки",
"daily_limit": "Слишком много активаций промокодов за сегодня",
"trial_subscription_exists": "У вас уже есть подписка, поэтому триал-промокод применить нельзя",
"trial_provisioning_failed": "Не удалось выдать триал прямо сейчас, попробуйте позже",
"user_not_found": "Пользователь не найден",
"server_error": "Ошибка сервера"
},

View File

@@ -674,6 +674,13 @@
"not_yet_valid": "优惠码尚未生效",
"used": "优惠码已被使用",
"already_used_by_user": "您已使用过此优惠码",
"active_discount_exists": "您已有一个生效中的折扣,请先停用它。",
"no_subscription_for_days": "此优惠码需要有效或已过期的订阅",
"subscription_not_found": "未找到订阅",
"not_first_purchase": "此优惠码仅限首次购买使用",
"daily_limit": "今日优惠码激活次数过多",
"trial_subscription_exists": "您已有订阅,因此无法使用此试用优惠码",
"trial_provisioning_failed": "暂时无法开通试用,请稍后再试",
"user_not_found": "用户不存在",
"server_error": "服务器错误"
},