1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-21 12:05:42 +01:00

[SG 475] Fix error thrown when changing payment method (#2137)

* Add null check for sources

* Add expand to get customer sources
This commit is contained in:
Robyn MacCallum 2022-07-21 12:55:57 -04:00 committed by GitHub
parent f736008cb3
commit 378b54524f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1187,7 +1187,9 @@ namespace Bit.Core.Services
if (!string.IsNullOrWhiteSpace(subscriber.GatewayCustomerId))
{
customer = await _stripeAdapter.CustomerGetAsync(subscriber.GatewayCustomerId);
var options = new Stripe.CustomerGetOptions();
options.AddExpand("sources");
customer = await _stripeAdapter.CustomerGetAsync(subscriber.GatewayCustomerId, options);
if (customer.Metadata?.Any() ?? false)
{
stripeCustomerMetadata = customer.Metadata;
@ -1372,15 +1374,18 @@ namespace Bit.Core.Services
}
}
foreach (var source in customer.Sources.Where(s => s.Id != defaultSourceId))
if (customer.Sources != null)
{
if (source is Stripe.BankAccount)
foreach (var source in customer.Sources.Where(s => s.Id != defaultSourceId))
{
await _stripeAdapter.BankAccountDeleteAsync(customer.Id, source.Id);
}
else if (source is Stripe.Card)
{
await _stripeAdapter.CardDeleteAsync(customer.Id, source.Id);
if (source is Stripe.BankAccount)
{
await _stripeAdapter.BankAccountDeleteAsync(customer.Id, source.Id);
}
else if (source is Stripe.Card)
{
await _stripeAdapter.CardDeleteAsync(customer.Id, source.Id);
}
}
}