mirror of
https://github.com/bitwarden/server
synced 2025-12-10 13:23:27 +00:00
[PM-24552] - Remove code for pm-19956-require-provider-payment-method-during-setup (#6196)
* [PM-24552] - remove code for feature flag * pr gate: removing unused and redundant usings/qualifiers
This commit is contained in:
@@ -120,10 +120,7 @@ public class ProviderService : IProviderService
|
|||||||
throw new BadRequestException("Both address and postal code are required to set up your provider.");
|
throw new BadRequestException("Both address and postal code are required to set up your provider.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var requireProviderPaymentMethodDuringSetup =
|
if (tokenizedPaymentSource is not
|
||||||
_featureService.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup);
|
|
||||||
|
|
||||||
if (requireProviderPaymentMethodDuringSetup && tokenizedPaymentSource is not
|
|
||||||
{
|
{
|
||||||
Type: PaymentMethodType.BankAccount or PaymentMethodType.Card or PaymentMethodType.PayPal,
|
Type: PaymentMethodType.BankAccount or PaymentMethodType.Card or PaymentMethodType.PayPal,
|
||||||
Token: not null and not ""
|
Token: not null and not ""
|
||||||
|
|||||||
@@ -483,8 +483,10 @@ public class ProviderBillingService(
|
|||||||
public async Task<Customer> SetupCustomer(
|
public async Task<Customer> SetupCustomer(
|
||||||
Provider provider,
|
Provider provider,
|
||||||
TaxInfo taxInfo,
|
TaxInfo taxInfo,
|
||||||
TokenizedPaymentSource tokenizedPaymentSource = null)
|
TokenizedPaymentSource tokenizedPaymentSource)
|
||||||
{
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(tokenizedPaymentSource);
|
||||||
|
|
||||||
if (taxInfo is not
|
if (taxInfo is not
|
||||||
{
|
{
|
||||||
BillingAddressCountry: not null and not "",
|
BillingAddressCountry: not null and not "",
|
||||||
@@ -569,56 +571,50 @@ public class ProviderBillingService(
|
|||||||
options.Coupon = provider.DiscountId;
|
options.Coupon = provider.DiscountId;
|
||||||
}
|
}
|
||||||
|
|
||||||
var requireProviderPaymentMethodDuringSetup =
|
|
||||||
featureService.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup);
|
|
||||||
|
|
||||||
var braintreeCustomerId = "";
|
var braintreeCustomerId = "";
|
||||||
|
|
||||||
if (requireProviderPaymentMethodDuringSetup)
|
if (tokenizedPaymentSource is not
|
||||||
|
{
|
||||||
|
Type: PaymentMethodType.BankAccount or PaymentMethodType.Card or PaymentMethodType.PayPal,
|
||||||
|
Token: not null and not ""
|
||||||
|
})
|
||||||
{
|
{
|
||||||
if (tokenizedPaymentSource is not
|
logger.LogError("Cannot create customer for provider ({ProviderID}) with invalid payment method", provider.Id);
|
||||||
|
throw new BillingException();
|
||||||
|
}
|
||||||
|
|
||||||
|
var (type, token) = tokenizedPaymentSource;
|
||||||
|
|
||||||
|
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case PaymentMethodType.BankAccount:
|
||||||
{
|
{
|
||||||
Type: PaymentMethodType.BankAccount or PaymentMethodType.Card or PaymentMethodType.PayPal,
|
var setupIntent =
|
||||||
Token: not null and not ""
|
(await stripeAdapter.SetupIntentList(new SetupIntentListOptions { PaymentMethod = token }))
|
||||||
})
|
.FirstOrDefault();
|
||||||
{
|
|
||||||
logger.LogError("Cannot create customer for provider ({ProviderID}) without a payment method", provider.Id);
|
|
||||||
throw new BillingException();
|
|
||||||
}
|
|
||||||
|
|
||||||
var (type, token) = tokenizedPaymentSource;
|
if (setupIntent == null)
|
||||||
|
|
||||||
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case PaymentMethodType.BankAccount:
|
|
||||||
{
|
{
|
||||||
var setupIntent =
|
logger.LogError("Cannot create customer for provider ({ProviderID}) without a setup intent for their bank account", provider.Id);
|
||||||
(await stripeAdapter.SetupIntentList(new SetupIntentListOptions { PaymentMethod = token }))
|
throw new BillingException();
|
||||||
.FirstOrDefault();
|
}
|
||||||
|
|
||||||
if (setupIntent == null)
|
await setupIntentCache.Set(provider.Id, setupIntent.Id);
|
||||||
{
|
break;
|
||||||
logger.LogError("Cannot create customer for provider ({ProviderID}) without a setup intent for their bank account", provider.Id);
|
}
|
||||||
throw new BillingException();
|
case PaymentMethodType.Card:
|
||||||
}
|
{
|
||||||
|
options.PaymentMethod = token;
|
||||||
await setupIntentCache.Set(provider.Id, setupIntent.Id);
|
options.InvoiceSettings.DefaultPaymentMethod = token;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PaymentMethodType.Card:
|
case PaymentMethodType.PayPal:
|
||||||
{
|
{
|
||||||
options.PaymentMethod = token;
|
braintreeCustomerId = await subscriberService.CreateBraintreeCustomer(provider, token);
|
||||||
options.InvoiceSettings.DefaultPaymentMethod = token;
|
options.Metadata[BraintreeCustomerIdKey] = braintreeCustomerId;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PaymentMethodType.PayPal:
|
|
||||||
{
|
|
||||||
braintreeCustomerId = await subscriberService.CreateBraintreeCustomer(provider, token);
|
|
||||||
options.Metadata[BraintreeCustomerIdKey] = braintreeCustomerId;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -640,25 +636,22 @@ public class ProviderBillingService(
|
|||||||
|
|
||||||
async Task Revert()
|
async Task Revert()
|
||||||
{
|
{
|
||||||
if (requireProviderPaymentMethodDuringSetup && tokenizedPaymentSource != null)
|
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
|
||||||
|
switch (tokenizedPaymentSource.Type)
|
||||||
{
|
{
|
||||||
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
|
case PaymentMethodType.BankAccount:
|
||||||
switch (tokenizedPaymentSource.Type)
|
{
|
||||||
{
|
var setupIntentId = await setupIntentCache.Get(provider.Id);
|
||||||
case PaymentMethodType.BankAccount:
|
await stripeAdapter.SetupIntentCancel(setupIntentId,
|
||||||
{
|
new SetupIntentCancelOptions { CancellationReason = "abandoned" });
|
||||||
var setupIntentId = await setupIntentCache.Get(provider.Id);
|
await setupIntentCache.Remove(provider.Id);
|
||||||
await stripeAdapter.SetupIntentCancel(setupIntentId,
|
break;
|
||||||
new SetupIntentCancelOptions { CancellationReason = "abandoned" });
|
}
|
||||||
await setupIntentCache.Remove(provider.Id);
|
case PaymentMethodType.PayPal when !string.IsNullOrEmpty(braintreeCustomerId):
|
||||||
break;
|
{
|
||||||
}
|
await braintreeGateway.Customer.DeleteAsync(braintreeCustomerId);
|
||||||
case PaymentMethodType.PayPal when !string.IsNullOrEmpty(braintreeCustomerId):
|
break;
|
||||||
{
|
}
|
||||||
await braintreeGateway.Customer.DeleteAsync(braintreeCustomerId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -701,9 +694,6 @@ public class ProviderBillingService(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var requireProviderPaymentMethodDuringSetup =
|
|
||||||
featureService.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup);
|
|
||||||
|
|
||||||
var setupIntentId = await setupIntentCache.Get(provider.Id);
|
var setupIntentId = await setupIntentCache.Get(provider.Id);
|
||||||
|
|
||||||
var setupIntent = !string.IsNullOrEmpty(setupIntentId)
|
var setupIntent = !string.IsNullOrEmpty(setupIntentId)
|
||||||
@@ -714,10 +704,9 @@ public class ProviderBillingService(
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
var usePaymentMethod =
|
var usePaymentMethod =
|
||||||
requireProviderPaymentMethodDuringSetup &&
|
!string.IsNullOrEmpty(customer.InvoiceSettings?.DefaultPaymentMethodId) ||
|
||||||
(!string.IsNullOrEmpty(customer.InvoiceSettings.DefaultPaymentMethodId) ||
|
(customer.Metadata?.ContainsKey(BraintreeCustomerIdKey) == true) ||
|
||||||
customer.Metadata.ContainsKey(BraintreeCustomerIdKey) ||
|
(setupIntent?.IsUnverifiedBankAccount() == true);
|
||||||
setupIntent.IsUnverifiedBankAccount());
|
|
||||||
|
|
||||||
int? trialPeriodDays = provider.Type switch
|
int? trialPeriodDays = provider.Type switch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using Bit.Commercial.Core.AdminConsole.Services;
|
using Bit.Commercial.Core.AdminConsole.Services;
|
||||||
using Bit.Commercial.Core.Test.AdminConsole.AutoFixture;
|
using Bit.Commercial.Core.Test.AdminConsole.AutoFixture;
|
||||||
using Bit.Core;
|
|
||||||
using Bit.Core.AdminConsole.Entities;
|
using Bit.Core.AdminConsole.Entities;
|
||||||
using Bit.Core.AdminConsole.Entities.Provider;
|
using Bit.Core.AdminConsole.Entities.Provider;
|
||||||
using Bit.Core.AdminConsole.Enums.Provider;
|
using Bit.Core.AdminConsole.Enums.Provider;
|
||||||
@@ -120,8 +119,6 @@ public class ProviderServiceTests
|
|||||||
|
|
||||||
var token = protector.Protect($"ProviderSetupInvite {provider.Id} {user.Email} {CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow)}");
|
var token = protector.Protect($"ProviderSetupInvite {provider.Id} {user.Email} {CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow)}");
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup).Returns(true);
|
|
||||||
|
|
||||||
tokenizedPaymentSource = tokenizedPaymentSource with { Type = PaymentMethodType.BitPay };
|
tokenizedPaymentSource = tokenizedPaymentSource with { Type = PaymentMethodType.BitPay };
|
||||||
|
|
||||||
@@ -1194,7 +1191,7 @@ public class ProviderServiceTests
|
|||||||
private static SubscriptionUpdateOptions SubscriptionUpdateRequest(string expectedPlanId, Subscription subscriptionItem) =>
|
private static SubscriptionUpdateOptions SubscriptionUpdateRequest(string expectedPlanId, Subscription subscriptionItem) =>
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
Items = new List<Stripe.SubscriptionItemOptions>
|
Items = new List<SubscriptionItemOptions>
|
||||||
{
|
{
|
||||||
new() { Id = subscriptionItem.Id, Price = expectedPlanId },
|
new() { Id = subscriptionItem.Id, Price = expectedPlanId },
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -901,11 +901,12 @@ public class ProviderBillingServiceTests
|
|||||||
public async Task SetupCustomer_MissingCountry_ContactSupport(
|
public async Task SetupCustomer_MissingCountry_ContactSupport(
|
||||||
SutProvider<ProviderBillingService> sutProvider,
|
SutProvider<ProviderBillingService> sutProvider,
|
||||||
Provider provider,
|
Provider provider,
|
||||||
TaxInfo taxInfo)
|
TaxInfo taxInfo,
|
||||||
|
TokenizedPaymentSource tokenizedPaymentSource)
|
||||||
{
|
{
|
||||||
taxInfo.BillingAddressCountry = null;
|
taxInfo.BillingAddressCountry = null;
|
||||||
|
|
||||||
await ThrowsBillingExceptionAsync(() => sutProvider.Sut.SetupCustomer(provider, taxInfo));
|
await ThrowsBillingExceptionAsync(() => sutProvider.Sut.SetupCustomer(provider, taxInfo, tokenizedPaymentSource));
|
||||||
|
|
||||||
await sutProvider.GetDependency<IStripeAdapter>()
|
await sutProvider.GetDependency<IStripeAdapter>()
|
||||||
.DidNotReceiveWithAnyArgs()
|
.DidNotReceiveWithAnyArgs()
|
||||||
@@ -916,60 +917,27 @@ public class ProviderBillingServiceTests
|
|||||||
public async Task SetupCustomer_MissingPostalCode_ContactSupport(
|
public async Task SetupCustomer_MissingPostalCode_ContactSupport(
|
||||||
SutProvider<ProviderBillingService> sutProvider,
|
SutProvider<ProviderBillingService> sutProvider,
|
||||||
Provider provider,
|
Provider provider,
|
||||||
TaxInfo taxInfo)
|
TaxInfo taxInfo,
|
||||||
|
TokenizedPaymentSource tokenizedPaymentSource)
|
||||||
{
|
{
|
||||||
taxInfo.BillingAddressCountry = null;
|
taxInfo.BillingAddressCountry = null;
|
||||||
|
|
||||||
await ThrowsBillingExceptionAsync(() => sutProvider.Sut.SetupCustomer(provider, taxInfo));
|
await ThrowsBillingExceptionAsync(() => sutProvider.Sut.SetupCustomer(provider, taxInfo, tokenizedPaymentSource));
|
||||||
|
|
||||||
await sutProvider.GetDependency<IStripeAdapter>()
|
await sutProvider.GetDependency<IStripeAdapter>()
|
||||||
.DidNotReceiveWithAnyArgs()
|
.DidNotReceiveWithAnyArgs()
|
||||||
.CustomerGetAsync(Arg.Any<string>(), Arg.Any<CustomerGetOptions>());
|
.CustomerGetAsync(Arg.Any<string>(), Arg.Any<CustomerGetOptions>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task SetupCustomer_NoPaymentMethod_Success(
|
public async Task SetupCustomer_NullPaymentSource_ThrowsArgumentNullException(
|
||||||
SutProvider<ProviderBillingService> sutProvider,
|
SutProvider<ProviderBillingService> sutProvider,
|
||||||
Provider provider,
|
Provider provider,
|
||||||
TaxInfo taxInfo)
|
TaxInfo taxInfo)
|
||||||
{
|
{
|
||||||
provider.Name = "MSP";
|
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||||
|
sutProvider.Sut.SetupCustomer(provider, taxInfo, null));
|
||||||
sutProvider.GetDependency<ITaxService>()
|
|
||||||
.GetStripeTaxCode(Arg.Is<string>(
|
|
||||||
p => p == taxInfo.BillingAddressCountry),
|
|
||||||
Arg.Is<string>(p => p == taxInfo.TaxIdNumber))
|
|
||||||
.Returns(taxInfo.TaxIdType);
|
|
||||||
|
|
||||||
taxInfo.BillingAddressCountry = "AD";
|
|
||||||
|
|
||||||
var stripeAdapter = sutProvider.GetDependency<IStripeAdapter>();
|
|
||||||
|
|
||||||
var expected = new Customer
|
|
||||||
{
|
|
||||||
Id = "customer_id",
|
|
||||||
Tax = new CustomerTax { AutomaticTax = StripeConstants.AutomaticTaxStatus.Supported }
|
|
||||||
};
|
|
||||||
|
|
||||||
stripeAdapter.CustomerCreateAsync(Arg.Is<CustomerCreateOptions>(o =>
|
|
||||||
o.Address.Country == taxInfo.BillingAddressCountry &&
|
|
||||||
o.Address.PostalCode == taxInfo.BillingAddressPostalCode &&
|
|
||||||
o.Address.Line1 == taxInfo.BillingAddressLine1 &&
|
|
||||||
o.Address.Line2 == taxInfo.BillingAddressLine2 &&
|
|
||||||
o.Address.City == taxInfo.BillingAddressCity &&
|
|
||||||
o.Address.State == taxInfo.BillingAddressState &&
|
|
||||||
o.Description == WebUtility.HtmlDecode(provider.BusinessName) &&
|
|
||||||
o.Email == provider.BillingEmail &&
|
|
||||||
o.InvoiceSettings.CustomFields.FirstOrDefault().Name == "Provider" &&
|
|
||||||
o.InvoiceSettings.CustomFields.FirstOrDefault().Value == "MSP" &&
|
|
||||||
o.Metadata["region"] == "" &&
|
|
||||||
o.TaxIdData.FirstOrDefault().Type == taxInfo.TaxIdType &&
|
|
||||||
o.TaxIdData.FirstOrDefault().Value == taxInfo.TaxIdNumber))
|
|
||||||
.Returns(expected);
|
|
||||||
|
|
||||||
var actual = await sutProvider.Sut.SetupCustomer(provider, taxInfo);
|
|
||||||
|
|
||||||
Assert.Equivalent(expected, actual);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
@@ -989,8 +957,6 @@ public class ProviderBillingServiceTests
|
|||||||
|
|
||||||
taxInfo.BillingAddressCountry = "AD";
|
taxInfo.BillingAddressCountry = "AD";
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup).Returns(true);
|
|
||||||
|
|
||||||
tokenizedPaymentSource = tokenizedPaymentSource with { Type = PaymentMethodType.BitPay };
|
tokenizedPaymentSource = tokenizedPaymentSource with { Type = PaymentMethodType.BitPay };
|
||||||
|
|
||||||
@@ -1018,8 +984,6 @@ public class ProviderBillingServiceTests
|
|||||||
|
|
||||||
var tokenizedPaymentSource = new TokenizedPaymentSource(PaymentMethodType.BankAccount, "token");
|
var tokenizedPaymentSource = new TokenizedPaymentSource(PaymentMethodType.BankAccount, "token");
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup).Returns(true);
|
|
||||||
|
|
||||||
stripeAdapter.SetupIntentList(Arg.Is<SetupIntentListOptions>(options =>
|
stripeAdapter.SetupIntentList(Arg.Is<SetupIntentListOptions>(options =>
|
||||||
options.PaymentMethod == tokenizedPaymentSource.Token)).Returns([
|
options.PaymentMethod == tokenizedPaymentSource.Token)).Returns([
|
||||||
@@ -1075,8 +1039,6 @@ public class ProviderBillingServiceTests
|
|||||||
|
|
||||||
var tokenizedPaymentSource = new TokenizedPaymentSource(PaymentMethodType.PayPal, "token");
|
var tokenizedPaymentSource = new TokenizedPaymentSource(PaymentMethodType.PayPal, "token");
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup).Returns(true);
|
|
||||||
|
|
||||||
sutProvider.GetDependency<ISubscriberService>().CreateBraintreeCustomer(provider, tokenizedPaymentSource.Token)
|
sutProvider.GetDependency<ISubscriberService>().CreateBraintreeCustomer(provider, tokenizedPaymentSource.Token)
|
||||||
.Returns("braintree_customer_id");
|
.Returns("braintree_customer_id");
|
||||||
@@ -1130,8 +1092,6 @@ public class ProviderBillingServiceTests
|
|||||||
|
|
||||||
var tokenizedPaymentSource = new TokenizedPaymentSource(PaymentMethodType.BankAccount, "token");
|
var tokenizedPaymentSource = new TokenizedPaymentSource(PaymentMethodType.BankAccount, "token");
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup).Returns(true);
|
|
||||||
|
|
||||||
stripeAdapter.SetupIntentList(Arg.Is<SetupIntentListOptions>(options =>
|
stripeAdapter.SetupIntentList(Arg.Is<SetupIntentListOptions>(options =>
|
||||||
options.PaymentMethod == tokenizedPaymentSource.Token)).Returns([
|
options.PaymentMethod == tokenizedPaymentSource.Token)).Returns([
|
||||||
@@ -1187,8 +1147,6 @@ public class ProviderBillingServiceTests
|
|||||||
|
|
||||||
var tokenizedPaymentSource = new TokenizedPaymentSource(PaymentMethodType.PayPal, "token");
|
var tokenizedPaymentSource = new TokenizedPaymentSource(PaymentMethodType.PayPal, "token");
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup).Returns(true);
|
|
||||||
|
|
||||||
sutProvider.GetDependency<ISubscriberService>().CreateBraintreeCustomer(provider, tokenizedPaymentSource.Token)
|
sutProvider.GetDependency<ISubscriberService>().CreateBraintreeCustomer(provider, tokenizedPaymentSource.Token)
|
||||||
.Returns("braintree_customer_id");
|
.Returns("braintree_customer_id");
|
||||||
@@ -1241,8 +1199,6 @@ public class ProviderBillingServiceTests
|
|||||||
|
|
||||||
var tokenizedPaymentSource = new TokenizedPaymentSource(PaymentMethodType.Card, "token");
|
var tokenizedPaymentSource = new TokenizedPaymentSource(PaymentMethodType.Card, "token");
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup).Returns(true);
|
|
||||||
|
|
||||||
stripeAdapter.CustomerCreateAsync(Arg.Is<CustomerCreateOptions>(o =>
|
stripeAdapter.CustomerCreateAsync(Arg.Is<CustomerCreateOptions>(o =>
|
||||||
o.Address.Country == taxInfo.BillingAddressCountry &&
|
o.Address.Country == taxInfo.BillingAddressCountry &&
|
||||||
@@ -1293,8 +1249,6 @@ public class ProviderBillingServiceTests
|
|||||||
|
|
||||||
var tokenizedPaymentSource = new TokenizedPaymentSource(PaymentMethodType.Card, "token");
|
var tokenizedPaymentSource = new TokenizedPaymentSource(PaymentMethodType.Card, "token");
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup).Returns(true);
|
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
sutProvider.GetDependency<IFeatureService>()
|
||||||
.IsEnabled(FeatureFlagKeys.PM21092_SetNonUSBusinessUseToReverseCharge).Returns(true);
|
.IsEnabled(FeatureFlagKeys.PM21092_SetNonUSBusinessUseToReverseCharge).Returns(true);
|
||||||
@@ -1327,7 +1281,8 @@ public class ProviderBillingServiceTests
|
|||||||
public async Task SetupCustomer_Throws_BadRequestException_WhenTaxIdIsInvalid(
|
public async Task SetupCustomer_Throws_BadRequestException_WhenTaxIdIsInvalid(
|
||||||
SutProvider<ProviderBillingService> sutProvider,
|
SutProvider<ProviderBillingService> sutProvider,
|
||||||
Provider provider,
|
Provider provider,
|
||||||
TaxInfo taxInfo)
|
TaxInfo taxInfo,
|
||||||
|
TokenizedPaymentSource tokenizedPaymentSource)
|
||||||
{
|
{
|
||||||
provider.Name = "MSP";
|
provider.Name = "MSP";
|
||||||
|
|
||||||
@@ -1340,7 +1295,7 @@ public class ProviderBillingServiceTests
|
|||||||
.Returns((string)null);
|
.Returns((string)null);
|
||||||
|
|
||||||
var actual = await Assert.ThrowsAsync<BadRequestException>(async () =>
|
var actual = await Assert.ThrowsAsync<BadRequestException>(async () =>
|
||||||
await sutProvider.Sut.SetupCustomer(provider, taxInfo));
|
await sutProvider.Sut.SetupCustomer(provider, taxInfo, tokenizedPaymentSource));
|
||||||
|
|
||||||
Assert.IsType<BadRequestException>(actual);
|
Assert.IsType<BadRequestException>(actual);
|
||||||
Assert.Equal("billingTaxIdTypeInferenceError", actual.Message);
|
Assert.Equal("billingTaxIdTypeInferenceError", actual.Message);
|
||||||
@@ -1616,8 +1571,6 @@ public class ProviderBillingServiceTests
|
|||||||
|
|
||||||
var expected = new Subscription { Id = "subscription_id", Status = StripeConstants.SubscriptionStatus.Active };
|
var expected = new Subscription { Id = "subscription_id", Status = StripeConstants.SubscriptionStatus.Active };
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup).Returns(true);
|
|
||||||
|
|
||||||
sutProvider.GetDependency<IStripeAdapter>().SubscriptionCreateAsync(Arg.Is<SubscriptionCreateOptions>(
|
sutProvider.GetDependency<IStripeAdapter>().SubscriptionCreateAsync(Arg.Is<SubscriptionCreateOptions>(
|
||||||
sub =>
|
sub =>
|
||||||
@@ -1694,8 +1647,6 @@ public class ProviderBillingServiceTests
|
|||||||
|
|
||||||
var expected = new Subscription { Id = "subscription_id", Status = StripeConstants.SubscriptionStatus.Active };
|
var expected = new Subscription { Id = "subscription_id", Status = StripeConstants.SubscriptionStatus.Active };
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup).Returns(true);
|
|
||||||
|
|
||||||
const string setupIntentId = "seti_123";
|
const string setupIntentId = "seti_123";
|
||||||
|
|
||||||
@@ -1797,8 +1748,6 @@ public class ProviderBillingServiceTests
|
|||||||
|
|
||||||
var expected = new Subscription { Id = "subscription_id", Status = StripeConstants.SubscriptionStatus.Active };
|
var expected = new Subscription { Id = "subscription_id", Status = StripeConstants.SubscriptionStatus.Active };
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup).Returns(true);
|
|
||||||
|
|
||||||
sutProvider.GetDependency<IStripeAdapter>().SubscriptionCreateAsync(Arg.Is<SubscriptionCreateOptions>(
|
sutProvider.GetDependency<IStripeAdapter>().SubscriptionCreateAsync(Arg.Is<SubscriptionCreateOptions>(
|
||||||
sub =>
|
sub =>
|
||||||
@@ -1877,8 +1826,6 @@ public class ProviderBillingServiceTests
|
|||||||
|
|
||||||
var expected = new Subscription { Id = "subscription_id", Status = StripeConstants.SubscriptionStatus.Active };
|
var expected = new Subscription { Id = "subscription_id", Status = StripeConstants.SubscriptionStatus.Active };
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.PM19956_RequireProviderPaymentMethodDuringSetup).Returns(true);
|
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
sutProvider.GetDependency<IFeatureService>()
|
||||||
.IsEnabled(FeatureFlagKeys.PM21092_SetNonUSBusinessUseToReverseCharge).Returns(true);
|
.IsEnabled(FeatureFlagKeys.PM21092_SetNonUSBusinessUseToReverseCharge).Returns(true);
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ using Bit.Core.AdminConsole.Enums.Provider;
|
|||||||
using Bit.Core.AdminConsole.Repositories;
|
using Bit.Core.AdminConsole.Repositories;
|
||||||
using Bit.Core.Billing.Constants;
|
using Bit.Core.Billing.Constants;
|
||||||
using Bit.Core.Billing.Enums;
|
using Bit.Core.Billing.Enums;
|
||||||
|
using Bit.Core.Billing.Models;
|
||||||
using Bit.Core.Billing.Providers.Entities;
|
using Bit.Core.Billing.Providers.Entities;
|
||||||
using Bit.Core.Billing.Providers.Migration.Models;
|
using Bit.Core.Billing.Providers.Migration.Models;
|
||||||
using Bit.Core.Billing.Providers.Models;
|
using Bit.Core.Billing.Providers.Models;
|
||||||
using Bit.Core.Billing.Providers.Repositories;
|
using Bit.Core.Billing.Providers.Repositories;
|
||||||
using Bit.Core.Billing.Providers.Services;
|
using Bit.Core.Billing.Providers.Services;
|
||||||
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@@ -253,7 +255,10 @@ public class ProviderMigrator(
|
|||||||
|
|
||||||
var taxInfo = await paymentService.GetTaxInfoAsync(sampleOrganization);
|
var taxInfo = await paymentService.GetTaxInfoAsync(sampleOrganization);
|
||||||
|
|
||||||
var customer = await providerBillingService.SetupCustomer(provider, taxInfo);
|
// Create dummy payment source for legacy migration - this migrator is deprecated and will be removed
|
||||||
|
var dummyPaymentSource = new TokenizedPaymentSource(PaymentMethodType.Card, "migration_dummy_token");
|
||||||
|
|
||||||
|
var customer = await providerBillingService.SetupCustomer(provider, taxInfo, dummyPaymentSource);
|
||||||
|
|
||||||
await stripeAdapter.CustomerUpdateAsync(customer.Id, new CustomerUpdateOptions
|
await stripeAdapter.CustomerUpdateAsync(customer.Id, new CustomerUpdateOptions
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public interface IProviderBillingService
|
|||||||
Task<Customer> SetupCustomer(
|
Task<Customer> SetupCustomer(
|
||||||
Provider provider,
|
Provider provider,
|
||||||
TaxInfo taxInfo,
|
TaxInfo taxInfo,
|
||||||
TokenizedPaymentSource tokenizedPaymentSource = null);
|
TokenizedPaymentSource tokenizedPaymentSource);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For use during the provider setup process, this method starts a Stripe <see cref="Stripe.Subscription"/> for the given <paramref name="provider"/>.
|
/// For use during the provider setup process, this method starts a Stripe <see cref="Stripe.Subscription"/> for the given <paramref name="provider"/>.
|
||||||
|
|||||||
@@ -153,7 +153,6 @@ public static class FeatureFlagKeys
|
|||||||
public const string PM12276Breadcrumbing = "pm-12276-breadcrumbing-for-business-features";
|
public const string PM12276Breadcrumbing = "pm-12276-breadcrumbing-for-business-features";
|
||||||
public const string PM19422_AllowAutomaticTaxUpdates = "pm-19422-allow-automatic-tax-updates";
|
public const string PM19422_AllowAutomaticTaxUpdates = "pm-19422-allow-automatic-tax-updates";
|
||||||
public const string PM199566_UpdateMSPToChargeAutomatically = "pm-199566-update-msp-to-charge-automatically";
|
public const string PM199566_UpdateMSPToChargeAutomatically = "pm-199566-update-msp-to-charge-automatically";
|
||||||
public const string PM19956_RequireProviderPaymentMethodDuringSetup = "pm-19956-require-provider-payment-method-during-setup";
|
|
||||||
public const string UseOrganizationWarningsService = "use-organization-warnings-service";
|
public const string UseOrganizationWarningsService = "use-organization-warnings-service";
|
||||||
public const string PM20322_AllowTrialLength0 = "pm-20322-allow-trial-length-0";
|
public const string PM20322_AllowTrialLength0 = "pm-20322-allow-trial-length-0";
|
||||||
public const string PM21092_SetNonUSBusinessUseToReverseCharge = "pm-21092-set-non-us-business-use-to-reverse-charge";
|
public const string PM21092_SetNonUSBusinessUseToReverseCharge = "pm-21092-set-non-us-business-use-to-reverse-charge";
|
||||||
|
|||||||
Reference in New Issue
Block a user