Enhance user plan management and update related endpoints
- Added new configuration options for user plans in `.env.example`, including `Plans__MaxCustomConfigCount` and `Plans__MinCustomConfigCount`. - Introduced `MapPlanEndpoints` in `Program.cs` to handle plan-related API routes. - Implemented `SetUserPlan` endpoint in `RoleEndpoints` to allow admins to assign plans to users. - Removed deprecated role request approval endpoints from `AdminSupportEndpoints`. - Updated `ITelegramNotifier` and related classes to reflect changes in role request handling and payment notifications. - Refactored role management commands to remove `MaxConfigs` and focus on `MaxIpLimit` and billing settings. - Enhanced billing request handling to accommodate plan changes instead of role changes. - Updated various interfaces and command handlers to support new plan management features.
This commit is contained in:
+4
-4
@@ -33,7 +33,7 @@ public sealed class CreatePaymentRequestCommandHandler(
|
||||
if (!profile.BillingEnabled)
|
||||
return Result.Failure<PaymentRequestDto>(BillingErrors.NotEnabled);
|
||||
|
||||
if (profile.MaxConfigs == RoleQuota.Unlimited)
|
||||
if (profile.ConfigQuota == RoleQuota.Unlimited)
|
||||
return Result.Failure<PaymentRequestDto>(BillingErrors.UnlimitedRoleNotSupported);
|
||||
|
||||
var pricing = await dbContext.PricingSettings.AsNoTracking().FirstOrDefaultAsync(cancellationToken);
|
||||
@@ -54,16 +54,16 @@ public sealed class CreatePaymentRequestCommandHandler(
|
||||
.PricingDiscountTiers.AsNoTracking()
|
||||
.Where(t => t.PricingSettingsId == pricing.Id)
|
||||
.ToListAsync(cancellationToken);
|
||||
var discountPercent = PricingDiscount.ResolvePercent(discountTiers, profile.MaxConfigs);
|
||||
var discountPercent = PricingDiscount.ResolvePercent(discountTiers, profile.ConfigQuota);
|
||||
|
||||
var amount = PricingDiscount.Apply(rate * profile.MaxConfigs * command.Period.ToMonths(), discountPercent);
|
||||
var amount = PricingDiscount.Apply(rate * profile.ConfigQuota * command.Period.ToMonths(), discountPercent);
|
||||
|
||||
var claimed = await AdvisoryLock.RunAsync(
|
||||
dbContext,
|
||||
userId,
|
||||
async lockedCancellationToken =>
|
||||
{
|
||||
// RoleChangeTopUp не считается активной подписной заявкой — доплата за смену роли не
|
||||
// PlanChangeTopUp не считается активной подписной заявкой — доплата за смену тарифа не
|
||||
// должна мешать пользователю продлить/оформить обычную подписку.
|
||||
var hasActiveRequest = await dbContext.PaymentRequests.AnyAsync(
|
||||
r =>
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public sealed class MarkPaymentSentCommandHandler(
|
||||
// Оплаченный период уже мог истечь, пока пользователь собирался заплатить — не ждём часовой
|
||||
// тик BillingService, сразу держим клиента рабочим на панели на время рассмотрения заявки
|
||||
// (см. BillingConfigResumer.ProtectPendingConfigsAsync). Только для Subscription — доплата за
|
||||
// смену роли (RoleChangeTopUp) на приостановку не влияет.
|
||||
// смену тарифа (PlanChangeTopUp) на приостановку не влияет.
|
||||
if (
|
||||
request.Kind == PaymentRequestKind.Subscription
|
||||
&& (profile?.BillingPaidUntil is null || profile.BillingPaidUntil < DateTimeOffset.UtcNow)
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public sealed class SendRequisitesToTelegramCommandHandler(
|
||||
}
|
||||
|
||||
private static string DescribeRequest(PaymentRequest request) =>
|
||||
request.Kind == PaymentRequestKind.RoleChangeTopUp ? "доплата за смену роли" : PeriodLabel(request.Period!.Value);
|
||||
request.Kind == PaymentRequestKind.PlanChangeTopUp ? "доплата за смену тарифа" : PeriodLabel(request.Period!.Value);
|
||||
|
||||
private static string PeriodLabel(PaymentPeriod period) =>
|
||||
period switch
|
||||
|
||||
Reference in New Issue
Block a user