1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-23 04:21:05 -05:00

handle cases when sub is already cancelled

This commit is contained in:
Kyle Spearrin 2017-08-10 09:12:55 -04:00
parent 789636b394
commit c802292098
2 changed files with 17 additions and 11 deletions

View File

@ -518,12 +518,7 @@ namespace Bit.Core.Services
{ {
if(!string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId)) if(!string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId))
{ {
var subscriptionService = new StripeSubscriptionService(); await _stripePaymentService.CancelSubscriptionAsync(organization, false);
var canceledSub = await subscriptionService.CancelAsync(organization.GatewaySubscriptionId, false);
if(!canceledSub.CanceledAt.HasValue)
{
throw new BadRequestException("Unable to cancel subscription.");
}
} }
await _organizationRepository.DeleteAsync(organization); await _organizationRepository.DeleteAsync(organization);

View File

@ -191,17 +191,28 @@ namespace Bit.Core.Services
throw new GatewayException("Subscription was not found."); throw new GatewayException("Subscription was not found.");
} }
if(sub.CanceledAt.HasValue) if(sub.CanceledAt.HasValue || sub.Status == "cancelled")
{ {
throw new GatewayException("Subscription is already canceled."); // Already cancelled
return;
} }
try
{
var canceledSub = await subscriptionService.CancelAsync(sub.Id, endOfPeriod); var canceledSub = await subscriptionService.CancelAsync(sub.Id, endOfPeriod);
if(!canceledSub.CanceledAt.HasValue) if(!canceledSub.CanceledAt.HasValue)
{ {
throw new GatewayException("Unable to cancel subscription."); throw new GatewayException("Unable to cancel subscription.");
} }
} }
catch(StripeException e)
{
if(e.Message != $"No such subscription: {subscriber.GatewaySubscriptionId}")
{
throw e;
}
}
}
public async Task ReinstateSubscriptionAsync(ISubscriber subscriber) public async Task ReinstateSubscriptionAsync(ISubscriber subscriber)
{ {