From a7c093a0eb07d3bca7b45914953d0fd301d7d1b2 Mon Sep 17 00:00:00 2001 From: Aaron Clauson Date: Sun, 10 Oct 2021 07:54:25 +0100 Subject: [PATCH] Allow email notifications when creating invoices from Web UI (#2959) Currently invoice email notifications are only sent when the invoice is created via the API. This commit adds an option to set an email address for notifications when an invoice is created from the Web UI. --- BTCPayServer/Controllers/InvoiceController.UI.cs | 2 ++ BTCPayServer/HostedServices/InvoiceNotificationManager.cs | 2 +- BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs | 7 +++++++ BTCPayServer/Views/Invoice/CreateInvoice.cshtml | 5 +++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 7fa628956..7b4943f49 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -868,6 +868,8 @@ namespace BTCPayServer.Controllers Enabled = true }), DefaultPaymentMethod = model.DefaultPaymentMethod, + NotificationEmail = model.NotificationEmail, + ExtendedNotifications = model.NotificationEmail != null }, store, HttpContext.Request.GetAbsoluteRoot(), cancellationToken: cancellationToken); TempData[WellKnownTempData.SuccessMessage] = $"Invoice {result.Data.Id} just created!"; diff --git a/BTCPayServer/HostedServices/InvoiceNotificationManager.cs b/BTCPayServer/HostedServices/InvoiceNotificationManager.cs index d8390a1c8..ca1e2ba08 100644 --- a/BTCPayServer/HostedServices/InvoiceNotificationManager.cs +++ b/BTCPayServer/HostedServices/InvoiceNotificationManager.cs @@ -121,7 +121,7 @@ namespace BTCPayServer.HostedServices #pragma warning restore CS0618 } - if (invoiceEvent.Name != InvoiceEvent.Expired && !String.IsNullOrEmpty(invoice.NotificationEmail)) + if ((invoice.ExtendedNotifications || invoiceEvent.Name != InvoiceEvent.Expired) && !String.IsNullOrEmpty(invoice.NotificationEmail)) { var json = NBitcoin.JsonConverters.Serializer.ToString(notification); var store = await _StoreRepository.FindStore(invoice.StoreId); diff --git a/BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs b/BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs index 187c85c91..b5b754964 100644 --- a/BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs +++ b/BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs @@ -86,5 +86,12 @@ namespace BTCPayServer.Models.InvoicingModels { get; set; } + + [EmailAddress] + [DisplayName("Notification Email")] + public string NotificationEmail + { + get; set; + } } } diff --git a/BTCPayServer/Views/Invoice/CreateInvoice.cshtml b/BTCPayServer/Views/Invoice/CreateInvoice.cshtml index 88f3b787d..7a8b61049 100644 --- a/BTCPayServer/Views/Invoice/CreateInvoice.cshtml +++ b/BTCPayServer/Views/Invoice/CreateInvoice.cshtml @@ -84,6 +84,11 @@ +
+ + + +
Back to list