diff --git a/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpgradeOrganizationPlanCommand.cs b/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpgradeOrganizationPlanCommand.cs index 33dd38833..7f463460d 100644 --- a/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpgradeOrganizationPlanCommand.cs +++ b/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpgradeOrganizationPlanCommand.cs @@ -231,9 +231,19 @@ public class UpgradeOrganizationPlanCommand : IUpgradeOrganizationPlanCommand } else { - paymentIntentClientSecret = await _paymentService.UpgradeFreeOrganizationAsync(organization, - newPlan, upgrade); - success = string.IsNullOrWhiteSpace(paymentIntentClientSecret); + try + { + paymentIntentClientSecret = await _paymentService.UpgradeFreeOrganizationAsync(organization, + newPlan, upgrade); + success = string.IsNullOrWhiteSpace(paymentIntentClientSecret); + } + catch + { + await _paymentService.CancelAndRecoverChargesAsync(organization); + organization.GatewayCustomerId = null; + await _organizationService.ReplaceAndUpdateCacheAsync(organization); + throw; + } } } else