1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

billing response for org

This commit is contained in:
Kyle Spearrin 2017-08-14 22:05:37 -04:00
parent 5370c2303e
commit 63a82336c6
3 changed files with 34 additions and 10 deletions

View File

@ -25,6 +25,7 @@ namespace Bit.Api.Controllers
private readonly IOrganizationService _organizationService;
private readonly IUserService _userService;
private readonly CurrentContext _currentContext;
private readonly GlobalSettings _globalSettings;
private readonly UserManager<User> _userManager;
public OrganizationsController(
@ -33,6 +34,7 @@ namespace Bit.Api.Controllers
IOrganizationService organizationService,
IUserService userService,
CurrentContext currentContext,
GlobalSettings globalSettings,
UserManager<User> userManager)
{
_organizationRepository = organizationRepository;
@ -41,6 +43,7 @@ namespace Bit.Api.Controllers
_userService = userService;
_currentContext = currentContext;
_userManager = userManager;
_globalSettings = globalSettings;
}
[HttpGet("{id}")]
@ -76,14 +79,20 @@ namespace Bit.Api.Controllers
throw new NotFoundException();
}
var paymentService = new StripePaymentService();
var billingInfo = await paymentService.GetBillingAsync(organization);
if(billingInfo == null)
if(!_globalSettings.SelfHosted && organization.Gateway != null)
{
throw new NotFoundException();
var paymentService = new StripePaymentService();
var billingInfo = await paymentService.GetBillingAsync(organization);
if(billingInfo == null)
{
throw new NotFoundException();
}
return new OrganizationBillingResponseModel(organization, billingInfo);
}
else
{
return new OrganizationBillingResponseModel(organization);
}
return new OrganizationBillingResponseModel(organization, billingInfo);
}
[HttpGet("")]
@ -208,7 +217,7 @@ namespace Bit.Api.Controllers
await _organizationService.AdjustStorageAsync(orgIdGuid, model.StorageGbAdjustment.Value);
}
[HttpPost("{id}/verify-bank")]
[SelfHosted(NotSelfHostedOnly = true)]
public async Task PostVerifyBank(string id, [FromBody]OrganizationVerifyBankRequestModel model)
@ -307,13 +316,13 @@ namespace Bit.Api.Controllers
throw new NotFoundException();
}
var license = await ApiHelpers.ReadJsonFileFromBody<UserLicense>(HttpContext, model.License);
var license = await ApiHelpers.ReadJsonFileFromBody<OrganizationLicense>(HttpContext, model.License);
if(license == null)
{
throw new BadRequestException("Invalid license");
}
await _organizationService.UpdateLicenseAsync(id, license);
await _organizationService.UpdateLicenseAsync(new Guid(id), license);
}
[HttpPost("{id}/import")]

View File

@ -51,10 +51,22 @@ namespace Bit.Core.Models.Api
Subscription = billing.Subscription != null ? new BillingSubscription(billing.Subscription) : null;
Charges = billing.Charges.Select(c => new BillingCharge(c));
UpcomingInvoice = billing.UpcomingInvoice != null ? new BillingInvoice(billing.UpcomingInvoice) : null;
StorageName = organization.Storage.HasValue ?
StorageName = organization.Storage.HasValue ?
Utilities.CoreHelpers.ReadableBytesSize(organization.Storage.Value) : null;
StorageGb = organization.Storage.HasValue ? Math.Round(organization.Storage.Value / 1073741824D) : 0; // 1 GB
MaxStorageGb = organization.MaxStorageGb;
// License = ...
Expiration = DateTime.UtcNow.AddYears(1);
}
public OrganizationBillingResponseModel(Organization organization)
: base(organization, "organizationBilling")
{
StorageName = organization.Storage.HasValue ?
Utilities.CoreHelpers.ReadableBytesSize(organization.Storage.Value) : null;
StorageGb = organization.Storage.HasValue ? Math.Round(organization.Storage.Value / 1073741824D, 2) : 0; // 1 GB
MaxStorageGb = organization.MaxStorageGb;
Expiration = organization.ExpirationDate;
}
public string StorageName { get; set; }
@ -64,5 +76,7 @@ namespace Bit.Core.Models.Api
public BillingSubscription Subscription { get; set; }
public BillingInvoice UpcomingInvoice { get; set; }
public IEnumerable<BillingCharge> Charges { get; set; }
public OrganizationLicense License { get; set; }
public DateTime? Expiration { get; set; }
}
}

View File

@ -19,6 +19,7 @@ namespace Bit.Core.Services
Task VerifyBankAsync(Guid organizationId, int amount1, int amount2);
Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup organizationSignup);
Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationLicense license, User owner, string ownerKey);
Task UpdateLicenseAsync(Guid organizationId, OrganizationLicense license);
Task DeleteAsync(Organization organization);
Task DisableAsync(Guid organizationId, DateTime? expirationDate);
Task UpdateExpirationDateAsync(Guid organizationId, DateTime? expirationDate);