1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-24 12:35:25 +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,6 +1374,8 @@ namespace Bit.Core.Services
}
}
if (customer.Sources != null)
{
foreach (var source in customer.Sources.Where(s => s.Id != defaultSourceId))
{
if (source is Stripe.BankAccount)
@ -1383,6 +1387,7 @@ namespace Bit.Core.Services
await _stripeAdapter.CardDeleteAsync(customer.Id, source.Id);
}
}
}
var cardPaymentMethods = _stripeAdapter.PaymentMethodListAutoPaging(new Stripe.PaymentMethodListOptions
{