mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Cleaning up Webhooks code
This commit is contained in:
@@ -4,25 +4,26 @@ using BTCPayServer.Client.Models;
|
||||
using BTCPayServer.Controllers;
|
||||
using BTCPayServer.Data;
|
||||
using BTCPayServer.Services.Invoices;
|
||||
using MimeKit;
|
||||
using WebhookDeliveryData = BTCPayServer.Data.WebhookDeliveryData;
|
||||
|
||||
namespace BTCPayServer.HostedServices.Webhooks;
|
||||
|
||||
public class InvoiceWebhookDeliveryRequest : WebhookSender.WebhookDeliveryRequest
|
||||
public class InvoiceWebhookDeliveryRequest(
|
||||
InvoiceEntity invoice,
|
||||
string webhookId,
|
||||
WebhookEvent webhookEvent,
|
||||
WebhookDeliveryData delivery,
|
||||
WebhookBlob webhookBlob)
|
||||
: WebhookSender.WebhookDeliveryRequest(webhookId, webhookEvent, delivery, webhookBlob)
|
||||
{
|
||||
public InvoiceEntity Invoice { get; }
|
||||
|
||||
public InvoiceWebhookDeliveryRequest(InvoiceEntity invoice, string webhookId, WebhookEvent webhookEvent,
|
||||
WebhookDeliveryData delivery, WebhookBlob webhookBlob) : base(webhookId, webhookEvent, delivery, webhookBlob)
|
||||
{
|
||||
Invoice = invoice;
|
||||
}
|
||||
public InvoiceEntity Invoice { get; } = invoice;
|
||||
|
||||
public override Task<SendEmailRequest> Interpolate(SendEmailRequest req,
|
||||
UIStoresController.StoreEmailRule storeEmailRule)
|
||||
{
|
||||
if (storeEmailRule.CustomerEmail &&
|
||||
MailboxAddressValidator.TryParse(Invoice.Metadata.BuyerEmail, out var bmb))
|
||||
MailboxAddressValidator.TryParse(Invoice.Metadata.BuyerEmail, out MailboxAddress bmb))
|
||||
{
|
||||
req.Email ??= string.Empty;
|
||||
req.Email += $",{bmb}";
|
||||
@@ -35,7 +36,7 @@ public class InvoiceWebhookDeliveryRequest : WebhookSender.WebhookDeliveryReques
|
||||
|
||||
private string Interpolate(string str)
|
||||
{
|
||||
var res = str.Replace("{Invoice.Id}", Invoice.Id)
|
||||
string res = str.Replace("{Invoice.Id}", Invoice.Id)
|
||||
.Replace("{Invoice.StoreId}", Invoice.StoreId)
|
||||
.Replace("{Invoice.Price}", Invoice.Price.ToString(CultureInfo.InvariantCulture))
|
||||
.Replace("{Invoice.Currency}", Invoice.Currency)
|
||||
@@ -47,5 +48,4 @@ public class InvoiceWebhookDeliveryRequest : WebhookSender.WebhookDeliveryReques
|
||||
res = InterpolateJsonField(res, "Invoice.Metadata", Invoice.Metadata.ToJObject());
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user