1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 00:22:50 -05:00

apis for subscription vs billing

This commit is contained in:
Kyle Spearrin
2019-02-18 15:40:47 -05:00
parent 5945c39b32
commit b036657d78
14 changed files with 353 additions and 340 deletions

View File

@ -469,6 +469,7 @@ namespace Bit.Api.Controllers
}
[HttpGet("billing")]
[SelfHosted(NotSelfHostedOnly = true)]
public async Task<BillingResponseModel> GetBilling()
{
var user = await _userService.GetUserByPrincipalAsync(User);
@ -477,20 +478,33 @@ namespace Bit.Api.Controllers
throw new UnauthorizedAccessException();
}
var billingInfo = await _paymentService.GetBillingAsync(user);
return new BillingResponseModel(billingInfo);
}
[HttpGet("subscription")]
public async Task<SubscriptionResponseModel> GetSubscription()
{
var user = await _userService.GetUserByPrincipalAsync(User);
if(user == null)
{
throw new UnauthorizedAccessException();
}
if(!_globalSettings.SelfHosted && user.Gateway != null)
{
var billingInfo = await _paymentService.GetBillingAsync(user);
var license = await _userService.GenerateLicenseAsync(user, billingInfo);
return new BillingResponseModel(user, billingInfo, license);
var subscriptionInfo = await _paymentService.GetSubscriptionAsync(user);
var license = await _userService.GenerateLicenseAsync(user, subscriptionInfo);
return new SubscriptionResponseModel(user, subscriptionInfo, license);
}
else if(!_globalSettings.SelfHosted)
{
var license = await _userService.GenerateLicenseAsync(user);
return new BillingResponseModel(user, license);
return new SubscriptionResponseModel(user, license);
}
else
{
return new BillingResponseModel(user);
return new SubscriptionResponseModel(user);
}
}