Display send email checkbox #6653 (#6815)

This commit is contained in:
AdamWroblewski
2025-07-02 02:55:40 +02:00
committed by GitHub
parent 9b64e90394
commit 756f48213d
8 changed files with 43 additions and 7 deletions

View File

@@ -6,6 +6,8 @@ namespace BTCPayServer.HostedServices.Webhooks;
public interface IWebhookProvider
{
public bool SupportsCustomerEmail { get; }
public Dictionary<string, string> GetSupportedWebhookTypes();
public WebhookEvent CreateTestEvent(string type, params object[] args);

View File

@@ -14,6 +14,8 @@ public class InvoiceWebhookProvider(
ILogger<InvoiceWebhookProvider> logger)
: WebhookProvider<InvoiceEvent>(eventAggregator, logger, webhookSender)
{
public override bool SupportsCustomerEmail { get; } = true;
public override Dictionary<string, string> GetSupportedWebhookTypes()
{
return new Dictionary<string, string>

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using BTCPayServer.Client.Models;
using BTCPayServer.Data;
@@ -10,6 +10,8 @@ namespace BTCPayServer.HostedServices.Webhooks;
public class PaymentRequestWebhookProvider(EventAggregator eventAggregator, ILogger<PaymentRequestWebhookProvider> logger, WebhookSender webhookSender)
: WebhookProvider<PaymentRequestEvent>(eventAggregator, logger, webhookSender)
{
public override bool SupportsCustomerEmail { get; } = true;
public override Dictionary<string, string> GetSupportedWebhookTypes()
{
return new Dictionary<string, string>

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using BTCPayServer.Client.Models;
using BTCPayServer.Data;
@@ -36,6 +36,8 @@ public class PayoutWebhookProvider(
return new PayoutWebhookDeliveryRequest(payoutEvent, webhook?.Id, webhookEvent, delivery, webhookBlob, btcPayNetworkJsonSerializerSettings);
}
public override bool SupportsCustomerEmail { get; } = false;
public override Dictionary<string, string> GetSupportedWebhookTypes()
{
return new Dictionary<string, string>

View File

@@ -18,6 +18,8 @@ public class PendingTransactionWebhookProvider(
public const string PendingTransactionBroadcast = nameof(PendingTransactionBroadcast);
public const string PendingTransactionCancelled = nameof(PendingTransactionCancelled);
public override bool SupportsCustomerEmail { get; } = false;
public override Dictionary<string, string> GetSupportedWebhookTypes()
{
return new Dictionary<string, string>

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Client.Models;
@@ -10,6 +10,8 @@ namespace BTCPayServer.HostedServices.Webhooks;
public abstract class WebhookProvider<T>(EventAggregator eventAggregator, ILogger logger, WebhookSender webhookSender)
: EventHostedServiceBase(eventAggregator, logger), IWebhookProvider
{
public abstract bool SupportsCustomerEmail { get; }
public abstract Dictionary<string, string> GetSupportedWebhookTypes();
public abstract WebhookEvent CreateTestEvent(string type, params object[] args);

View File

@@ -268,6 +268,14 @@ public class WebhookSender(
.SelectMany(provider => provider.GetSupportedWebhookTypes()).ToDictionary(pair => pair.Key, pair => pair.Value);
}
public Dictionary<string, bool> GetWebhookTypesSupportedByCustomerEmail()
{
return serviceProvider.GetServices<IWebhookProvider>()
.SelectMany(provider => provider.GetSupportedWebhookTypes()
.Select(pair => new { pair.Key, Value = provider.SupportsCustomerEmail }))
.ToDictionary(x => x.Key, x => x.Value);
}
public class WebhookDeliveryRequest(
string webhookId,
WebhookEvent webhookEvent,

View File

@@ -33,8 +33,8 @@
<h2>@ViewData["Title"]</h2>
</nav>
<div>
<button id="SaveEmailRules" type="submit" class="btn btn-primary">Save</button>
<a asp-action="StoreEmailRulesList" asp-route-storeId="@storeId" class="btn btn-secondary">Cancel</a>
<button id="SaveEmailRules" type="submit" class="btn btn-primary">Save</button>
<a asp-action="StoreEmailRulesList" asp-route-storeId="@storeId" class="btn btn-secondary">Cancel</a>
</div>
</div>
<partial name="_StatusMessage" />
@@ -55,8 +55,8 @@
<div class="form-text" text-translate="true">Who to send the email to. For multiple emails, separate with a comma.</div>
</div>
<div class="form-check mb-4">
<input asp-for="CustomerEmail" type="checkbox" class="form-check-input email-rule-customer-email" />
<div class="form-check mb-4 customer-email-container">
<input asp-for="CustomerEmail" type="checkbox" class="form-check-input email-rule-customer-email customer-email-checkbox" />
<label asp-for="CustomerEmail" class="form-check-label" text-translate="true">Send the email to the buyer, if email was provided to the invoice</label>
<span asp-validation-for="CustomerEmail" class="text-danger"></span>
</div>
@@ -229,11 +229,27 @@
}
}
function toggleCustomerEmailVisibility() {
const customerEmailContainer = document.querySelector('.customer-email-container');
const customerEmailCheckbox = document.querySelector('.customer-email-checkbox');
const selectedTrigger = triggerSelect.value;
const supportsCustomerEmailDict = @Safe.Json(WebhookSender.GetWebhookTypesSupportedByCustomerEmail());
if (supportsCustomerEmailDict[selectedTrigger]) {
customerEmailContainer.style.display = 'block';
} else {
customerEmailContainer.style.display = 'none';
customerEmailCheckbox.checked = false;
}
}
triggerSelect.addEventListener('change', applyTemplate);
triggerSelect.addEventListener('change', toggleCustomerEmailVisibility);
// Apply template on page load if a trigger is selected
if (triggerSelect.value) {
applyTemplate();
toggleCustomerEmailVisibility();
}
});
</script>