diff --git a/src/BCards.Web/Controllers/AdminController.cs b/src/BCards.Web/Controllers/AdminController.cs index 4252733..71f5195 100644 --- a/src/BCards.Web/Controllers/AdminController.cs +++ b/src/BCards.Web/Controllers/AdminController.cs @@ -60,7 +60,13 @@ public class AdminController : Controller if (user == null) return RedirectToAction("Login", "Auth"); + _logger.LogInformation("[DASHBOARD DEBUG] User {UserId} ({Email}) - CurrentPlan: '{CurrentPlan}'", + user.Id, user.Email, user.CurrentPlan ?? "NULL"); + var userPlanType = Enum.TryParse(user.CurrentPlan, true, out var planType) ? planType : PlanType.Trial; + + _logger.LogInformation("[DASHBOARD DEBUG] Parsed PlanType: {PlanType} (from '{CurrentPlan}')", + userPlanType, user.CurrentPlan ?? "NULL"); var userPages = await _userPageService.GetUserPagesAsync(user.Id); var listCounts = new Dictionary(); diff --git a/src/BCards.Web/Controllers/StripeWebhookController.cs b/src/BCards.Web/Controllers/StripeWebhookController.cs index ecd4f8f..624ced2 100644 --- a/src/BCards.Web/Controllers/StripeWebhookController.cs +++ b/src/BCards.Web/Controllers/StripeWebhookController.cs @@ -443,6 +443,15 @@ public class StripeWebhookController : ControllerBase await _subscriptionRepository.CreateAsync(newSubscription); _logger.LogInformation($"[TID: {traceId}] - Created new subscription {newSubscription.Id} for user {user.Id}"); + // 🔥 CORREÇÃO: Update user's CurrentPlan + _logger.LogInformation($"[TID: {traceId}] - Updating user {user.Id} CurrentPlan from '{user.CurrentPlan}' to '{planType}'"); + user.CurrentPlan = planType; + user.UpdatedAt = DateTime.UtcNow; + + var usersCollection = mongoDatabase.GetCollection("users"); + await usersCollection.ReplaceOneAsync(u => u.Id == user.Id, user); + _logger.LogInformation($"[TID: {traceId}] - User {user.Id} CurrentPlan updated to '{planType}'"); + // Activate user pages that were pending payment or expired var userPages = await _userPageService.GetUserPagesAsync(user.Id); foreach (var page in userPages.Where(p =>