mirror of
https://github.com/bitwarden/server
synced 2026-01-10 12:33:49 +00:00
[PM-24964] Stripe-hosted bank account verification (#6263)
* Implement bank account hosted URL verification with webhook handling notification * Fix tests * Run dotnet format * Remove unused VerifyBankAccount operation * Stephon's feedback * Removing unused test * TEMP: Add logging for deployment check * Run dotnet format * fix test * Revert "fix test" This reverts commitb8743ab3b5. * Revert "Run dotnet format" This reverts commit5c861b0b72. * Revert "TEMP: Add logging for deployment check" This reverts commit0a88acd6a1. * Resolve GetPaymentMethodQuery order of operations
This commit is contained in:
@@ -71,7 +71,7 @@ public class GetOrganizationWarningsQueryTests
|
||||
});
|
||||
|
||||
sutProvider.GetDependency<ICurrentContext>().EditSubscription(organization.Id).Returns(true);
|
||||
sutProvider.GetDependency<ISetupIntentCache>().Get(organization.Id).Returns((string?)null);
|
||||
sutProvider.GetDependency<ISetupIntentCache>().GetSetupIntentIdForSubscriber(organization.Id).Returns((string?)null);
|
||||
|
||||
var response = await sutProvider.Sut.Run(organization);
|
||||
|
||||
@@ -109,7 +109,7 @@ public class GetOrganizationWarningsQueryTests
|
||||
});
|
||||
|
||||
sutProvider.GetDependency<ICurrentContext>().EditSubscription(organization.Id).Returns(true);
|
||||
sutProvider.GetDependency<ISetupIntentCache>().Get(organization.Id).Returns(setupIntentId);
|
||||
sutProvider.GetDependency<ISetupIntentCache>().GetSetupIntentIdForSubscriber(organization.Id).Returns(setupIntentId);
|
||||
sutProvider.GetDependency<IStripeAdapter>().SetupIntentGet(setupIntentId, Arg.Is<SetupIntentGetOptions>(
|
||||
options => options.Expand.Contains("payment_method"))).Returns(new SetupIntent
|
||||
{
|
||||
|
||||
@@ -74,7 +74,10 @@ public class UpdatePaymentMethodCommandTests
|
||||
},
|
||||
NextAction = new SetupIntentNextAction
|
||||
{
|
||||
VerifyWithMicrodeposits = new SetupIntentNextActionVerifyWithMicrodeposits()
|
||||
VerifyWithMicrodeposits = new SetupIntentNextActionVerifyWithMicrodeposits
|
||||
{
|
||||
HostedVerificationUrl = "https://example.com"
|
||||
}
|
||||
},
|
||||
Status = "requires_action"
|
||||
};
|
||||
@@ -95,7 +98,7 @@ public class UpdatePaymentMethodCommandTests
|
||||
var maskedBankAccount = maskedPaymentMethod.AsT0;
|
||||
Assert.Equal("Chase", maskedBankAccount.BankName);
|
||||
Assert.Equal("9999", maskedBankAccount.Last4);
|
||||
Assert.False(maskedBankAccount.Verified);
|
||||
Assert.Equal("https://example.com", maskedBankAccount.HostedVerificationUrl);
|
||||
|
||||
await _setupIntentCache.Received(1).Set(organization.Id, setupIntent.Id);
|
||||
}
|
||||
@@ -133,7 +136,10 @@ public class UpdatePaymentMethodCommandTests
|
||||
},
|
||||
NextAction = new SetupIntentNextAction
|
||||
{
|
||||
VerifyWithMicrodeposits = new SetupIntentNextActionVerifyWithMicrodeposits()
|
||||
VerifyWithMicrodeposits = new SetupIntentNextActionVerifyWithMicrodeposits
|
||||
{
|
||||
HostedVerificationUrl = "https://example.com"
|
||||
}
|
||||
},
|
||||
Status = "requires_action"
|
||||
};
|
||||
@@ -154,7 +160,7 @@ public class UpdatePaymentMethodCommandTests
|
||||
var maskedBankAccount = maskedPaymentMethod.AsT0;
|
||||
Assert.Equal("Chase", maskedBankAccount.BankName);
|
||||
Assert.Equal("9999", maskedBankAccount.Last4);
|
||||
Assert.False(maskedBankAccount.Verified);
|
||||
Assert.Equal("https://example.com", maskedBankAccount.HostedVerificationUrl);
|
||||
|
||||
await _subscriberService.Received(1).CreateStripeCustomer(organization);
|
||||
|
||||
@@ -199,7 +205,10 @@ public class UpdatePaymentMethodCommandTests
|
||||
},
|
||||
NextAction = new SetupIntentNextAction
|
||||
{
|
||||
VerifyWithMicrodeposits = new SetupIntentNextActionVerifyWithMicrodeposits()
|
||||
VerifyWithMicrodeposits = new SetupIntentNextActionVerifyWithMicrodeposits
|
||||
{
|
||||
HostedVerificationUrl = "https://example.com"
|
||||
}
|
||||
},
|
||||
Status = "requires_action"
|
||||
};
|
||||
@@ -220,7 +229,7 @@ public class UpdatePaymentMethodCommandTests
|
||||
var maskedBankAccount = maskedPaymentMethod.AsT0;
|
||||
Assert.Equal("Chase", maskedBankAccount.BankName);
|
||||
Assert.Equal("9999", maskedBankAccount.Last4);
|
||||
Assert.False(maskedBankAccount.Verified);
|
||||
Assert.Equal("https://example.com", maskedBankAccount.HostedVerificationUrl);
|
||||
|
||||
await _setupIntentCache.Received(1).Set(organization.Id, setupIntent.Id);
|
||||
await _stripeAdapter.Received(1).CustomerUpdateAsync(customer.Id, Arg.Is<CustomerUpdateOptions>(options =>
|
||||
|
||||
@@ -1,81 +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.Get(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()
|
||||
},
|
||||
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.True(maskedBankAccount.Verified);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public class MaskedPaymentMethodTests
|
||||
{
|
||||
BankName = "Chase",
|
||||
Last4 = "9999",
|
||||
Verified = true
|
||||
HostedVerificationUrl = "https://example.com"
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(input);
|
||||
@@ -32,7 +32,7 @@ public class MaskedPaymentMethodTests
|
||||
{
|
||||
BankName = "Chase",
|
||||
Last4 = "9999",
|
||||
Verified = true
|
||||
HostedVerificationUrl = "https://example.com"
|
||||
};
|
||||
|
||||
var jsonSerializerOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
|
||||
|
||||
@@ -108,7 +108,7 @@ public class GetPaymentMethodQueryTests
|
||||
var maskedBankAccount = maskedPaymentMethod.AsT0;
|
||||
Assert.Equal("Chase", maskedBankAccount.BankName);
|
||||
Assert.Equal("9999", maskedBankAccount.Last4);
|
||||
Assert.True(maskedBankAccount.Verified);
|
||||
Assert.Null(maskedBankAccount.HostedVerificationUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -142,7 +142,7 @@ public class GetPaymentMethodQueryTests
|
||||
var maskedBankAccount = maskedPaymentMethod.AsT0;
|
||||
Assert.Equal("Chase", maskedBankAccount.BankName);
|
||||
Assert.Equal("9999", maskedBankAccount.Last4);
|
||||
Assert.True(maskedBankAccount.Verified);
|
||||
Assert.Null(maskedBankAccount.HostedVerificationUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -163,7 +163,7 @@ public class GetPaymentMethodQueryTests
|
||||
Arg.Is<CustomerGetOptions>(options =>
|
||||
options.HasExpansions("default_source", "invoice_settings.default_payment_method"))).Returns(customer);
|
||||
|
||||
_setupIntentCache.Get(organization.Id).Returns("seti_123");
|
||||
_setupIntentCache.GetSetupIntentIdForSubscriber(organization.Id).Returns("seti_123");
|
||||
|
||||
_stripeAdapter
|
||||
.SetupIntentGet("seti_123",
|
||||
@@ -177,7 +177,10 @@ public class GetPaymentMethodQueryTests
|
||||
},
|
||||
NextAction = new SetupIntentNextAction
|
||||
{
|
||||
VerifyWithMicrodeposits = new SetupIntentNextActionVerifyWithMicrodeposits()
|
||||
VerifyWithMicrodeposits = new SetupIntentNextActionVerifyWithMicrodeposits
|
||||
{
|
||||
HostedVerificationUrl = "https://example.com"
|
||||
}
|
||||
},
|
||||
Status = "requires_action"
|
||||
});
|
||||
@@ -189,7 +192,7 @@ public class GetPaymentMethodQueryTests
|
||||
var maskedBankAccount = maskedPaymentMethod.AsT0;
|
||||
Assert.Equal("Chase", maskedBankAccount.BankName);
|
||||
Assert.Equal("9999", maskedBankAccount.Last4);
|
||||
Assert.False(maskedBankAccount.Verified);
|
||||
Assert.Equal("https://example.com", maskedBankAccount.HostedVerificationUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -670,7 +670,7 @@ public class SubscriberServiceTests
|
||||
}
|
||||
};
|
||||
|
||||
sutProvider.GetDependency<ISetupIntentCache>().Get(provider.Id).Returns(setupIntent.Id);
|
||||
sutProvider.GetDependency<ISetupIntentCache>().GetSetupIntentIdForSubscriber(provider.Id).Returns(setupIntent.Id);
|
||||
|
||||
sutProvider.GetDependency<IStripeAdapter>().SetupIntentGet(setupIntent.Id,
|
||||
Arg.Is<SetupIntentGetOptions>(options => options.Expand.Contains("payment_method"))).Returns(setupIntent);
|
||||
@@ -1876,7 +1876,7 @@ public class SubscriberServiceTests
|
||||
PaymentMethodId = "payment_method_id"
|
||||
};
|
||||
|
||||
sutProvider.GetDependency<ISetupIntentCache>().Get(provider.Id).Returns(setupIntent.Id);
|
||||
sutProvider.GetDependency<ISetupIntentCache>().GetSetupIntentIdForSubscriber(provider.Id).Returns(setupIntent.Id);
|
||||
|
||||
var stripeAdapter = sutProvider.GetDependency<IStripeAdapter>();
|
||||
|
||||
|
||||
@@ -651,31 +651,6 @@ public class AzureQueuePushEngineTests
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PushSyncOrganizationStatusAsync_SendsExpectedResponse()
|
||||
{
|
||||
var organization = new Organization
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Enabled = true,
|
||||
};
|
||||
|
||||
var expectedPayload = new JsonObject
|
||||
{
|
||||
["Type"] = 18,
|
||||
["Payload"] = new JsonObject
|
||||
{
|
||||
["OrganizationId"] = organization.Id,
|
||||
["Enabled"] = organization.Enabled,
|
||||
},
|
||||
};
|
||||
|
||||
await VerifyNotificationAsync(
|
||||
async sut => await sut.PushSyncOrganizationStatusAsync(organization),
|
||||
expectedPayload
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PushSyncOrganizationCollectionManagementSettingsAsync_SendsExpectedResponse()
|
||||
{
|
||||
|
||||
@@ -413,21 +413,6 @@ public abstract class PushTestBase
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PushSyncOrganizationStatusAsync_SendsExpectedResponse()
|
||||
{
|
||||
var organization = new Organization
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Enabled = true,
|
||||
};
|
||||
|
||||
await VerifyNotificationAsync(
|
||||
async sut => await sut.PushSyncOrganizationStatusAsync(organization),
|
||||
GetPushSyncOrganizationStatusResponsePayload(organization)
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PushSyncOrganizationCollectionManagementSettingsAsync_SendsExpectedResponse()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user