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

storage in billing and org signup

This commit is contained in:
Kyle Spearrin 2017-07-11 10:25:00 -04:00
parent 879494274a
commit a8ff190fb5
8 changed files with 44 additions and 3 deletions

View File

@ -369,7 +369,7 @@ namespace Bit.Api.Controllers
throw new NotFoundException();
}
return new BillingResponseModel(billingInfo);
return new BillingResponseModel(user, billingInfo);
}
[HttpPut("payment")]

View File

@ -23,6 +23,8 @@ namespace Bit.Core.Models.Api
public string PaymentToken { get; set; }
[Range(0, double.MaxValue)]
public short AdditionalSeats { get; set; }
[Range(0, 99)]
public short? AdditionalStorageGb { get; set; }
public virtual OrganizationSignup ToOrganizationSignup(User user)
{
@ -34,6 +36,7 @@ namespace Bit.Core.Models.Api
Plan = PlanType,
PaymentToken = PaymentToken,
AdditionalSeats = AdditionalSeats,
AdditionalStorageGb = AdditionalStorageGb.GetValueOrDefault(0),
BillingEmail = BillingEmail,
BusinessName = BusinessName
};

View File

@ -3,20 +3,27 @@ using System.Linq;
using System.Collections.Generic;
using Bit.Core.Models.Business;
using Stripe;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api
{
public class BillingResponseModel : ResponseModel
{
public BillingResponseModel(BillingInfo billing)
public BillingResponseModel(IStorable storable, BillingInfo billing)
: base("billing")
{
PaymentSource = billing.PaymentSource != null ? new BillingSource(billing.PaymentSource) : null;
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 = storable.Storage.HasValue ? Utilities.CoreHelpers.ReadableBytesSize(storable.Storage.Value) : null;
StorageGb = storable.Storage.HasValue ? Math.Round(storable.Storage.Value / 1073741824D, 2) : 0; // 1 GB
MaxStorageGb = storable.MaxStorageGb;
}
public string StorageName { get; set; }
public double? StorageGb { get; set; }
public short? MaxStorageGb { get; set; }
public BillingSource PaymentSource { get; set; }
public BillingSubscription Subscription { get; set; }
public BillingInvoice UpcomingInvoice { get; set; }

View File

@ -26,6 +26,7 @@ namespace Bit.Core.Models.Api
MaxCollections = organization.MaxCollections;
UseGroups = organization.UseGroups;
UseDirectory = organization.UseDirectory;
UseTotp = organization.UseTotp;
}
public string Id { get; set; }
@ -38,6 +39,7 @@ namespace Bit.Core.Models.Api
public short? MaxCollections { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseTotp { get; set; }
}
public class OrganizationBillingResponseModel : OrganizationResponseModel
@ -49,8 +51,15 @@ 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 ?
Utilities.CoreHelpers.ReadableBytesSize(organization.Storage.Value) : null;
StorageGb = organization.Storage.HasValue ? Math.Round(organization.Storage.Value / 1073741824D) : 0; // 1 GB
MaxStorageGb = organization.MaxStorageGb;
}
public string StorageName { get; set; }
public double? StorageGb { get; set; }
public short? MaxStorageGb { get; set; }
public BillingSource PaymentSource { get; set; }
public BillingSubscription Subscription { get; set; }
public BillingInvoice UpcomingInvoice { get; set; }

View File

@ -12,6 +12,7 @@ namespace Bit.Core.Models.Business
public string OwnerKey { get; set; }
public Enums.PlanType Plan { get; set; }
public short AdditionalSeats { get; set; }
public short AdditionalStorageGb { get; set; }
public string PaymentToken { get; set; }
}
}

View File

@ -7,6 +7,7 @@ namespace Bit.Core.Models.StaticStore
public string Name { get; set; }
public string StripePlanId { get; set; }
public string StripeSeatPlanId { get; set; }
public string StripStoragePlanId { get; set; }
public PlanType Type { get; set; }
public short BaseSeats { get; set; }
public bool CanBuyAdditionalSeats { get; set; }

View File

@ -334,6 +334,11 @@ namespace Bit.Core.Services
StripeCustomer customer = null;
StripeSubscription subscription = null;
if(!plan.MaxStorageGb.HasValue && signup.AdditionalStorageGb > 0)
{
throw new BadRequestException("Plan does not allow additional storage.");
}
if(plan.BaseSeats + signup.AdditionalSeats <= 0)
{
throw new BadRequestException("You do not have any seats!");
@ -399,6 +404,15 @@ namespace Bit.Core.Services
});
}
if(signup.AdditionalStorageGb > 0)
{
subCreateOptions.Items.Add(new StripeSubscriptionItemOption
{
PlanId = plan.StripStoragePlanId,
Quantity = signup.AdditionalStorageGb
});
}
try
{
subscription = await subscriptionService.CreateAsync(customer.Id, subCreateOptions);
@ -423,7 +437,8 @@ namespace Bit.Core.Services
PlanType = plan.Type,
Seats = (short)(plan.BaseSeats + signup.AdditionalSeats),
MaxCollections = plan.MaxCollections,
MaxStorageGb = plan.MaxStorageGb,
MaxStorageGb = !plan.MaxStorageGb.HasValue ?
(short?)null : (short)(plan.MaxStorageGb.Value + signup.AdditionalStorageGb),
UseGroups = plan.UseGroups,
UseDirectory = plan.UseDirectory,
UseTotp = plan.UseTotp,

View File

@ -110,6 +110,7 @@ namespace Bit.Core.Utilities
Name = "Personal",
StripePlanId = "personal-org-annually",
StripeSeatPlanId = "personal-org-seat-annually",
StripStoragePlanId = "storage-gb-annually",
UpgradeSortOrder = 1,
TrialPeriodDays = 7,
UseTotp = true,
@ -125,6 +126,7 @@ namespace Bit.Core.Utilities
Name = "Teams (Monthly)",
StripePlanId = "teams-org-monthly",
StripeSeatPlanId = "teams-org-seat-monthly",
StripStoragePlanId = "storage-gb-monthly",
UpgradeSortOrder = 2,
TrialPeriodDays = 7,
UseTotp = true,
@ -140,6 +142,7 @@ namespace Bit.Core.Utilities
Name = "Teams (Annually)",
StripePlanId = "teams-org-annually",
StripeSeatPlanId = "teams-org-seat-annually",
StripStoragePlanId = "storage-gb-annually",
UpgradeSortOrder = 2,
TrialPeriodDays = 7,
UseTotp = true,
@ -155,6 +158,7 @@ namespace Bit.Core.Utilities
Name = "Enterprise (Monthly)",
StripePlanId = null,
StripeSeatPlanId = "enterprise-org-seat-monthly",
StripStoragePlanId = "storage-gb-monthly",
UpgradeSortOrder = 3,
TrialPeriodDays = 7,
UseGroups = true,
@ -172,6 +176,7 @@ namespace Bit.Core.Utilities
Name = "Enterprise (Annually)",
StripePlanId = null,
StripeSeatPlanId = "enterprise-org-seat-annually",
StripStoragePlanId = "storage-gb-annually",
UpgradeSortOrder = 3,
TrialPeriodDays = 7,
UseGroups = true,