From 379480b6157869142601b7202c8fb1a79caa0d2b Mon Sep 17 00:00:00 2001 From: Alex Morask Date: Fri, 4 Oct 2024 12:04:32 -0400 Subject: [PATCH 1/3] Update InvoiceCreatedHandler to log exception messages --- .../Implementations/InvoiceCreatedHandler.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Billing/Services/Implementations/InvoiceCreatedHandler.cs b/src/Billing/Services/Implementations/InvoiceCreatedHandler.cs index 5bb098bec5f0..06d923221bc8 100644 --- a/src/Billing/Services/Implementations/InvoiceCreatedHandler.cs +++ b/src/Billing/Services/Implementations/InvoiceCreatedHandler.cs @@ -49,7 +49,11 @@ public async Task HandleAsync(Event parsedEvent) } catch (Exception exception) { - logger.LogError(exception, "Failed to attempt paying for invoice while handling 'invoice.created' event ({EventID})", parsedEvent.Id); + logger.LogError(exception, "Failed to attempt paying for invoice while handling 'invoice.created' event ({EventID}) | Message: {Message}", + parsedEvent.Id, + exception.Message); + + throw; } try @@ -58,7 +62,11 @@ public async Task HandleAsync(Event parsedEvent) } catch (Exception exception) { - logger.LogError(exception, "Failed to record provider invoice line items while handling 'invoice.created' event ({EventID})", parsedEvent.Id); + logger.LogError(exception, "Failed to record provider invoice line items while handling 'invoice.created' event ({EventID}) | Message: {Message}", + parsedEvent.Id, + exception.Message); + + throw; } } } From 1159a6bfc9a6f344b6684a03df997ebe45227514 Mon Sep 17 00:00:00 2001 From: Alex Morask Date: Wed, 9 Oct 2024 10:08:56 -0400 Subject: [PATCH 2/3] Add logging --- .../StripeEventUtilityService.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/Billing/Services/Implementations/StripeEventUtilityService.cs b/src/Billing/Services/Implementations/StripeEventUtilityService.cs index 520205e745bc..88c49dcfd3e3 100644 --- a/src/Billing/Services/Implementations/StripeEventUtilityService.cs +++ b/src/Billing/Services/Implementations/StripeEventUtilityService.cs @@ -8,6 +8,7 @@ using Braintree; using Stripe; using Customer = Stripe.Customer; +using Environment = Braintree.Environment; using Subscription = Stripe.Subscription; using Transaction = Bit.Core.Entities.Transaction; using TransactionType = Bit.Core.Enums.TransactionType; @@ -261,6 +262,8 @@ invoice is private async Task AttemptToPayInvoiceWithBraintreeAsync(Invoice invoice, Customer customer) { + LogBraintreeConfiguration(); + _logger.LogDebug("Attempting to pay invoice with Braintree"); if (!customer?.Metadata?.ContainsKey("btCustomerId") ?? true) { @@ -404,4 +407,48 @@ private async Task AttemptToPayInvoiceWithStripeAsync(Invoice invoice) throw; } } + + private void LogBraintreeConfiguration() + { + var environment = System.Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); + + if (environment != "QA") + { + _logger.LogInformation("Braintree: Not logging for {Environment}", environment); + return; + } + + var merchantId = _globalSettings.Braintree.MerchantId; + + if (string.IsNullOrEmpty(merchantId)) + { + _logger.LogWarning("Braintree Merchant ID: null or empty"); + } + else + { + _logger.LogInformation("Braintree Merchant ID: {MerchantId}", merchantId[..5]); + } + + var publicKey = _globalSettings.Braintree.PublicKey; + + if (string.IsNullOrEmpty(publicKey)) + { + _logger.LogWarning("Braintree Public Key: null or empty"); + } + else + { + _logger.LogInformation("Braintree Public Key: {PublicKey}", publicKey[..5]); + } + + var privateKey = _globalSettings.Braintree.PrivateKey; + + if (string.IsNullOrEmpty(privateKey)) + { + _logger.LogWarning("Braintree Private Key: null or empty"); + } + else + { + _logger.LogInformation("Braintree Private Key: {PrivateKey}", privateKey[..5]); + } + } } From c3f5c24bf4c1443a84b3cde35dbec4d9f48b02bd Mon Sep 17 00:00:00 2001 From: Alex Morask Date: Wed, 9 Oct 2024 10:16:10 -0400 Subject: [PATCH 3/3] Run dotnet format --- .../Services/Implementations/StripeEventUtilityService.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Billing/Services/Implementations/StripeEventUtilityService.cs b/src/Billing/Services/Implementations/StripeEventUtilityService.cs index 88c49dcfd3e3..74d7da7795af 100644 --- a/src/Billing/Services/Implementations/StripeEventUtilityService.cs +++ b/src/Billing/Services/Implementations/StripeEventUtilityService.cs @@ -8,7 +8,6 @@ using Braintree; using Stripe; using Customer = Stripe.Customer; -using Environment = Braintree.Environment; using Subscription = Stripe.Subscription; using Transaction = Bit.Core.Entities.Transaction; using TransactionType = Bit.Core.Enums.TransactionType;