Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-11730] Remove feature flag: AC-2476-deprecate-stripe-sources-api #5201

Merged
26 changes: 0 additions & 26 deletions src/Api/Billing/Controllers/OrganizationBillingController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
๏ปฟ#nullable enable
using Bit.Api.Billing.Models.Requests;
using Bit.Api.Billing.Models.Responses;
using Bit.Core;
using Bit.Core.Billing.Services;
using Bit.Core.Context;
using Bit.Core.Repositories;
Expand Down Expand Up @@ -136,11 +135,6 @@ public async Task<IResult> GetBillingAsync(Guid organizationId)
[HttpGet("payment-method")]
public async Task<IResult> GetPaymentMethodAsync([FromRoute] Guid organizationId)
{
if (!featureService.IsEnabled(FeatureFlagKeys.AC2476_DeprecateStripeSourcesAPI))
{
return Error.NotFound();
}

if (!await currentContext.EditPaymentMethods(organizationId))
{
return Error.Unauthorized();
Expand All @@ -165,11 +159,6 @@ public async Task<IResult> UpdatePaymentMethodAsync(
[FromRoute] Guid organizationId,
[FromBody] UpdatePaymentMethodRequestBody requestBody)
{
if (!featureService.IsEnabled(FeatureFlagKeys.AC2476_DeprecateStripeSourcesAPI))
{
return Error.NotFound();
}

if (!await currentContext.EditPaymentMethods(organizationId))
{
return Error.Unauthorized();
Expand All @@ -196,11 +185,6 @@ public async Task<IResult> VerifyBankAccountAsync(
[FromRoute] Guid organizationId,
[FromBody] VerifyBankAccountRequestBody requestBody)
{
if (!featureService.IsEnabled(FeatureFlagKeys.AC2476_DeprecateStripeSourcesAPI))
{
return Error.NotFound();
}

if (!await currentContext.EditPaymentMethods(organizationId))
{
return Error.Unauthorized();
Expand All @@ -226,11 +210,6 @@ public async Task<IResult> VerifyBankAccountAsync(
[HttpGet("tax-information")]
public async Task<IResult> GetTaxInformationAsync([FromRoute] Guid organizationId)
{
if (!featureService.IsEnabled(FeatureFlagKeys.AC2476_DeprecateStripeSourcesAPI))
{
return Error.NotFound();
}

if (!await currentContext.EditPaymentMethods(organizationId))
{
return Error.Unauthorized();
Expand All @@ -255,11 +234,6 @@ public async Task<IResult> UpdateTaxInformationAsync(
[FromRoute] Guid organizationId,
[FromBody] TaxInformationRequestBody requestBody)
{
if (!featureService.IsEnabled(FeatureFlagKeys.AC2476_DeprecateStripeSourcesAPI))
{
return Error.NotFound();
}

if (!await currentContext.EditPaymentMethods(organizationId))
{
return Error.Unauthorized();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class CloudOrganizationSignUpCommand(
IOrganizationUserRepository organizationUserRepository,
IFeatureService featureService,

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (win-x64)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (MsSqlMigratorUtility, ./util, true)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Identity, ./src)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Setup, ./util)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (linux-x64)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Api, ./src)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Events, ./src)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Billing, ./src)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (osx-x64)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Icons, ./src)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (EventsProcessor, ./src)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Notifications, ./src)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Scim, ./bitwarden_license/src, true)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Sso, ./bitwarden_license/src, true)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Quality scan

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Admin, ./src, true)

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Run tests

Parameter 'featureService' is unread.

Check warning on line 35 in src/Core/AdminConsole/OrganizationFeatures/Organizations/CloudOrganizationSignUpCommand.cs

View workflow job for this annotation

GitHub Actions / Upload

Parameter 'featureService' is unread.
IOrganizationBillingService organizationBillingService,
IPaymentService paymentService,
IPolicyService policyService,
Expand Down Expand Up @@ -124,28 +124,8 @@
}
else if (plan.Type != PlanType.Free)
{
if (featureService.IsEnabled(FeatureFlagKeys.AC2476_DeprecateStripeSourcesAPI))
{
var sale = OrganizationSale.From(organization, signup);
await organizationBillingService.Finalize(sale);
}
else
{
if (signup.PaymentMethodType != null)
{
await paymentService.PurchaseOrganizationAsync(organization, signup.PaymentMethodType.Value,
signup.PaymentToken, plan, signup.AdditionalStorageGb, signup.AdditionalSeats,
signup.PremiumAccessAddon, signup.TaxInfo, signup.IsFromProvider, signup.AdditionalSmSeats.GetValueOrDefault(),
signup.AdditionalServiceAccounts.GetValueOrDefault(), signup.IsFromSecretsManagerTrial);
}
else
{
await paymentService.PurchaseOrganizationNoPaymentMethod(organization, plan, signup.AdditionalSeats,
signup.PremiumAccessAddon, signup.AdditionalSmSeats.GetValueOrDefault(),
signup.AdditionalServiceAccounts.GetValueOrDefault(), signup.IsFromSecretsManagerTrial);
}

}
var sale = OrganizationSale.From(organization, signup);
await organizationBillingService.Finalize(sale);
}

var ownerId = signup.IsFromProvider ? default : signup.Owner.Id;
Expand Down
1 change: 0 additions & 1 deletion src/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public static class FeatureFlagKeys
public const string NativeCreateAccountFlow = "native-create-account-flow";
public const string AccountDeprovisioning = "pm-10308-account-deprovisioning";
public const string NotificationBarAddLoginImprovements = "notification-bar-add-login-improvements";
public const string AC2476_DeprecateStripeSourcesAPI = "AC-2476-deprecate-stripe-sources-api";
public const string PersistPopupView = "persist-popup-view";
public const string CipherKeyEncryption = "cipher-key-encryption";
public const string EnableNewCardCombinedExpiryAutofill = "enable-new-card-combined-expiry-autofill";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,8 @@ await _organizationUserRepository.GetManyByOrganizationAsync(organization.Id,

if (string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId))
{
if (_featureService.IsEnabled(FeatureFlagKeys.AC2476_DeprecateStripeSourcesAPI))
{
var sale = OrganizationSale.From(organization, upgrade);
await _organizationBillingService.Finalize(sale);
}
else
{
try
{
paymentIntentClientSecret = await _paymentService.UpgradeFreeOrganizationAsync(organization,
newPlan, upgrade);
success = string.IsNullOrWhiteSpace(paymentIntentClientSecret);
}
catch
{
await _paymentService.CancelAndRecoverChargesAsync(organization);
organization.GatewayCustomerId = null;
await _organizationService.ReplaceAndUpdateCacheAsync(organization);
throw;
}
}
var sale = OrganizationSale.From(organization, upgrade);
await _organizationBillingService.Finalize(sale);
}
else
{
Expand Down
14 changes: 2 additions & 12 deletions src/Core/Services/Implementations/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -928,18 +928,8 @@
}
else
{
var deprecateStripeSourcesAPI = _featureService.IsEnabled(FeatureFlagKeys.AC2476_DeprecateStripeSourcesAPI);

if (deprecateStripeSourcesAPI)
{
var sale = PremiumUserSale.From(user, paymentMethodType, paymentToken, taxInfo, additionalStorageGb);
await _premiumUserBillingService.Finalize(sale);
}
else
{
paymentIntentClientSecret = await _paymentService.PurchasePremiumAsync(user, paymentMethodType,
paymentToken, additionalStorageGb, taxInfo);
}
var sale = PremiumUserSale.From(user, paymentMethodType, paymentToken, taxInfo, additionalStorageGb);
await _premiumUserBillingService.Finalize(sale);

Check warning on line 932 in src/Core/Services/Implementations/UserService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Services/Implementations/UserService.cs#L931-L932

Added lines #L931 - L932 were not covered by tests
}

user.Premium = true;
Expand Down
8 changes: 7 additions & 1 deletion test/Api.IntegrationTest/Helpers/OrganizationTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ public static async Task<Tuple<Organization, OrganizationUser>> SignUpAsync<T>(W
OwnerKey = ownerKey,
Owner = owner,
AdditionalSeats = passwordManagerSeats,
PaymentMethodType = paymentMethod
PaymentMethodType = paymentMethod,
PaymentToken = "TOKEN",
TaxInfo = new TaxInfo
{
BillingAddressCountry = "US",
BillingAddressPostalCode = "12345"
}
});

