👔 Purchase gift requires minimal level
This commit is contained in:
@@ -146,19 +146,6 @@ public class SubscriptionGiftController(
|
|||||||
{
|
{
|
||||||
error = "You already have an active subscription of this type.";
|
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
|
else
|
||||||
{
|
{
|
||||||
canRedeem = true;
|
canRedeem = true;
|
||||||
@@ -197,6 +184,8 @@ public class SubscriptionGiftController(
|
|||||||
public int? SubscriptionDurationDays { get; set; } = 30; // Subscription lasts 30 days when redeemed
|
public int? SubscriptionDurationDays { get; set; } = 30; // Subscription lasts 30 days when redeemed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int MinimumAccountLevel = 60;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Purchases a gift subscription.
|
/// Purchases a gift subscription.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -206,6 +195,11 @@ public class SubscriptionGiftController(
|
|||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized();
|
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;
|
Duration? giftDuration = null;
|
||||||
if (request.GiftDurationDays.HasValue)
|
if (request.GiftDurationDays.HasValue)
|
||||||
giftDuration = Duration.FromDays(request.GiftDurationDays.Value);
|
giftDuration = Duration.FromDays(request.GiftDurationDays.Value);
|
||||||
|
@@ -710,7 +710,7 @@ public class SubscriptionService(
|
|||||||
// We do not check account level requirement, since it is a gift
|
// We do not check account level requirement, since it is a gift
|
||||||
|
|
||||||
// Create the subscription from the 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
|
var subscription = new SnWalletSubscription
|
||||||
{
|
{
|
||||||
BegunAt = now,
|
BegunAt = now,
|
||||||
@@ -719,7 +719,7 @@ public class SubscriptionService(
|
|||||||
IsActive = true,
|
IsActive = true,
|
||||||
IsFreeTrial = false,
|
IsFreeTrial = false,
|
||||||
Status = Shared.Models.SubscriptionStatus.Active,
|
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
|
PaymentDetails = new Shared.Models.SnPaymentDetails
|
||||||
{
|
{
|
||||||
Currency = "gift",
|
Currency = "gift",
|
||||||
|
Reference in New Issue
Block a user