mirror of
https://github.com/bitwarden/server
synced 2025-12-20 18:23:44 +00:00
* Upgrade Stripe.net to v48.4.0 * Update PreviewTaxAmountCommand * Remove unused UpcomingInvoiceOptionExtensions * Added SubscriptionExtensions with GetCurrentPeriodEnd * Update PremiumUserBillingService * Update OrganizationBillingService * Update GetOrganizationWarningsQuery * Update BillingHistoryInfo * Update SubscriptionInfo * Remove unused Sql Billing folder * Update StripeAdapter * Update StripePaymentService * Update InvoiceCreatedHandler * Update PaymentFailedHandler * Update PaymentSucceededHandler * Update ProviderEventService * Update StripeEventUtilityService * Update SubscriptionDeletedHandler * Update SubscriptionUpdatedHandler * Update UpcomingInvoiceHandler * Update ProviderSubscriptionResponse * Remove unused Stripe Subscriptions Admin Tool * Update RemoveOrganizationFromProviderCommand * Update ProviderBillingService * Update RemoveOrganizatinoFromProviderCommandTests * Update PreviewTaxAmountCommandTests * Update GetCloudOrganizationLicenseQueryTests * Update GetOrganizationWarningsQueryTests * Update StripePaymentServiceTests * Update ProviderBillingControllerTests * Update ProviderEventServiceTests * Update SubscriptionDeletedHandlerTests * Update SubscriptionUpdatedHandlerTests * Resolve Billing test failures I completely removed tests for the StripeEventService as they were using a system I setup a while back that read JSON files of the Stripe event structure. I did not anticipate how frequently these structures would change with each API version and the cost of trying to update these specific JSON files to test a very static data retrieval service far outweigh the benefit. * Resolve Core test failures * Run dotnet format * Remove unused provider migration * Fixed failing tests * Run dotnet format * Replace the old webhook secret key with new one (#6223) * Fix compilation failures in additions * Run dotnet format * Bump Stripe API version * Fix recent addition: CreatePremiumCloudHostedSubscriptionCommand * Fix new code in main according to Stripe update * Fix InvoiceExtensions * Bump SDK version to match API Version * Fix provider invoice generation validation * More QA fixes * Fix tests * QA defect resolutions * QA defect resolutions * Run dotnet format * Fix tests --------- Co-authored-by: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com>
114 lines
3.6 KiB
C#
114 lines
3.6 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.Billing.Constants;
|
|
using Bit.Core.Billing.Models;
|
|
using Bit.Core.Billing.Models.Sales;
|
|
using Bit.Core.Billing.Tax.Models;
|
|
using Bit.Core.Models.Business;
|
|
|
|
namespace Bit.Core.Billing.Organizations.Models;
|
|
|
|
public class OrganizationSale
|
|
{
|
|
internal OrganizationSale() { }
|
|
|
|
public void Deconstruct(
|
|
out Organization organization,
|
|
out CustomerSetup? customerSetup,
|
|
out SubscriptionSetup subscriptionSetup)
|
|
{
|
|
organization = Organization;
|
|
customerSetup = CustomerSetup;
|
|
subscriptionSetup = SubscriptionSetup;
|
|
}
|
|
|
|
public required Organization Organization { get; init; }
|
|
public CustomerSetup? CustomerSetup { get; init; }
|
|
public required SubscriptionSetup SubscriptionSetup { get; init; }
|
|
|
|
public static OrganizationSale From(
|
|
Organization organization,
|
|
OrganizationSignup signup)
|
|
{
|
|
var customerSetup = string.IsNullOrEmpty(organization.GatewayCustomerId) ? GetCustomerSetup(signup) : null;
|
|
|
|
var subscriptionSetup = GetSubscriptionSetup(signup);
|
|
|
|
subscriptionSetup.SkipTrial = signup.SkipTrial;
|
|
subscriptionSetup.InitiationPath = signup.InitiationPath;
|
|
|
|
return new OrganizationSale
|
|
{
|
|
Organization = organization,
|
|
CustomerSetup = customerSetup,
|
|
SubscriptionSetup = subscriptionSetup
|
|
};
|
|
}
|
|
|
|
public static OrganizationSale From(
|
|
Organization organization,
|
|
OrganizationUpgrade upgrade) => new()
|
|
{
|
|
Organization = organization,
|
|
SubscriptionSetup = GetSubscriptionSetup(upgrade)
|
|
};
|
|
|
|
private static CustomerSetup GetCustomerSetup(OrganizationSignup signup)
|
|
{
|
|
var customerSetup = new CustomerSetup
|
|
{
|
|
Coupon = signup.IsFromProvider
|
|
// TODO: Remove when last of the legacy providers has been migrated.
|
|
? StripeConstants.CouponIDs.LegacyMSPDiscount
|
|
: signup.IsFromSecretsManagerTrial
|
|
? StripeConstants.CouponIDs.SecretsManagerStandalone
|
|
: null
|
|
};
|
|
|
|
if (!signup.PaymentMethodType.HasValue)
|
|
{
|
|
return customerSetup;
|
|
}
|
|
|
|
customerSetup.TokenizedPaymentSource = new TokenizedPaymentSource(
|
|
signup.PaymentMethodType!.Value,
|
|
signup.PaymentToken);
|
|
|
|
customerSetup.TaxInformation = new TaxInformation(
|
|
signup.TaxInfo.BillingAddressCountry,
|
|
signup.TaxInfo.BillingAddressPostalCode,
|
|
signup.TaxInfo.TaxIdNumber,
|
|
signup.TaxInfo.TaxIdType,
|
|
signup.TaxInfo.BillingAddressLine1,
|
|
signup.TaxInfo.BillingAddressLine2,
|
|
signup.TaxInfo.BillingAddressCity,
|
|
signup.TaxInfo.BillingAddressState);
|
|
|
|
return customerSetup;
|
|
}
|
|
|
|
private static SubscriptionSetup GetSubscriptionSetup(OrganizationUpgrade upgrade)
|
|
{
|
|
var passwordManagerOptions = new SubscriptionSetup.PasswordManager
|
|
{
|
|
Seats = upgrade.AdditionalSeats,
|
|
Storage = upgrade.AdditionalStorageGb,
|
|
PremiumAccess = upgrade.PremiumAccessAddon
|
|
};
|
|
|
|
var secretsManagerOptions = upgrade.UseSecretsManager
|
|
? new SubscriptionSetup.SecretsManager
|
|
{
|
|
Seats = upgrade.AdditionalSmSeats ?? 0,
|
|
ServiceAccounts = upgrade.AdditionalServiceAccounts
|
|
}
|
|
: null;
|
|
|
|
return new SubscriptionSetup
|
|
{
|
|
PlanType = upgrade.Plan,
|
|
PasswordManagerOptions = passwordManagerOptions,
|
|
SecretsManagerOptions = secretsManagerOptions
|
|
};
|
|
}
|
|
}
|