👔 Purchase gift requires minimal level

This commit is contained in:
2025-10-03 17:20:58 +08:00
parent eb83a0392a
commit dcbefeaaab
2 changed files with 9 additions and 15 deletions

View File

@@ -146,19 +146,6 @@ public class SubscriptionGiftController(
{
error = "You already have an active subscription of this type.";
}
else if (subscriptionInfo.RequiredLevel > 0)
{
var profile = await db.AccountProfiles.FirstOrDefaultAsync(p => p.AccountId == currentUser.Id);
if (profile is null || profile.Level < subscriptionInfo.RequiredLevel)
{
error =
$"Account level must be at least {subscriptionInfo.RequiredLevel} to redeem this gift.";
}
else
{
canRedeem = true;
}
}
else
{
canRedeem = true;
@@ -197,6 +184,8 @@ public class SubscriptionGiftController(
public int? SubscriptionDurationDays { get; set; } = 30; // Subscription lasts 30 days when redeemed
}
const int MinimumAccountLevel = 60;
/// <summary>
/// Purchases a gift subscription.
/// </summary>
@@ -206,6 +195,11 @@ public class SubscriptionGiftController(
{
if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized();
if (currentUser.Profile.Level < MinimumAccountLevel)
{
return StatusCode(403, "Account level must be at least 60 to purchase a gift.");
}
Duration? giftDuration = null;
if (request.GiftDurationDays.HasValue)
giftDuration = Duration.FromDays(request.GiftDurationDays.Value);

View File

@@ -710,7 +710,7 @@ public class SubscriptionService(
// We do not check account level requirement, since it is a gift
// Create the subscription from the gift
var cycleDuration = Duration.FromDays(30); // Standard 30-day subscription
var cycleDuration = Duration.FromDays(28); // Standard 28-day subscription
var subscription = new SnWalletSubscription
{
BegunAt = now,
@@ -719,7 +719,7 @@ public class SubscriptionService(
IsActive = true,
IsFreeTrial = false,
Status = Shared.Models.SubscriptionStatus.Active,
PaymentMethod = $"gift:{gift.Id}", // Special payment method indicating gift redemption
PaymentMethod = "gift", // Special payment method indicating gift redemption
PaymentDetails = new Shared.Models.SnPaymentDetails
{
Currency = "gift",