From a020a7268e1b8d6bc32a98c3b9af14e1f5eaa49a Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 11 Aug 2017 23:23:50 -0400 Subject: [PATCH] billing info when self hosted with no gateway info --- src/Api/Controllers/AccountsController.cs | 14 ++++++++------ .../Models/Api/Response/BillingResponseModel.cs | 8 ++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Api/Controllers/AccountsController.cs b/src/Api/Controllers/AccountsController.cs index 34e57461ba..e13d33087c 100644 --- a/src/Api/Controllers/AccountsController.cs +++ b/src/Api/Controllers/AccountsController.cs @@ -444,14 +444,16 @@ namespace Bit.Api.Controllers throw new UnauthorizedAccessException(); } - var paymentService = user.GetPaymentService(_globalSettings); - var billingInfo = await paymentService.GetBillingAsync(user); - if(billingInfo == null) + if(!_globalSettings.SelfHosted && user.Gateway != 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")] diff --git a/src/Core/Models/Api/Response/BillingResponseModel.cs b/src/Core/Models/Api/Response/BillingResponseModel.cs index b71352472e..5d92422e4f 100644 --- a/src/Core/Models/Api/Response/BillingResponseModel.cs +++ b/src/Core/Models/Api/Response/BillingResponseModel.cs @@ -23,6 +23,14 @@ namespace Bit.Core.Models.Api 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 double? StorageGb { get; set; } public short? MaxStorageGb { get; set; }