From bd17067838dc33a8afed9de0961017f1b9a67aca Mon Sep 17 00:00:00 2001 From: Alex Morask Date: Fri, 5 Dec 2025 10:50:41 -0600 Subject: [PATCH] Claude feedback --- .../StripeEventUtilityService.cs | 22 +++++++++++++++---- .../Services/Implementations/StripeFacade.cs | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Billing/Services/Implementations/StripeEventUtilityService.cs b/src/Billing/Services/Implementations/StripeEventUtilityService.cs index 5dbdd7a0a0..0567c0dcd3 100644 --- a/src/Billing/Services/Implementations/StripeEventUtilityService.cs +++ b/src/Billing/Services/Implementations/StripeEventUtilityService.cs @@ -432,6 +432,14 @@ public class StripeEventUtilityService : IStripeEventUtilityService } } + /// + /// Retrieves the bank transfer type that funded a charge paid via customer balance. + /// + /// The charge to analyze. + /// + /// The bank transfer type (e.g., "us_bank_transfer", "eu_bank_transfer") if the charge was funded + /// by a bank transfer via customer balance, otherwise null. + /// private async Task GetFundingBankTransferTypeAsync(Charge charge) { if (charge is not @@ -447,7 +455,7 @@ public class StripeEventUtilityService : IStripeEventUtilityService var cashBalanceTransactions = _stripeFacade.GetCustomerCashBalanceTransactions(charge.CustomerId); string bankTransferType = null; - var fundedCharge = false; + var matchingPaymentIntentFound = false; await foreach (var cashBalanceTransaction in cashBalanceTransactions) { @@ -458,14 +466,20 @@ public class StripeEventUtilityService : IStripeEventUtilityService bankTransferType = cashBalanceTransaction.Funded.BankTransfer.Type; break; } - case { Type: "applied_to_payment", AppliedToPayment: not null }: + case { Type: "applied_to_payment", AppliedToPayment: not null } + when cashBalanceTransaction.AppliedToPayment.PaymentIntentId == charge.PaymentIntentId: { - fundedCharge = charge.PaymentIntentId == cashBalanceTransaction.AppliedToPayment.PaymentIntentId; + matchingPaymentIntentFound = true; break; } } + + if (matchingPaymentIntentFound && !string.IsNullOrEmpty(bankTransferType)) + { + return bankTransferType; + } } - return !fundedCharge ? null : bankTransferType; + return null; } } diff --git a/src/Billing/Services/Implementations/StripeFacade.cs b/src/Billing/Services/Implementations/StripeFacade.cs index eeb7b86233..49cde981cd 100644 --- a/src/Billing/Services/Implementations/StripeFacade.cs +++ b/src/Billing/Services/Implementations/StripeFacade.cs @@ -44,7 +44,7 @@ public class StripeFacade : IStripeFacade public IAsyncEnumerable GetCustomerCashBalanceTransactions( string customerId, - CustomerCashBalanceTransactionListOptions customerCashBalanceTransactionListOptions, + CustomerCashBalanceTransactionListOptions customerCashBalanceTransactionListOptions = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) => _customerCashBalanceTransactionService.ListAutoPagingAsync(customerId, customerCashBalanceTransactionListOptions, requestOptions, cancellationToken);