1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

storage adjustment and billing fixes

This commit is contained in:
Kyle Spearrin
2017-07-11 10:59:59 -04:00
parent a8ff190fb5
commit b49c16f529
6 changed files with 51 additions and 14 deletions

View File

@ -183,8 +183,8 @@ namespace Bit.Core.Utilities
throw new BadRequestException("Subscription not found.");
}
var seatItem = sub.Items?.Data?.FirstOrDefault(i => i.Plan.Id == storagePlanId);
if(seatItem == null)
var storageItem = sub.Items?.Data?.FirstOrDefault(i => i.Plan.Id == storagePlanId);
if(additionalStorage > 0 && storageItem == null)
{
await subscriptionItemService.CreateAsync(new StripeSubscriptionItemCreateOptions
{
@ -194,23 +194,23 @@ namespace Bit.Core.Utilities
SubscriptionId = sub.Id
});
}
else if(additionalStorage > 0)
else if(additionalStorage > 0 && storageItem != null)
{
await subscriptionItemService.UpdateAsync(seatItem.Id, new StripeSubscriptionItemUpdateOptions
await subscriptionItemService.UpdateAsync(storageItem.Id, new StripeSubscriptionItemUpdateOptions
{
PlanId = storagePlanId,
Quantity = additionalStorage,
Prorate = true
});
}
else if(additionalStorage == 0)
else if(additionalStorage == 0 && storageItem != null)
{
await subscriptionItemService.DeleteAsync(storagePlanId);
await subscriptionItemService.DeleteAsync(storageItem.Id);
}
if(additionalStorage > 0)
{
await PreviewUpcomingInvoiceAndPayAsync(storableSubscriber, storagePlanId, 300);
await PreviewUpcomingInvoiceAndPayAsync(storableSubscriber, storagePlanId, 400);
}
storableSubscriber.MaxStorageGb = newStorageGb;