From 97795de19e925c7b81cc7877e5614756a6069771 Mon Sep 17 00:00:00 2001 From: Alex Morask <144709477+amorask-bitwarden@users.noreply.github.com> Date: Thu, 12 Sep 2024 08:47:34 -0400 Subject: [PATCH] [PM-11993] Fix free organization bug in SubscriberService.GetPaymentMethod (#4766) * Handle free organization in SubscriberService.GetPaymentMethod * Run dotnet format --- src/Core/Billing/Models/PaymentMethod.cs | 5 ++++- .../Billing/Services/Implementations/SubscriberService.cs | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Core/Billing/Models/PaymentMethod.cs b/src/Core/Billing/Models/PaymentMethod.cs index eed338d96..b07fe82e4 100644 --- a/src/Core/Billing/Models/PaymentMethod.cs +++ b/src/Core/Billing/Models/PaymentMethod.cs @@ -4,4 +4,7 @@ public record PaymentMethod( long AccountCredit, PaymentSource PaymentSource, string SubscriptionStatus, - TaxInformation TaxInformation); + TaxInformation TaxInformation) +{ + public static PaymentMethod Empty => new(0, null, null, null); +} diff --git a/src/Core/Billing/Services/Implementations/SubscriberService.cs b/src/Core/Billing/Services/Implementations/SubscriberService.cs index 33eb8e7e8..9daf95622 100644 --- a/src/Core/Billing/Services/Implementations/SubscriberService.cs +++ b/src/Core/Billing/Services/Implementations/SubscriberService.cs @@ -213,11 +213,16 @@ public class SubscriberService( { ArgumentNullException.ThrowIfNull(subscriber); - var customer = await GetCustomerOrThrow(subscriber, new CustomerGetOptions + var customer = await GetCustomer(subscriber, new CustomerGetOptions { Expand = ["default_source", "invoice_settings.default_payment_method", "subscriptions", "tax_ids"] }); + if (customer == null) + { + return PaymentMethod.Empty; + } + var accountCredit = customer.Balance * -1 / 100; var paymentMethod = await GetPaymentSourceAsync(subscriber.Id, customer);