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:
parent
879494274a
commit
a8ff190fb5
@ -369,7 +369,7 @@ namespace Bit.Api.Controllers
|
|||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BillingResponseModel(billingInfo);
|
return new BillingResponseModel(user, billingInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("payment")]
|
[HttpPut("payment")]
|
||||||
|
@ -23,6 +23,8 @@ namespace Bit.Core.Models.Api
|
|||||||
public string PaymentToken { get; set; }
|
public string PaymentToken { get; set; }
|
||||||
[Range(0, double.MaxValue)]
|
[Range(0, double.MaxValue)]
|
||||||
public short AdditionalSeats { get; set; }
|
public short AdditionalSeats { get; set; }
|
||||||
|
[Range(0, 99)]
|
||||||
|
public short? AdditionalStorageGb { get; set; }
|
||||||
|
|
||||||
public virtual OrganizationSignup ToOrganizationSignup(User user)
|
public virtual OrganizationSignup ToOrganizationSignup(User user)
|
||||||
{
|
{
|
||||||
@ -34,6 +36,7 @@ namespace Bit.Core.Models.Api
|
|||||||
Plan = PlanType,
|
Plan = PlanType,
|
||||||
PaymentToken = PaymentToken,
|
PaymentToken = PaymentToken,
|
||||||
AdditionalSeats = AdditionalSeats,
|
AdditionalSeats = AdditionalSeats,
|
||||||
|
AdditionalStorageGb = AdditionalStorageGb.GetValueOrDefault(0),
|
||||||
BillingEmail = BillingEmail,
|
BillingEmail = BillingEmail,
|
||||||
BusinessName = BusinessName
|
BusinessName = BusinessName
|
||||||
};
|
};
|
||||||
|
@ -3,20 +3,27 @@ using System.Linq;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Bit.Core.Models.Business;
|
using Bit.Core.Models.Business;
|
||||||
using Stripe;
|
using Stripe;
|
||||||
|
using Bit.Core.Models.Table;
|
||||||
|
|
||||||
namespace Bit.Core.Models.Api
|
namespace Bit.Core.Models.Api
|
||||||
{
|
{
|
||||||
public class BillingResponseModel : ResponseModel
|
public class BillingResponseModel : ResponseModel
|
||||||
{
|
{
|
||||||
public BillingResponseModel(BillingInfo billing)
|
public BillingResponseModel(IStorable storable, BillingInfo billing)
|
||||||
: base("billing")
|
: base("billing")
|
||||||
{
|
{
|
||||||
PaymentSource = billing.PaymentSource != null ? new BillingSource(billing.PaymentSource) : null;
|
PaymentSource = billing.PaymentSource != null ? new BillingSource(billing.PaymentSource) : null;
|
||||||
Subscription = billing.Subscription != null ? new BillingSubscription(billing.Subscription) : null;
|
Subscription = billing.Subscription != null ? new BillingSubscription(billing.Subscription) : null;
|
||||||
Charges = billing.Charges.Select(c => new BillingCharge(c));
|
Charges = billing.Charges.Select(c => new BillingCharge(c));
|
||||||
UpcomingInvoice = billing.UpcomingInvoice != null ? new BillingInvoice(billing.UpcomingInvoice) : null;
|
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 BillingSource PaymentSource { get; set; }
|
||||||
public BillingSubscription Subscription { get; set; }
|
public BillingSubscription Subscription { get; set; }
|
||||||
public BillingInvoice UpcomingInvoice { get; set; }
|
public BillingInvoice UpcomingInvoice { get; set; }
|
||||||
|
@ -26,6 +26,7 @@ namespace Bit.Core.Models.Api
|
|||||||
MaxCollections = organization.MaxCollections;
|
MaxCollections = organization.MaxCollections;
|
||||||
UseGroups = organization.UseGroups;
|
UseGroups = organization.UseGroups;
|
||||||
UseDirectory = organization.UseDirectory;
|
UseDirectory = organization.UseDirectory;
|
||||||
|
UseTotp = organization.UseTotp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
@ -38,6 +39,7 @@ namespace Bit.Core.Models.Api
|
|||||||
public short? MaxCollections { get; set; }
|
public short? MaxCollections { get; set; }
|
||||||
public bool UseGroups { get; set; }
|
public bool UseGroups { get; set; }
|
||||||
public bool UseDirectory { get; set; }
|
public bool UseDirectory { get; set; }
|
||||||
|
public bool UseTotp { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class OrganizationBillingResponseModel : OrganizationResponseModel
|
public class OrganizationBillingResponseModel : OrganizationResponseModel
|
||||||
@ -49,8 +51,15 @@ namespace Bit.Core.Models.Api
|
|||||||
Subscription = billing.Subscription != null ? new BillingSubscription(billing.Subscription) : null;
|
Subscription = billing.Subscription != null ? new BillingSubscription(billing.Subscription) : null;
|
||||||
Charges = billing.Charges.Select(c => new BillingCharge(c));
|
Charges = billing.Charges.Select(c => new BillingCharge(c));
|
||||||
UpcomingInvoice = billing.UpcomingInvoice != null ? new BillingInvoice(billing.UpcomingInvoice) : null;
|
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 BillingSource PaymentSource { get; set; }
|
||||||
public BillingSubscription Subscription { get; set; }
|
public BillingSubscription Subscription { get; set; }
|
||||||
public BillingInvoice UpcomingInvoice { get; set; }
|
public BillingInvoice UpcomingInvoice { get; set; }
|
||||||
|
@ -12,6 +12,7 @@ namespace Bit.Core.Models.Business
|
|||||||
public string OwnerKey { get; set; }
|
public string OwnerKey { get; set; }
|
||||||
public Enums.PlanType Plan { get; set; }
|
public Enums.PlanType Plan { get; set; }
|
||||||
public short AdditionalSeats { get; set; }
|
public short AdditionalSeats { get; set; }
|
||||||
|
public short AdditionalStorageGb { get; set; }
|
||||||
public string PaymentToken { get; set; }
|
public string PaymentToken { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ namespace Bit.Core.Models.StaticStore
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string StripePlanId { get; set; }
|
public string StripePlanId { get; set; }
|
||||||
public string StripeSeatPlanId { get; set; }
|
public string StripeSeatPlanId { get; set; }
|
||||||
|
public string StripStoragePlanId { get; set; }
|
||||||
public PlanType Type { get; set; }
|
public PlanType Type { get; set; }
|
||||||
public short BaseSeats { get; set; }
|
public short BaseSeats { get; set; }
|
||||||
public bool CanBuyAdditionalSeats { get; set; }
|
public bool CanBuyAdditionalSeats { get; set; }
|
||||||
|
@ -334,6 +334,11 @@ namespace Bit.Core.Services
|
|||||||
StripeCustomer customer = null;
|
StripeCustomer customer = null;
|
||||||
StripeSubscription subscription = 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)
|
if(plan.BaseSeats + signup.AdditionalSeats <= 0)
|
||||||
{
|
{
|
||||||
throw new BadRequestException("You do not have any seats!");
|
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
|
try
|
||||||
{
|
{
|
||||||
subscription = await subscriptionService.CreateAsync(customer.Id, subCreateOptions);
|
subscription = await subscriptionService.CreateAsync(customer.Id, subCreateOptions);
|
||||||
@ -423,7 +437,8 @@ namespace Bit.Core.Services
|
|||||||
PlanType = plan.Type,
|
PlanType = plan.Type,
|
||||||
Seats = (short)(plan.BaseSeats + signup.AdditionalSeats),
|
Seats = (short)(plan.BaseSeats + signup.AdditionalSeats),
|
||||||
MaxCollections = plan.MaxCollections,
|
MaxCollections = plan.MaxCollections,
|
||||||
MaxStorageGb = plan.MaxStorageGb,
|
MaxStorageGb = !plan.MaxStorageGb.HasValue ?
|
||||||
|
(short?)null : (short)(plan.MaxStorageGb.Value + signup.AdditionalStorageGb),
|
||||||
UseGroups = plan.UseGroups,
|
UseGroups = plan.UseGroups,
|
||||||
UseDirectory = plan.UseDirectory,
|
UseDirectory = plan.UseDirectory,
|
||||||
UseTotp = plan.UseTotp,
|
UseTotp = plan.UseTotp,
|
||||||
|
@ -110,6 +110,7 @@ namespace Bit.Core.Utilities
|
|||||||
Name = "Personal",
|
Name = "Personal",
|
||||||
StripePlanId = "personal-org-annually",
|
StripePlanId = "personal-org-annually",
|
||||||
StripeSeatPlanId = "personal-org-seat-annually",
|
StripeSeatPlanId = "personal-org-seat-annually",
|
||||||
|
StripStoragePlanId = "storage-gb-annually",
|
||||||
UpgradeSortOrder = 1,
|
UpgradeSortOrder = 1,
|
||||||
TrialPeriodDays = 7,
|
TrialPeriodDays = 7,
|
||||||
UseTotp = true,
|
UseTotp = true,
|
||||||
@ -125,6 +126,7 @@ namespace Bit.Core.Utilities
|
|||||||
Name = "Teams (Monthly)",
|
Name = "Teams (Monthly)",
|
||||||
StripePlanId = "teams-org-monthly",
|
StripePlanId = "teams-org-monthly",
|
||||||
StripeSeatPlanId = "teams-org-seat-monthly",
|
StripeSeatPlanId = "teams-org-seat-monthly",
|
||||||
|
StripStoragePlanId = "storage-gb-monthly",
|
||||||
UpgradeSortOrder = 2,
|
UpgradeSortOrder = 2,
|
||||||
TrialPeriodDays = 7,
|
TrialPeriodDays = 7,
|
||||||
UseTotp = true,
|
UseTotp = true,
|
||||||
@ -140,6 +142,7 @@ namespace Bit.Core.Utilities
|
|||||||
Name = "Teams (Annually)",
|
Name = "Teams (Annually)",
|
||||||
StripePlanId = "teams-org-annually",
|
StripePlanId = "teams-org-annually",
|
||||||
StripeSeatPlanId = "teams-org-seat-annually",
|
StripeSeatPlanId = "teams-org-seat-annually",
|
||||||
|
StripStoragePlanId = "storage-gb-annually",
|
||||||
UpgradeSortOrder = 2,
|
UpgradeSortOrder = 2,
|
||||||
TrialPeriodDays = 7,
|
TrialPeriodDays = 7,
|
||||||
UseTotp = true,
|
UseTotp = true,
|
||||||
@ -155,6 +158,7 @@ namespace Bit.Core.Utilities
|
|||||||
Name = "Enterprise (Monthly)",
|
Name = "Enterprise (Monthly)",
|
||||||
StripePlanId = null,
|
StripePlanId = null,
|
||||||
StripeSeatPlanId = "enterprise-org-seat-monthly",
|
StripeSeatPlanId = "enterprise-org-seat-monthly",
|
||||||
|
StripStoragePlanId = "storage-gb-monthly",
|
||||||
UpgradeSortOrder = 3,
|
UpgradeSortOrder = 3,
|
||||||
TrialPeriodDays = 7,
|
TrialPeriodDays = 7,
|
||||||
UseGroups = true,
|
UseGroups = true,
|
||||||
@ -172,6 +176,7 @@ namespace Bit.Core.Utilities
|
|||||||
Name = "Enterprise (Annually)",
|
Name = "Enterprise (Annually)",
|
||||||
StripePlanId = null,
|
StripePlanId = null,
|
||||||
StripeSeatPlanId = "enterprise-org-seat-annually",
|
StripeSeatPlanId = "enterprise-org-seat-annually",
|
||||||
|
StripStoragePlanId = "storage-gb-annually",
|
||||||
UpgradeSortOrder = 3,
|
UpgradeSortOrder = 3,
|
||||||
TrialPeriodDays = 7,
|
TrialPeriodDays = 7,
|
||||||
UseGroups = true,
|
UseGroups = true,
|
||||||
|
Loading…
Reference in New Issue
Block a user