Debug.Assert(signUpResult.OrganizationUser is not null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
๏ปฟusing Bit.Core.AdminConsole.Entities;
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations;
using Bit.Core.Billing.Enums;
using Bit.Core.Billing.Models.Sales;
using Bit.Core.Billing.Services;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Models.Business;
using Bit.Core.Models.Data;
using Bit.Core.Models.StaticStore;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Tools.Enums;
using Bit.Core.Tools.Models.Business;
using Bit.Core.Tools.Services;
Expand Down Expand Up @@ -59,20 +59,16 @@ await sutProvider.GetDependency<IReferenceEventService>().Received(1)
Assert.NotNull(result.Organization);
Assert.NotNull(result.OrganizationUser);

await sutProvider.GetDependency<IPaymentService>().Received(1).PurchaseOrganizationAsync(
Arg.Any<Organization>(),
signup.PaymentMethodType.Value,
signup.PaymentToken,
plan,
signup.AdditionalStorageGb,
signup.AdditionalSeats,
signup.PremiumAccessAddon,
signup.TaxInfo,
false,
signup.AdditionalSmSeats.GetValueOrDefault(),
signup.AdditionalServiceAccounts.GetValueOrDefault(),
signup.UseSecretsManager
);
await sutProvider.GetDependency<IOrganizationBillingService>().Received(1).Finalize(
Arg.Is<OrganizationSale>(sale =>
sale.CustomerSetup.TokenizedPaymentSource.Type == signup.PaymentMethodType.Value &&
sale.CustomerSetup.TokenizedPaymentSource.Token == signup.PaymentToken &&
sale.CustomerSetup.TaxInformation.Country == signup.TaxInfo.BillingAddressCountry &&
sale.CustomerSetup.TaxInformation.PostalCode == signup.TaxInfo.BillingAddressPostalCode &&
sale.SubscriptionSetup.Plan == plan &&
sale.SubscriptionSetup.PasswordManagerOptions.Seats == signup.AdditionalSeats &&
sale.SubscriptionSetup.PasswordManagerOptions.Storage == signup.AdditionalStorageGb &&
sale.SubscriptionSetup.SecretsManagerOptions == null));
}

