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

apis for org settings & billing

This commit is contained in:
Kyle Spearrin
2017-04-06 16:52:39 -04:00
parent 8ab363cc73
commit 2d7cb1321b
6 changed files with 182 additions and 3 deletions

View File

@ -39,6 +39,40 @@ namespace Bit.Core.Services
_dataProtector = dataProtectionProvider.CreateProtector("OrganizationServiceDataProtector");
_mailService = mailService;
}
public async Task<OrganizationBilling> GetBillingAsync(Organization organization)
{
var orgBilling = new OrganizationBilling();
var customerService = new StripeCustomerService();
var subscriptionService = new StripeSubscriptionService();
var chargeService = new StripeChargeService();
if(!string.IsNullOrWhiteSpace(organization.StripeCustomerId))
{
var customer = await customerService.GetAsync(organization.StripeCustomerId);
if(customer != null)
{
orgBilling.PaymentSource = customer.DefaultSource;
var charges = await chargeService.ListAsync(new StripeChargeListOptions
{
CustomerId = customer.Id,
Limit = 20
});
orgBilling.Charges = charges.OrderByDescending(c => c.Created);
}
}
if(!string.IsNullOrWhiteSpace(organization.StripeSubscriptionId))
{
var sub = await subscriptionService.GetAsync(organization.StripeSubscriptionId);
if(sub != null)
{
orgBilling.Subscription = sub;
}
}
return orgBilling;
}
public async Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup signup)
{