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:
parent
f736008cb3
commit
378b54524f
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user