From 420954ed00d2e2b993f0933f773db84f4025b670 Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Mon, 28 Nov 2022 00:50:52 -0800 Subject: [PATCH] Add metadata to invoice webhook event (#4370) close #4223 --- BTCPayServer.Client/Models/WebhookInvoiceEvent.cs | 6 ++---- BTCPayServer/HostedServices/WebhookSender.cs | 1 + .../wwwroot/swagger/v1/swagger.template.webhooks.json | 7 ++++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/BTCPayServer.Client/Models/WebhookInvoiceEvent.cs b/BTCPayServer.Client/Models/WebhookInvoiceEvent.cs index 8ab503d1e..fff25d13c 100644 --- a/BTCPayServer.Client/Models/WebhookInvoiceEvent.cs +++ b/BTCPayServer.Client/Models/WebhookInvoiceEvent.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Text; using Newtonsoft.Json; -using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; namespace BTCPayServer.Client.Models { @@ -19,6 +16,7 @@ namespace BTCPayServer.Client.Models [JsonProperty(Order = 1)] public string StoreId { get; set; } [JsonProperty(Order = 2)] public string InvoiceId { get; set; } + [JsonProperty(Order = 3)] public JObject Metadata { get; set; } } public class WebhookInvoiceSettledEvent : WebhookInvoiceEvent diff --git a/BTCPayServer/HostedServices/WebhookSender.cs b/BTCPayServer/HostedServices/WebhookSender.cs index adca83cff..8b3e92893 100644 --- a/BTCPayServer/HostedServices/WebhookSender.cs +++ b/BTCPayServer/HostedServices/WebhookSender.cs @@ -157,6 +157,7 @@ namespace BTCPayServer.HostedServices webhookEvent.DeliveryId = delivery.Id; webhookEvent.WebhookId = webhook.Id; webhookEvent.OriginalDeliveryId = delivery.Id; + webhookEvent.Metadata = invoiceEvent.Invoice.Metadata.ToJObject(); webhookEvent.IsRedelivery = false; webhookEvent.Timestamp = delivery.Timestamp; var context = new WebhookDeliveryRequest(webhook.Id, webhookEvent, delivery, webhookBlob); diff --git a/BTCPayServer/wwwroot/swagger/v1/swagger.template.webhooks.json b/BTCPayServer/wwwroot/swagger/v1/swagger.template.webhooks.json index 5706e8ffb..a5a67bcbe 100644 --- a/BTCPayServer/wwwroot/swagger/v1/swagger.template.webhooks.json +++ b/BTCPayServer/wwwroot/swagger/v1/swagger.template.webhooks.json @@ -673,7 +673,12 @@ "type": "string", "description": "The invoice id of the invoice's event", "nullable": false - } + }, + "metadata": { + "type": "object", + "description": "User-supplied metadata added to the invoice at the time of its creation", + "nullable": false + } } } ]