mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
handle cases when sub is already cancelled
This commit is contained in:
parent
789636b394
commit
c802292098
@ -518,12 +518,7 @@ namespace Bit.Core.Services
|
||||
{
|
||||
if(!string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId))
|
||||
{
|
||||
var subscriptionService = new StripeSubscriptionService();
|
||||
var canceledSub = await subscriptionService.CancelAsync(organization.GatewaySubscriptionId, false);
|
||||
if(!canceledSub.CanceledAt.HasValue)
|
||||
{
|
||||
throw new BadRequestException("Unable to cancel subscription.");
|
||||
}
|
||||
await _stripePaymentService.CancelSubscriptionAsync(organization, false);
|
||||
}
|
||||
|
||||
await _organizationRepository.DeleteAsync(organization);
|
||||
|
@ -191,15 +191,26 @@ namespace Bit.Core.Services
|
||||
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;
|
||||
}
|
||||
|
||||
var canceledSub = await subscriptionService.CancelAsync(sub.Id, endOfPeriod);
|
||||
if(!canceledSub.CanceledAt.HasValue)
|
||||
try
|
||||
{
|
||||
throw new GatewayException("Unable to cancel subscription.");
|
||||
var canceledSub = await subscriptionService.CancelAsync(sub.Id, endOfPeriod);
|
||||
if(!canceledSub.CanceledAt.HasValue)
|
||||
{
|
||||
throw new GatewayException("Unable to cancel subscription.");
|
||||
}
|
||||
}
|
||||
catch(StripeException e)
|
||||
{
|
||||
if(e.Message != $"No such subscription: {subscriber.GatewaySubscriptionId}")
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user