mirror of
https://github.com/bitwarden/server
synced 2026-01-06 10:34:01 +00:00
Turn on file scoped namespaces (#2225)
This commit is contained in:
@@ -2,57 +2,56 @@
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Services;
|
||||
|
||||
namespace Bit.Core.Utilities
|
||||
namespace Bit.Core.Utilities;
|
||||
|
||||
public static class BillingHelpers
|
||||
{
|
||||
public static class BillingHelpers
|
||||
internal static async Task<string> AdjustStorageAsync(IPaymentService paymentService, IStorableSubscriber storableSubscriber,
|
||||
short storageAdjustmentGb, string storagePlanId)
|
||||
{
|
||||
internal static async Task<string> AdjustStorageAsync(IPaymentService paymentService, IStorableSubscriber storableSubscriber,
|
||||
short storageAdjustmentGb, string storagePlanId)
|
||||
if (storableSubscriber == null)
|
||||
{
|
||||
if (storableSubscriber == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(storableSubscriber));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(storableSubscriber.GatewayCustomerId))
|
||||
{
|
||||
throw new BadRequestException("No payment method found.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(storableSubscriber.GatewaySubscriptionId))
|
||||
{
|
||||
throw new BadRequestException("No subscription found.");
|
||||
}
|
||||
|
||||
if (!storableSubscriber.MaxStorageGb.HasValue)
|
||||
{
|
||||
throw new BadRequestException("No access to storage.");
|
||||
}
|
||||
|
||||
var newStorageGb = (short)(storableSubscriber.MaxStorageGb.Value + storageAdjustmentGb);
|
||||
if (newStorageGb < 1)
|
||||
{
|
||||
newStorageGb = 1;
|
||||
}
|
||||
|
||||
if (newStorageGb > 100)
|
||||
{
|
||||
throw new BadRequestException("Maximum storage is 100 GB.");
|
||||
}
|
||||
|
||||
var remainingStorage = storableSubscriber.StorageBytesRemaining(newStorageGb);
|
||||
if (remainingStorage < 0)
|
||||
{
|
||||
throw new BadRequestException("You are currently using " +
|
||||
$"{CoreHelpers.ReadableBytesSize(storableSubscriber.Storage.GetValueOrDefault(0))} of storage. " +
|
||||
"Delete some stored data first.");
|
||||
}
|
||||
|
||||
var additionalStorage = newStorageGb - 1;
|
||||
var paymentIntentClientSecret = await paymentService.AdjustStorageAsync(storableSubscriber,
|
||||
additionalStorage, storagePlanId);
|
||||
storableSubscriber.MaxStorageGb = newStorageGb;
|
||||
return paymentIntentClientSecret;
|
||||
throw new ArgumentNullException(nameof(storableSubscriber));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(storableSubscriber.GatewayCustomerId))
|
||||
{
|
||||
throw new BadRequestException("No payment method found.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(storableSubscriber.GatewaySubscriptionId))
|
||||
{
|
||||
throw new BadRequestException("No subscription found.");
|
||||
}
|
||||
|
||||
if (!storableSubscriber.MaxStorageGb.HasValue)
|
||||
{
|
||||
throw new BadRequestException("No access to storage.");
|
||||
}
|
||||
|
||||
var newStorageGb = (short)(storableSubscriber.MaxStorageGb.Value + storageAdjustmentGb);
|
||||
if (newStorageGb < 1)
|
||||
{
|
||||
newStorageGb = 1;
|
||||
}
|
||||
|
||||
if (newStorageGb > 100)
|
||||
{
|
||||
throw new BadRequestException("Maximum storage is 100 GB.");
|
||||
}
|
||||
|
||||
var remainingStorage = storableSubscriber.StorageBytesRemaining(newStorageGb);
|
||||
if (remainingStorage < 0)
|
||||
{
|
||||
throw new BadRequestException("You are currently using " +
|
||||
$"{CoreHelpers.ReadableBytesSize(storableSubscriber.Storage.GetValueOrDefault(0))} of storage. " +
|
||||
"Delete some stored data first.");
|
||||
}
|
||||
|
||||
var additionalStorage = newStorageGb - 1;
|
||||
var paymentIntentClientSecret = await paymentService.AdjustStorageAsync(storableSubscriber,
|
||||
additionalStorage, storagePlanId);
|
||||
storableSubscriber.MaxStorageGb = newStorageGb;
|
||||
return paymentIntentClientSecret;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user