feat(subscriptions): add trial period validation for subscriptions
- Implemented a check to verify if a user has already utilized their trial period before allowing access to subscription services. - Enhanced error handling to provide a clear message when a trial period has been previously used, improving user experience and subscription management.
This commit is contained in:
parent
4f87b9cef6
commit
cadc3cd26a
@ -44,6 +44,22 @@ export class SubscriptionsService extends BaseService {
|
||||
// Получаем пользователя и проверяем бан
|
||||
const { customer } = await this.checkIsBanned();
|
||||
|
||||
// Проверяем, не использовал ли пользователь уже пробный период
|
||||
const { subscription: existingSubscription } = await this.getSubscription({
|
||||
telegramId: customer.telegramId,
|
||||
});
|
||||
if (existingSubscription) {
|
||||
// Проверяем, есть ли в истории успешная пробная подписка
|
||||
const hasUsedTrial = existingSubscription.subscriptionHistories?.some(
|
||||
(item) =>
|
||||
item?.period === GQL.Enum_Subscriptionhistory_Period.Trial &&
|
||||
item?.state === GQL.Enum_Subscriptionhistory_State.Success,
|
||||
);
|
||||
if (hasUsedTrial) {
|
||||
throw new Error('Пробный период уже был использован');
|
||||
}
|
||||
}
|
||||
|
||||
// Получаем цены подписки для определения длительности пробного периода
|
||||
const { subscriptionPrices } = await this.getSubscriptionPrices({ isActive: true });
|
||||
if (!subscriptionPrices) throw new Error('Subscription prices not found');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user