From 001bbf2f2b30359d3cd7a3cec486db26ae5b5524 Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Wed, 20 Jan 2021 12:40:45 -0500 Subject: [PATCH] null checked Stripe.Customer.Address for org seat and storage upgrades (#1099) --- .../Implementations/OrganizationService.cs | 30 +++++++++++-------- .../Implementations/StripePaymentService.cs | 30 +++++++++++-------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs index 23a4fad113..79537c284f 100644 --- a/src/Core/Services/Implementations/OrganizationService.cs +++ b/src/Core/Services/Implementations/OrganizationService.cs @@ -415,20 +415,24 @@ namespace Bit.Core.Services }; var customer = await new CustomerService().GetAsync(sub.CustomerId); - var taxRates = await _taxRateRepository.GetByLocationAsync( - new Bit.Core.Models.Table.TaxRate() - { - Country = customer.Address.Country, - PostalCode = customer.Address.PostalCode - } - ); - var taxRate = taxRates.FirstOrDefault(); - if (taxRate != null && !sub.DefaultTaxRates.Any(x => x.Equals(taxRate.Id))) + if (!string.IsNullOrWhiteSpace(customer?.Address?.Country) + && !string.IsNullOrWhiteSpace(customer?.Address?.PostalCode)) { - subUpdateOptions.DefaultTaxRates = new List(1) - { - taxRate.Id - }; + var taxRates = await _taxRateRepository.GetByLocationAsync( + new Bit.Core.Models.Table.TaxRate() + { + Country = customer.Address.Country, + PostalCode = customer.Address.PostalCode + } + ); + var taxRate = taxRates.FirstOrDefault(); + if (taxRate != null && !sub.DefaultTaxRates.Any(x => x.Equals(taxRate.Id))) + { + subUpdateOptions.DefaultTaxRates = new List(1) + { + taxRate.Id + }; + } } var subResponse = await subscriptionService.UpdateAsync(sub.Id, subUpdateOptions); diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index 4aaf150644..d435d74642 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -719,20 +719,24 @@ namespace Bit.Core.Services }; var customer = await new CustomerService().GetAsync(sub.CustomerId); - var taxRates = await _taxRateRepository.GetByLocationAsync( - new Bit.Core.Models.Table.TaxRate() - { - Country = customer.Address.Country, - PostalCode = customer.Address.PostalCode - } - ); - var taxRate = taxRates.FirstOrDefault(); - if (taxRate != null && !sub.DefaultTaxRates.Any(x => x.Equals(taxRate.Id))) + if (!string.IsNullOrWhiteSpace(customer?.Address?.Country) + && !string.IsNullOrWhiteSpace(customer?.Address?.PostalCode)) { - subUpdateOptions.DefaultTaxRates = new List(1) - { - taxRate.Id - }; + var taxRates = await _taxRateRepository.GetByLocationAsync( + new Bit.Core.Models.Table.TaxRate() + { + Country = customer.Address.Country, + PostalCode = customer.Address.PostalCode + } + ); + var taxRate = taxRates.FirstOrDefault(); + if (taxRate != null && !sub.DefaultTaxRates.Any(x => x.Equals(taxRate.Id))) + { + subUpdateOptions.DefaultTaxRates = new List(1) + { + taxRate.Id + }; + } } var subResponse = await subscriptionService.UpdateAsync(sub.Id, subUpdateOptions);