mirror of
https://github.com/bitwarden/server
synced 2025-12-15 15:53:59 +00:00
* refactor the plan and create new objects * initial commit * Add new plan types * continue the refactoring by adding new plantypes * changes for plans * Refactoring continues * making changes for plan * Fixing the failing test * Fixing whitespace * Fix some in correct values * Resolve the plan data * rearranging the plan * Make the plan more immutable * Resolve the lint errors * Fix the failing test * Add custom plan * Fix the failing test * Fix the failing test * resolve the failing addons after refactoring * Refactoring * Merge branch 'master' into ac-1451/refactor-staticstore-plans-and-consuming-logic * merge from master * Merge branch 'master' into ac-1451/refactor-staticstore-plans-and-consuming-logic * format whitespace * resolve the conflict * Fix some pr comments * Fixing some of the pr comments * fixing some of the pr comments * Resolve some pr comments * Resolve pr comments * Resolves some pr comments * Resolving some or comments * Resolve a failing test * fix the failing test * Resolving some pr comments * Fix the failing test * resolve pr comment * add a using statement fir a failing test --------- Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
121 lines
4.3 KiB
C#
121 lines
4.3 KiB
C#
using Bit.Core.Entities;
|
|
using Stripe;
|
|
using Plan = Bit.Core.Models.StaticStore.Plan;
|
|
|
|
namespace Bit.Core.Models.Business;
|
|
|
|
public class OrganizationSubscriptionOptionsBase : Stripe.SubscriptionCreateOptions
|
|
{
|
|
public OrganizationSubscriptionOptionsBase(Organization org, StaticStore.Plan plan, TaxInfo taxInfo, int additionalSeats,
|
|
int additionalStorageGb, bool premiumAccessAddon, int additionalSmSeats, int additionalServiceAccounts)
|
|
{
|
|
Items = new List<SubscriptionItemOptions>();
|
|
Metadata = new Dictionary<string, string>
|
|
{
|
|
[org.GatewayIdField()] = org.Id.ToString()
|
|
};
|
|
|
|
AddPlanIdToSubscription(plan);
|
|
|
|
if (org.UseSecretsManager)
|
|
{
|
|
AddSecretsManagerSeat(plan, additionalSmSeats);
|
|
AddServiceAccount(plan, additionalServiceAccounts);
|
|
}
|
|
|
|
AddPremiumAccessAddon(plan, premiumAccessAddon);
|
|
AddPasswordManagerSeat(plan, additionalSeats);
|
|
AddAdditionalStorage(plan, additionalStorageGb);
|
|
|
|
if (!string.IsNullOrWhiteSpace(taxInfo?.StripeTaxRateId))
|
|
{
|
|
DefaultTaxRates = new List<string> { taxInfo.StripeTaxRateId };
|
|
}
|
|
}
|
|
|
|
private void AddSecretsManagerSeat(Plan plan, int additionalSmSeats)
|
|
{
|
|
if (additionalSmSeats > 0 && plan.SecretsManager.StripeSeatPlanId != null)
|
|
{
|
|
Items.Add(new SubscriptionItemOptions
|
|
{ Plan = plan.SecretsManager.StripeSeatPlanId, Quantity = additionalSmSeats });
|
|
}
|
|
}
|
|
|
|
private void AddPasswordManagerSeat(Plan plan, int additionalSeats)
|
|
{
|
|
if (additionalSeats > 0 && plan.PasswordManager.StripeSeatPlanId != null)
|
|
{
|
|
Items.Add(new SubscriptionItemOptions
|
|
{ Plan = plan.PasswordManager.StripeSeatPlanId, Quantity = additionalSeats });
|
|
}
|
|
}
|
|
|
|
private void AddServiceAccount(StaticStore.Plan plan, int additionalServiceAccounts)
|
|
{
|
|
if (additionalServiceAccounts > 0 && plan.SecretsManager.StripeServiceAccountPlanId != null)
|
|
{
|
|
Items.Add(new SubscriptionItemOptions
|
|
{
|
|
Plan = plan.SecretsManager.StripeServiceAccountPlanId,
|
|
Quantity = additionalServiceAccounts
|
|
});
|
|
}
|
|
}
|
|
|
|
private void AddAdditionalStorage(StaticStore.Plan plan, int additionalStorageGb)
|
|
{
|
|
if (additionalStorageGb > 0)
|
|
{
|
|
Items.Add(new SubscriptionItemOptions
|
|
{
|
|
Plan = plan.PasswordManager.StripeStoragePlanId,
|
|
Quantity = additionalStorageGb
|
|
});
|
|
}
|
|
}
|
|
|
|
private void AddPremiumAccessAddon(StaticStore.Plan plan, bool premiumAccessAddon)
|
|
{
|
|
if (premiumAccessAddon && plan.PasswordManager.StripePremiumAccessPlanId != null)
|
|
{
|
|
Items.Add(new SubscriptionItemOptions { Plan = plan.PasswordManager.StripePremiumAccessPlanId, Quantity = 1 });
|
|
}
|
|
}
|
|
|
|
private void AddPlanIdToSubscription(StaticStore.Plan plan)
|
|
{
|
|
if (plan.PasswordManager.StripePlanId != null)
|
|
{
|
|
Items.Add(new SubscriptionItemOptions { Plan = plan.PasswordManager.StripePlanId, Quantity = 1 });
|
|
}
|
|
}
|
|
}
|
|
|
|
public class OrganizationPurchaseSubscriptionOptions : OrganizationSubscriptionOptionsBase
|
|
{
|
|
public OrganizationPurchaseSubscriptionOptions(
|
|
Organization org, StaticStore.Plan plan,
|
|
TaxInfo taxInfo, int additionalSeats,
|
|
int additionalStorageGb, bool premiumAccessAddon,
|
|
int additionalSmSeats, int additionalServiceAccounts) :
|
|
base(org, plan, taxInfo, additionalSeats, additionalStorageGb, premiumAccessAddon, additionalSmSeats, additionalServiceAccounts)
|
|
{
|
|
OffSession = true;
|
|
TrialPeriodDays = plan.TrialPeriodDays;
|
|
}
|
|
}
|
|
|
|
public class OrganizationUpgradeSubscriptionOptions : OrganizationSubscriptionOptionsBase
|
|
{
|
|
public OrganizationUpgradeSubscriptionOptions(
|
|
string customerId, Organization org,
|
|
StaticStore.Plan plan, OrganizationUpgrade upgrade) :
|
|
base(org, plan, upgrade.TaxInfo, upgrade.AdditionalSeats, upgrade.AdditionalStorageGb,
|
|
upgrade.PremiumAccessAddon, upgrade.AdditionalSmSeats.GetValueOrDefault(),
|
|
upgrade.AdditionalServiceAccounts.GetValueOrDefault())
|
|
{
|
|
Customer = customerId;
|
|
}
|
|
}
|