Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLazarescu committed Feb 22, 2024
1 parent acb621d commit 6b24931
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Presentation/Controllers/WebHookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public async Task<IActionResult> Stripe()
await AddCustomerIdToUser(stripeEvent.Data.Object as Customer);
break;
case Events.CustomerSubscriptionCreated:
case Events.CustomerSubscriptionUpdated:
await AddTierToCustomer(stripeEvent.Data.Object as Subscription);
break;
case Events.CustomerSubscriptionUpdated:
await UpdateSubscription(stripeEvent.Data.Object as Subscription);
break;
case Events.CustomerSubscriptionDeleted:
case Events.CustomerSubscriptionPendingUpdateExpired:
await RemoveTierFromCustomer(stripeEvent.Data.Object as Subscription);
Expand All @@ -68,6 +70,18 @@ public async Task<IActionResult> Stripe()
}
}

private async Task UpdateSubscription(Subscription subscription)
{
if (subscription.Status == "incomplete_expired")
{
await RemoveTierFromCustomer(subscription);
}
else
{
await AddTierToCustomer(subscription);
}
}

private async Task AddTierToCustomer(Subscription subscription)
{
var customerId = subscription.CustomerId;
Expand Down

0 comments on commit 6b24931

Please sign in to comment.