Webhooks: Fix invoice interpolation (#5586)

* Webhooks: Fix invoice interpolation

Fixes #5584.

* Syntax cleanups
This commit is contained in:
d11n 2023-12-22 02:50:08 +01:00 committed by GitHub
parent ad89139e07
commit c585a0b276
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 12 deletions

View file

@ -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<string>())
.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);

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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());