feat: logs de debug
All checks were successful
BCards Deployment Pipeline / Run Tests (push) Successful in 10s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Build and Push Image (push) Successful in 15m26s
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Successful in 1m21s
BCards Deployment Pipeline / Deploy to Staging (x86 - Local) (push) Has been skipped
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been skipped
BCards Deployment Pipeline / Deployment Summary (push) Successful in 0s

This commit is contained in:
Ricardo Carneiro 2025-09-08 08:57:36 -03:00
parent 32b83923dc
commit ce1c1409de

View File

@ -62,7 +62,7 @@ public class StripeWebhookController : ControllerBase
throwOnApiVersionMismatch: false throwOnApiVersionMismatch: false
); );
_logger.LogInformation($"Processing Stripe webhook: {stripeEvent.Type}"); _logger.LogInformation($"[DEBUG] Processing Stripe webhook: {stripeEvent.Type}");
switch (stripeEvent.Type) switch (stripeEvent.Type)
{ {
@ -275,14 +275,19 @@ public class StripeWebhookController : ControllerBase
{ {
try try
{ {
_logger.LogInformation($"[DEBUG] HandleSubscriptionCreated started");
if (stripeEvent.Data.Object is Subscription stripeSubscription) if (stripeEvent.Data.Object is Subscription stripeSubscription)
{ {
_logger.LogInformation($"Subscription created: {stripeSubscription.Id} for customer: {stripeSubscription.CustomerId}"); _logger.LogInformation($"[DEBUG] Subscription created: {stripeSubscription.Id} for customer: {stripeSubscription.CustomerId}");
// Get subscription record from our database // Get subscription record from our database
_logger.LogInformation($"[DEBUG] Looking for existing subscription with ID: {stripeSubscription.Id}");
var subscription = await _subscriptionRepository.GetByStripeSubscriptionIdAsync(stripeSubscription.Id); var subscription = await _subscriptionRepository.GetByStripeSubscriptionIdAsync(stripeSubscription.Id);
if (subscription != null) if (subscription != null)
{ {
_logger.LogInformation($"[DEBUG] Found existing subscription: {subscription.Id}");
var service = new SubscriptionItemService(); var service = new SubscriptionItemService();
var subItem = service.Get(stripeSubscription.Items.Data[0].Id); var subItem = service.Get(stripeSubscription.Items.Data[0].Id);
@ -316,7 +321,8 @@ public class StripeWebhookController : ControllerBase
} }
else else
{ {
_logger.LogWarning($"Subscription not found in database: {stripeSubscription.Id}"); _logger.LogInformation($"[DEBUG] Subscription not found in database: {stripeSubscription.Id}");
_logger.LogInformation($"[DEBUG] Calling HandleSubscriptionCreatedForNewSubscription");
// Try to find user by Stripe Customer ID and create/update subscription // Try to find user by Stripe Customer ID and create/update subscription
await HandleSubscriptionCreatedForNewSubscription(stripeSubscription); await HandleSubscriptionCreatedForNewSubscription(stripeSubscription);
@ -389,15 +395,20 @@ public class StripeWebhookController : ControllerBase
{ {
try try
{ {
_logger.LogInformation($"[DEBUG] HandleSubscriptionCreatedForNewSubscription started for customer: {stripeSubscription.CustomerId}");
// Find user by Stripe Customer ID using a MongoDB query // Find user by Stripe Customer ID using a MongoDB query
// Since IUserRepository doesn't have GetByStripeCustomerIdAsync, we'll use MongoDB directly // Since IUserRepository doesn't have GetByStripeCustomerIdAsync, we'll use MongoDB directly
_logger.LogInformation($"[DEBUG] Getting MongoDB database");
var mongoDatabase = HttpContext.RequestServices.GetRequiredService<IMongoDatabase>(); var mongoDatabase = HttpContext.RequestServices.GetRequiredService<IMongoDatabase>();
var usersCollection = mongoDatabase.GetCollection<Models.User>("users"); var usersCollection = mongoDatabase.GetCollection<Models.User>("users");
_logger.LogInformation($"[DEBUG] Searching for user with StripeCustomerId: {stripeSubscription.CustomerId}");
var user = await usersCollection.Find(u => u.StripeCustomerId == stripeSubscription.CustomerId).FirstOrDefaultAsync(); var user = await usersCollection.Find(u => u.StripeCustomerId == stripeSubscription.CustomerId).FirstOrDefaultAsync();
if (user != null) if (user != null)
{ {
_logger.LogInformation($"[DEBUG] Found user: {user.Id} ({user.Email})");
_logger.LogInformation($"Found user {user.Id} for customer {stripeSubscription.CustomerId}"); _logger.LogInformation($"Found user {user.Id} for customer {stripeSubscription.CustomerId}");
var service = new SubscriptionItemService(); var service = new SubscriptionItemService();
@ -440,7 +451,15 @@ public class StripeWebhookController : ControllerBase
} }
else else
{ {
_logger.LogError($"User not found for Stripe customer ID: {stripeSubscription.CustomerId}"); _logger.LogError($"[DEBUG] User not found for Stripe customer ID: {stripeSubscription.CustomerId}");
_logger.LogInformation($"[DEBUG] Will try to list some users to debug");
// Debug: list some users to see what we have
var allUsers = await usersCollection.Find(_ => true).Limit(5).ToListAsync();
foreach (var u in allUsers)
{
_logger.LogInformation($"[DEBUG] User in DB: {u.Id} - {u.Email} - StripeCustomerId: '{u.StripeCustomerId}'");
}
} }
} }
catch (Exception ex) catch (Exception ex)