From f0f58897a910b28fc9e66165e541555e6475a7c0 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 11 Jul 2017 11:19:58 -0400 Subject: [PATCH] cancel any subscriptions when deleting account --- src/Core/Services/Implementations/UserService.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Core/Services/Implementations/UserService.cs b/src/Core/Services/Implementations/UserService.cs index a939e74be..dccaa0f07 100644 --- a/src/Core/Services/Implementations/UserService.cs +++ b/src/Core/Services/Implementations/UserService.cs @@ -164,6 +164,16 @@ namespace Bit.Core.Services }); } + if(!string.IsNullOrWhiteSpace(user.StripeSubscriptionId)) + { + var subscriptionService = new StripeSubscriptionService(); + var canceledSub = await subscriptionService.CancelAsync(user.StripeSubscriptionId, false); + if(!canceledSub.CanceledAt.HasValue) + { + throw new BadRequestException("Unable to cancel subscription."); + } + } + await _userRepository.DeleteAsync(user); return IdentityResult.Success; }