1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-01 23:31:41 +01:00

billing info when self hosted with no gateway info

This commit is contained in:
Kyle Spearrin 2017-08-11 23:23:50 -04:00
parent 67edcd035c
commit a020a7268e
2 changed files with 16 additions and 6 deletions

View File

@ -444,14 +444,16 @@ namespace Bit.Api.Controllers
throw new UnauthorizedAccessException(); throw new UnauthorizedAccessException();
} }
var paymentService = user.GetPaymentService(_globalSettings); if(!_globalSettings.SelfHosted && user.Gateway != null)
var billingInfo = await paymentService.GetBillingAsync(user);
if(billingInfo == null)
{ {
throw new NotFoundException(); var paymentService = user.GetPaymentService(_globalSettings);
var billingInfo = await paymentService.GetBillingAsync(user);
return new BillingResponseModel(user, billingInfo, _licenseService);
}
else
{
return new BillingResponseModel(user);
} }
return new BillingResponseModel(user, billingInfo, _licenseService);
} }
[HttpPut("payment")] [HttpPut("payment")]

View File

@ -23,6 +23,14 @@ namespace Bit.Core.Models.Api
License = new UserLicense(user, billing, licenseService); License = new UserLicense(user, billing, licenseService);
} }
public BillingResponseModel(User user)
: base("billing")
{
StorageName = user.Storage.HasValue ? Utilities.CoreHelpers.ReadableBytesSize(user.Storage.Value) : null;
StorageGb = user.Storage.HasValue ? Math.Round(user.Storage.Value / 1073741824D, 2) : 0; // 1 GB
MaxStorageGb = user.MaxStorageGb;
}
public string StorageName { get; set; } public string StorageName { get; set; }
public double? StorageGb { get; set; } public double? StorageGb { get; set; }
public short? MaxStorageGb { get; set; } public short? MaxStorageGb { get; set; }