Compare commits
No commits in common. "0f6ae719973a05ea58fb59398aa777bee774ca96" and "787fa63f68d0af05b5d3c1944df81776ad1b74da" have entirely different histories.
0f6ae71997
...
787fa63f68
@ -24,8 +24,7 @@
|
|||||||
"Bash(dotnet nuget locals:*)",
|
"Bash(dotnet nuget locals:*)",
|
||||||
"Bash(/mnt/c/vscode/vcart.me.novo/clean-build.sh:*)",
|
"Bash(/mnt/c/vscode/vcart.me.novo/clean-build.sh:*)",
|
||||||
"Bash(sed:*)",
|
"Bash(sed:*)",
|
||||||
"Bash(./clean-build.sh:*)",
|
"Bash(./clean-build.sh:*)"
|
||||||
"Bash(git add:*)"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"enableAllProjectMcpServers": false
|
"enableAllProjectMcpServers": false
|
||||||
|
|||||||
@ -78,10 +78,6 @@ public class StripeWebhookController : ControllerBase
|
|||||||
await HandleSubscriptionUpdated(stripeEvent);
|
await HandleSubscriptionUpdated(stripeEvent);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "customer.subscription.created":
|
|
||||||
await HandleSubscriptionCreated(stripeEvent);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
_logger.LogInformation($"Unhandled webhook event type: {stripeEvent.Type}");
|
_logger.LogInformation($"Unhandled webhook event type: {stripeEvent.Type}");
|
||||||
break;
|
break;
|
||||||
@ -267,66 +263,6 @@ public class StripeWebhookController : ControllerBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleSubscriptionCreated(Event stripeEvent)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (stripeEvent.Data.Object is Subscription stripeSubscription)
|
|
||||||
{
|
|
||||||
_logger.LogInformation($"Subscription created: {stripeSubscription.Id} for customer: {stripeSubscription.CustomerId}");
|
|
||||||
|
|
||||||
// Get subscription record from our database
|
|
||||||
var subscription = await _subscriptionRepository.GetByStripeSubscriptionIdAsync(stripeSubscription.Id);
|
|
||||||
if (subscription != null)
|
|
||||||
{
|
|
||||||
var service = new SubscriptionItemService();
|
|
||||||
var subItem = service.Get(stripeSubscription.Items.Data[0].Id);
|
|
||||||
|
|
||||||
// Update subscription status to active
|
|
||||||
subscription.Status = "active";
|
|
||||||
subscription.UpdatedAt = DateTime.UtcNow;
|
|
||||||
subscription.CurrentPeriodStart = subItem.CurrentPeriodStart;
|
|
||||||
subscription.CurrentPeriodEnd = subItem.CurrentPeriodEnd;
|
|
||||||
|
|
||||||
// Update plan type based on Stripe price ID
|
|
||||||
var priceId = stripeSubscription.Items.Data.FirstOrDefault()?.Price.Id;
|
|
||||||
if (!string.IsNullOrEmpty(priceId))
|
|
||||||
{
|
|
||||||
subscription.PlanType = MapPriceIdToPlanType(priceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
await _subscriptionRepository.UpdateAsync(subscription);
|
|
||||||
|
|
||||||
// Activate user pages that were pending payment or trial
|
|
||||||
var userPages = await _userPageService.GetUserPagesAsync(subscription.UserId);
|
|
||||||
foreach (var page in userPages.Where(p =>
|
|
||||||
p.Status == ViewModels.PageStatus.PendingPayment ||
|
|
||||||
p.Status == ViewModels.PageStatus.Expired))
|
|
||||||
{
|
|
||||||
page.Status = ViewModels.PageStatus.Active;
|
|
||||||
page.UpdatedAt = DateTime.UtcNow;
|
|
||||||
await _userPageService.UpdatePageAsync(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogInformation($"Activated subscription and {userPages.Count()} pages for user {subscription.UserId}");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.LogWarning($"Subscription not found in database: {stripeSubscription.Id}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.LogWarning($"Unexpected event type on HandleSubscriptionCreated: {stripeEvent.Type}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error handling subscription created event");
|
|
||||||
throw new Exception("Error handling subscription created event", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private string MapPriceIdToPlanType(string priceId)
|
private string MapPriceIdToPlanType(string priceId)
|
||||||
{
|
{
|
||||||
// Map Stripe price IDs to plan types
|
// Map Stripe price IDs to plan types
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user