mirror of
https://github.com/bitwarden/server
synced 2025-12-26 13:13:24 +00:00
Remove unused VerifyBankAccount operation
This commit is contained in:
@@ -25,8 +25,7 @@ public class OrganizationBillingVNextController(
|
||||
IGetOrganizationWarningsQuery getOrganizationWarningsQuery,
|
||||
IGetPaymentMethodQuery getPaymentMethodQuery,
|
||||
IUpdateBillingAddressCommand updateBillingAddressCommand,
|
||||
IUpdatePaymentMethodCommand updatePaymentMethodCommand,
|
||||
IVerifyBankAccountCommand verifyBankAccountCommand) : BaseBillingController
|
||||
IUpdatePaymentMethodCommand updatePaymentMethodCommand) : BaseBillingController
|
||||
{
|
||||
[Authorize<ManageOrganizationBillingRequirement>]
|
||||
[HttpGet("address")]
|
||||
@@ -96,17 +95,6 @@ public class OrganizationBillingVNextController(
|
||||
return Handle(result);
|
||||
}
|
||||
|
||||
[Authorize<ManageOrganizationBillingRequirement>]
|
||||
[HttpPost("payment-method/verify-bank-account")]
|
||||
[InjectOrganization]
|
||||
public async Task<IResult> VerifyBankAccountAsync(
|
||||
[BindNever] Organization organization,
|
||||
[FromBody] VerifyBankAccountRequest request)
|
||||
{
|
||||
var result = await verifyBankAccountCommand.Run(organization, request.DescriptorCode);
|
||||
return Handle(result);
|
||||
}
|
||||
|
||||
[Authorize<MemberOrProviderRequirement>]
|
||||
[HttpGet("warnings")]
|
||||
[InjectOrganization]
|
||||
|
||||
@@ -23,8 +23,7 @@ public class ProviderBillingVNextController(
|
||||
IGetProviderWarningsQuery getProviderWarningsQuery,
|
||||
IProviderService providerService,
|
||||
IUpdateBillingAddressCommand updateBillingAddressCommand,
|
||||
IUpdatePaymentMethodCommand updatePaymentMethodCommand,
|
||||
IVerifyBankAccountCommand verifyBankAccountCommand) : BaseBillingController
|
||||
IUpdatePaymentMethodCommand updatePaymentMethodCommand) : BaseBillingController
|
||||
{
|
||||
[HttpGet("address")]
|
||||
[InjectProvider(ProviderUserType.ProviderAdmin)]
|
||||
@@ -97,16 +96,6 @@ public class ProviderBillingVNextController(
|
||||
return Handle(result);
|
||||
}
|
||||
|
||||
[HttpPost("payment-method/verify-bank-account")]
|
||||
[InjectProvider(ProviderUserType.ProviderAdmin)]
|
||||
public async Task<IResult> VerifyBankAccountAsync(
|
||||
[BindNever] Provider provider,
|
||||
[FromBody] VerifyBankAccountRequest request)
|
||||
{
|
||||
var result = await verifyBankAccountCommand.Run(provider, request.DescriptorCode);
|
||||
return Handle(result);
|
||||
}
|
||||
|
||||
[HttpGet("warnings")]
|
||||
[InjectProvider(ProviderUserType.ServiceUser)]
|
||||
public async Task<IResult> GetWarningsAsync(
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
using Bit.Core.Billing.Caches;
|
||||
using Bit.Core.Billing.Commands;
|
||||
using Bit.Core.Billing.Payment.Models;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Stripe;
|
||||
|
||||
namespace Bit.Core.Billing.Payment.Commands;
|
||||
|
||||
public interface IVerifyBankAccountCommand
|
||||
{
|
||||
Task<BillingCommandResult<MaskedPaymentMethod>> Run(
|
||||
ISubscriber subscriber,
|
||||
string descriptorCode);
|
||||
}
|
||||
|
||||
public class VerifyBankAccountCommand(
|
||||
ILogger<VerifyBankAccountCommand> logger,
|
||||
ISetupIntentCache setupIntentCache,
|
||||
IStripeAdapter stripeAdapter) : BaseBillingCommand<VerifyBankAccountCommand>(logger), IVerifyBankAccountCommand
|
||||
{
|
||||
private readonly ILogger<VerifyBankAccountCommand> _logger = logger;
|
||||
|
||||
protected override Conflict DefaultConflict
|
||||
=> new("We had a problem verifying your bank account. Please contact support for assistance.");
|
||||
|
||||
public Task<BillingCommandResult<MaskedPaymentMethod>> Run(
|
||||
ISubscriber subscriber,
|
||||
string descriptorCode) => HandleAsync<MaskedPaymentMethod>(async () =>
|
||||
{
|
||||
var setupIntentId = await setupIntentCache.GetSetupIntentIdForSubscriber(subscriber.Id);
|
||||
|
||||
if (string.IsNullOrEmpty(setupIntentId))
|
||||
{
|
||||
_logger.LogError(
|
||||
"{Command}: Could not find setup intent to verify subscriber's ({SubscriberID}) bank account",
|
||||
CommandName, subscriber.Id);
|
||||
return DefaultConflict;
|
||||
}
|
||||
|
||||
await stripeAdapter.SetupIntentVerifyMicroDeposit(setupIntentId,
|
||||
new SetupIntentVerifyMicrodepositsOptions { DescriptorCode = descriptorCode });
|
||||
|
||||
var setupIntent = await stripeAdapter.SetupIntentGet(setupIntentId,
|
||||
new SetupIntentGetOptions { Expand = ["payment_method"] });
|
||||
|
||||
var paymentMethod = await stripeAdapter.PaymentMethodAttachAsync(setupIntent.PaymentMethodId,
|
||||
new PaymentMethodAttachOptions { Customer = subscriber.GatewayCustomerId });
|
||||
|
||||
await stripeAdapter.CustomerUpdateAsync(subscriber.GatewayCustomerId,
|
||||
new CustomerUpdateOptions
|
||||
{
|
||||
InvoiceSettings = new CustomerInvoiceSettingsOptions
|
||||
{
|
||||
DefaultPaymentMethod = setupIntent.PaymentMethodId
|
||||
}
|
||||
});
|
||||
|
||||
return MaskedPaymentMethod.From(paymentMethod.UsBankAccount);
|
||||
});
|
||||
}
|
||||
@@ -14,7 +14,6 @@ public static class Registrations
|
||||
services.AddTransient<ICreateBitPayInvoiceForCreditCommand, CreateBitPayInvoiceForCreditCommand>();
|
||||
services.AddTransient<IUpdateBillingAddressCommand, UpdateBillingAddressCommand>();
|
||||
services.AddTransient<IUpdatePaymentMethodCommand, UpdatePaymentMethodCommand>();
|
||||
services.AddTransient<IVerifyBankAccountCommand, VerifyBankAccountCommand>();
|
||||
|
||||
// Queries
|
||||
services.AddTransient<IGetBillingAddressQuery, GetBillingAddressQuery>();
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.Billing.Caches;
|
||||
using Bit.Core.Billing.Payment.Commands;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Test.Billing.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using Stripe;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Billing.Payment.Commands;
|
||||
|
||||
public class VerifyBankAccountCommandTests
|
||||
{
|
||||
private readonly ISetupIntentCache _setupIntentCache = Substitute.For<ISetupIntentCache>();
|
||||
private readonly IStripeAdapter _stripeAdapter = Substitute.For<IStripeAdapter>();
|
||||
private readonly VerifyBankAccountCommand _command;
|
||||
|
||||
public VerifyBankAccountCommandTests()
|
||||
{
|
||||
_command = new VerifyBankAccountCommand(
|
||||
Substitute.For<ILogger<VerifyBankAccountCommand>>(),
|
||||
_setupIntentCache,
|
||||
_stripeAdapter);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Run_MakesCorrectInvocations_ReturnsMaskedBankAccount()
|
||||
{
|
||||
var organization = new Organization
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
GatewayCustomerId = "cus_123"
|
||||
};
|
||||
|
||||
const string setupIntentId = "seti_123";
|
||||
|
||||
_setupIntentCache.GetSetupIntentIdForSubscriber(organization.Id).Returns(setupIntentId);
|
||||
|
||||
var setupIntent = new SetupIntent
|
||||
{
|
||||
Id = setupIntentId,
|
||||
PaymentMethodId = "pm_123",
|
||||
PaymentMethod =
|
||||
new PaymentMethod
|
||||
{
|
||||
Id = "pm_123",
|
||||
Type = "us_bank_account",
|
||||
UsBankAccount = new PaymentMethodUsBankAccount { BankName = "Chase", Last4 = "9999" }
|
||||
},
|
||||
NextAction = new SetupIntentNextAction
|
||||
{
|
||||
VerifyWithMicrodeposits = new SetupIntentNextActionVerifyWithMicrodeposits
|
||||
{
|
||||
HostedVerificationUrl = "https://example.com"
|
||||
}
|
||||
},
|
||||
Status = "requires_action"
|
||||
};
|
||||
|
||||
_stripeAdapter.SetupIntentGet(setupIntentId,
|
||||
Arg.Is<SetupIntentGetOptions>(options => options.HasExpansions("payment_method"))).Returns(setupIntent);
|
||||
|
||||
_stripeAdapter.PaymentMethodAttachAsync(setupIntent.PaymentMethodId,
|
||||
Arg.Is<PaymentMethodAttachOptions>(options => options.Customer == organization.GatewayCustomerId))
|
||||
.Returns(setupIntent.PaymentMethod);
|
||||
|
||||
var result = await _command.Run(organization, "DESCRIPTOR_CODE");
|
||||
|
||||
Assert.True(result.IsT0);
|
||||
var maskedPaymentMethod = result.AsT0;
|
||||
Assert.True(maskedPaymentMethod.IsT0);
|
||||
var maskedBankAccount = maskedPaymentMethod.AsT0;
|
||||
Assert.Equal("Chase", maskedBankAccount.BankName);
|
||||
Assert.Equal("9999", maskedBankAccount.Last4);
|
||||
Assert.Equal("https://example.com", maskedBankAccount.HostedVerificationUrl);
|
||||
|
||||
await _stripeAdapter.Received(1).SetupIntentVerifyMicroDeposit(setupIntent.Id,
|
||||
Arg.Is<SetupIntentVerifyMicrodepositsOptions>(options => options.DescriptorCode == "DESCRIPTOR_CODE"));
|
||||
|
||||
await _stripeAdapter.Received(1).CustomerUpdateAsync(organization.GatewayCustomerId, Arg.Is<CustomerUpdateOptions>(
|
||||
options => options.InvoiceSettings.DefaultPaymentMethod == setupIntent.PaymentMethodId));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user