[Theory]
Expand Down Expand Up @@ -151,20 +147,17 @@ await sutProvider.GetDependency<IReferenceEventService>().Received(1)
Assert.NotNull(result.Organization);
Assert.NotNull(result.OrganizationUser);

await sutProvider.GetDependency<IPaymentService>().Received(1).PurchaseOrganizationAsync(
Arg.Any<Organization>(),
signup.PaymentMethodType.Value,
signup.PaymentToken,
Arg.Is<Plan>(plan),
signup.AdditionalStorageGb,
signup.AdditionalSeats,
signup.PremiumAccessAddon,
signup.TaxInfo,
false,
signup.AdditionalSmSeats.GetValueOrDefault(),
signup.AdditionalServiceAccounts.GetValueOrDefault(),
signup.IsFromSecretsManagerTrial
);
await sutProvider.GetDependency<IOrganizationBillingService>().Received(1).Finalize(
Arg.Is<OrganizationSale>(sale =>
sale.CustomerSetup.TokenizedPaymentSource.Type == signup.PaymentMethodType.Value &&
sale.CustomerSetup.TokenizedPaymentSource.Token == signup.PaymentToken &&
sale.CustomerSetup.TaxInformation.Country == signup.TaxInfo.BillingAddressCountry &&
sale.CustomerSetup.TaxInformation.PostalCode == signup.TaxInfo.BillingAddressPostalCode &&
sale.SubscriptionSetup.Plan == plan &&
sale.SubscriptionSetup.PasswordManagerOptions.Seats == signup.AdditionalSeats &&
sale.SubscriptionSetup.PasswordManagerOptions.Storage == signup.AdditionalStorageGb &&
sale.SubscriptionSetup.SecretsManagerOptions.Seats == signup.AdditionalSmSeats &&
sale.SubscriptionSetup.SecretsManagerOptions.ServiceAccounts == signup.AdditionalServiceAccounts));
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ await sutProvider.GetDependency<IOrganizationService>().Received(1).ReplaceAndUp
&& o.SmServiceAccounts == plan.SecretsManager.BaseServiceAccount + upgrade.AdditionalServiceAccounts));

Assert.True(result.Item1);
Assert.NotNull(result.Item2);
Assert.Null(result.Item2);
}

[Theory, FreeOrganizationUpgradeCustomize]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
๏ปฟusing AspNetCoreRateLimit;
using Bit.Core.Auth.Services;
using Bit.Core.Billing.Services;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Tools.Services;
Expand Down Expand Up @@ -245,6 +246,11 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
var stripePaymentService = services.First(sd => sd.ServiceType == typeof(IPaymentService));
services.Remove(stripePaymentService);
services.AddSingleton(Substitute.For<IPaymentService>());

var organizationBillingService =
services.First(sd => sd.ServiceType == typeof(IOrganizationBillingService));
services.Remove(organizationBillingService);
services.AddSingleton(Substitute.For<IOrganizationBillingService>());
});

foreach (var configureTestService in _configureTestServices)
Expand Down
Loading