From 1c5567225c8d218b425f7c048d2c9e652c7fa3f1 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Fri, 28 Aug 2020 16:20:59 +0200 Subject: [PATCH 1/3] Don't send mail for expired invoices --- BTCPayServer/HostedServices/InvoiceNotificationManager.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BTCPayServer/HostedServices/InvoiceNotificationManager.cs b/BTCPayServer/HostedServices/InvoiceNotificationManager.cs index 29b7f5080..4e5236771 100644 --- a/BTCPayServer/HostedServices/InvoiceNotificationManager.cs +++ b/BTCPayServer/HostedServices/InvoiceNotificationManager.cs @@ -118,7 +118,7 @@ namespace BTCPayServer.HostedServices #pragma warning restore CS0618 } - if (!String.IsNullOrEmpty(invoice.NotificationEmail)) + if (invoiceEvent.Name != InvoiceEvent.Expired && !String.IsNullOrEmpty(invoice.NotificationEmail)) { var emailBody = NBitcoin.JsonConverters.Serializer.ToString(notification); @@ -126,7 +126,6 @@ namespace BTCPayServer.HostedServices invoice.NotificationEmail, $"BtcPayServer Invoice Notification - ${invoice.StoreId}", emailBody); - } if (invoice.NotificationURL != null) From 79c685c99b8c94547639b912c0e3b3aec5937781 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Fri, 28 Aug 2020 18:23:46 +0200 Subject: [PATCH 2/3] Invoice notification email improvements --- .../InvoiceNotificationManager.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/BTCPayServer/HostedServices/InvoiceNotificationManager.cs b/BTCPayServer/HostedServices/InvoiceNotificationManager.cs index 4e5236771..9547cfb91 100644 --- a/BTCPayServer/HostedServices/InvoiceNotificationManager.cs +++ b/BTCPayServer/HostedServices/InvoiceNotificationManager.cs @@ -13,6 +13,7 @@ using BTCPayServer.Payments; using BTCPayServer.Services; using BTCPayServer.Services.Invoices; using BTCPayServer.Services.Mails; +using BTCPayServer.Services.Stores; using Microsoft.Extensions.Hosting; using NBitpayClient; using NBXplorer; @@ -42,13 +43,14 @@ namespace BTCPayServer.HostedServices readonly EventAggregator _EventAggregator; readonly InvoiceRepository _InvoiceRepository; private readonly EmailSenderFactory _EmailSenderFactory; + private readonly StoreRepository _StoreRepository; public InvoiceNotificationManager( IHttpClientFactory httpClientFactory, IBackgroundJobClient jobClient, EventAggregator eventAggregator, InvoiceRepository invoiceRepository, - BTCPayNetworkProvider networkProvider, + StoreRepository storeRepository, EmailSenderFactory emailSenderFactory) { _Client = httpClientFactory.CreateClient(); @@ -56,9 +58,10 @@ namespace BTCPayServer.HostedServices _EventAggregator = eventAggregator; _InvoiceRepository = invoiceRepository; _EmailSenderFactory = emailSenderFactory; + _StoreRepository = storeRepository; } - void Notify(InvoiceEntity invoice, InvoiceEvent invoiceEvent, bool extendedNotification) + async void Notify(InvoiceEntity invoice, InvoiceEvent invoiceEvent, bool extendedNotification) { var dto = invoice.EntityToDTO(); var notification = new InvoicePaymentNotificationEventWrapper() @@ -120,11 +123,18 @@ namespace BTCPayServer.HostedServices if (invoiceEvent.Name != InvoiceEvent.Expired && !String.IsNullOrEmpty(invoice.NotificationEmail)) { - var emailBody = NBitcoin.JsonConverters.Serializer.ToString(notification); + var json = NBitcoin.JsonConverters.Serializer.ToString(notification); + var store = await _StoreRepository.FindStore(invoice.StoreId); + var storeName = store.StoreName ?? "BTCPay Server"; + var emailBody = $"Store: {storeName}
" + + $"Invoice ID: {notification.Data.Id}
" + + $"Status: {notification.Data.Status}
" + + $"Amount: {notification.Data.Price} {notification.Data.Currency}
" + + $"
Details
{json}
"; _EmailSenderFactory.GetEmailSender(invoice.StoreId).SendEmail( invoice.NotificationEmail, - $"BtcPayServer Invoice Notification - ${invoice.StoreId}", + $"{storeName} Invoice Notification - ${invoice.StoreId}", emailBody); } From 45ba4675fc5e2321c2126c048a1ba3ef2b3d4be2 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Fri, 11 Sep 2020 16:43:49 +0200 Subject: [PATCH 3/3] Fix async void usage https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md#async-void --- BTCPayServer/HostedServices/InvoiceNotificationManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BTCPayServer/HostedServices/InvoiceNotificationManager.cs b/BTCPayServer/HostedServices/InvoiceNotificationManager.cs index 9547cfb91..37d3048c1 100644 --- a/BTCPayServer/HostedServices/InvoiceNotificationManager.cs +++ b/BTCPayServer/HostedServices/InvoiceNotificationManager.cs @@ -61,7 +61,7 @@ namespace BTCPayServer.HostedServices _StoreRepository = storeRepository; } - async void Notify(InvoiceEntity invoice, InvoiceEvent invoiceEvent, bool extendedNotification) + async Task Notify(InvoiceEntity invoice, InvoiceEvent invoiceEvent, bool extendedNotification) { var dto = invoice.EntityToDTO(); var notification = new InvoicePaymentNotificationEventWrapper()