From c585a0b27608d4dd6c1f0652f3dc656a4a47cc82 Mon Sep 17 00:00:00 2001 From: d11n Date: Fri, 22 Dec 2023 02:50:08 +0100 Subject: [PATCH] Webhooks: Fix invoice interpolation (#5586) * Webhooks: Fix invoice interpolation Fixes #5584. * Syntax cleanups --- .../HostedServices/StoreEmailRuleProcessorSender.cs | 7 ++----- .../Webhooks/InvoiceWebhookDeliveryRequest.cs | 6 ++---- .../Webhooks/PaymentRequestWebhookDeliveryRequest.cs | 4 ++-- .../Webhooks/PayoutWebhookDeliveryRequest.cs | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/BTCPayServer/HostedServices/StoreEmailRuleProcessorSender.cs b/BTCPayServer/HostedServices/StoreEmailRuleProcessorSender.cs index 903adb4d9..3bf72cd88 100644 --- a/BTCPayServer/HostedServices/StoreEmailRuleProcessorSender.cs +++ b/BTCPayServer/HostedServices/StoreEmailRuleProcessorSender.cs @@ -59,15 +59,12 @@ public class StoreEmailRuleProcessorSender : EventHostedServiceBase var sender = await _emailSenderFactory.GetEmailSender(storeWebhookEvent.StoreId); foreach (UIStoresController.StoreEmailRule actionableRule in actionableRules) { - - - var request = new SendEmailRequest() + var request = new SendEmailRequest { Subject = actionableRule.Subject, Body = actionableRule.Body, Email = actionableRule.To }; request = await webhookDeliveryRequest.Interpolate(request, actionableRule); - var recipients = (request?.Email?.Split(",", StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty()) .Select(o => { @@ -77,7 +74,7 @@ public class StoreEmailRuleProcessorSender : EventHostedServiceBase .Where(o => o != null) .ToArray(); - if(recipients.Length == 0) + if (recipients.Length == 0) continue; sender.SendEmail(recipients.ToArray(), null, null, request.Subject, request.Body); diff --git a/BTCPayServer/HostedServices/Webhooks/InvoiceWebhookDeliveryRequest.cs b/BTCPayServer/HostedServices/Webhooks/InvoiceWebhookDeliveryRequest.cs index a7f818b52..6224606ec 100644 --- a/BTCPayServer/HostedServices/Webhooks/InvoiceWebhookDeliveryRequest.cs +++ b/BTCPayServer/HostedServices/Webhooks/InvoiceWebhookDeliveryRequest.cs @@ -1,11 +1,9 @@ -using System; -using System.Globalization; +using System.Globalization; using System.Threading.Tasks; using BTCPayServer.Client.Models; using BTCPayServer.Controllers; using BTCPayServer.Data; using BTCPayServer.Services.Invoices; -using Newtonsoft.Json.Linq; using WebhookDeliveryData = BTCPayServer.Data.WebhookDeliveryData; namespace BTCPayServer.HostedServices.Webhooks; @@ -46,7 +44,7 @@ public class InvoiceWebhookDeliveryRequest : WebhookSender.WebhookDeliveryReques .Replace("{Invoice.OrderId}", Invoice.Metadata.OrderId); - res = InterpolateJsonField(str, "Invoice.Metadata", Invoice.Metadata.ToJObject()); + res = InterpolateJsonField(res, "Invoice.Metadata", Invoice.Metadata.ToJObject()); return res; } diff --git a/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookDeliveryRequest.cs b/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookDeliveryRequest.cs index 61ac47e94..d8d740ce9 100644 --- a/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookDeliveryRequest.cs +++ b/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookDeliveryRequest.cs @@ -37,14 +37,14 @@ public class PaymentRequestWebhookDeliveryRequest : WebhookSender.WebhookDeliver private string Interpolate(string str, PaymentRequestBaseData blob) { - var res= str.Replace("{PaymentRequest.Id}", _evt.Data.Id) + var res = str.Replace("{PaymentRequest.Id}", _evt.Data.Id) .Replace("{PaymentRequest.Price}", blob.Amount.ToString(CultureInfo.InvariantCulture)) .Replace("{PaymentRequest.Currency}", blob.Currency) .Replace("{PaymentRequest.Title}", blob.Title) .Replace("{PaymentRequest.Description}", blob.Description) .Replace("{PaymentRequest.Status}", _evt.Data.Status.ToString()); - res= InterpolateJsonField(res, "PaymentRequest.FormResponse", blob.FormResponse); + res = InterpolateJsonField(res, "PaymentRequest.FormResponse", blob.FormResponse); return res; } } diff --git a/BTCPayServer/HostedServices/Webhooks/PayoutWebhookDeliveryRequest.cs b/BTCPayServer/HostedServices/Webhooks/PayoutWebhookDeliveryRequest.cs index b9213aa50..dc41dcbb2 100644 --- a/BTCPayServer/HostedServices/Webhooks/PayoutWebhookDeliveryRequest.cs +++ b/BTCPayServer/HostedServices/Webhooks/PayoutWebhookDeliveryRequest.cs @@ -23,7 +23,7 @@ public class PayoutWebhookDeliveryRequest(PayoutEvent evt, string? webhookId, We private string Interpolate(string str) { - var res= str.Replace("{Payout.Id}", evt.Payout.Id) + var res = str.Replace("{Payout.Id}", evt.Payout.Id) .Replace("{Payout.PullPaymentId}", evt.Payout.PullPaymentDataId) .Replace("{Payout.Destination}", evt.Payout.Destination) .Replace("{Payout.State}", evt.Payout.State.ToString());