diff --git a/BTCPayServer.Client/Models/WebhookEvent.cs b/BTCPayServer.Client/Models/WebhookEvent.cs index b117919f8..afedd6459 100644 --- a/BTCPayServer.Client/Models/WebhookEvent.cs +++ b/BTCPayServer.Client/Models/WebhookEvent.cs @@ -19,7 +19,31 @@ namespace BTCPayServer.Client.Models } public string DeliveryId { get; set; } public string WebhookId { get; set; } - public string OrignalDeliveryId { get; set; } + string _OriginalDeliveryId; + public string OriginalDeliveryId + { + get + { + if (_OriginalDeliveryId is null) + { + // Due to a typo in old version, we serialized `orignalDeliveryId` rather than `orignalDeliveryId` + // We silently fix that here. + // Note we can remove this code later on, as old webhook event are unlikely to be useful to anyone, + // and having a null orignalDeliveryId is not end of the world + if (AdditionalData != null && + AdditionalData.TryGetValue("orignalDeliveryId", out var tok)) + { + _OriginalDeliveryId = tok.Value(); + AdditionalData.Remove("orignalDeliveryId"); + } + } + return _OriginalDeliveryId; + } + set + { + _OriginalDeliveryId = value; + } + } public bool IsRedelivery { get; set; } [JsonConverter(typeof(StringEnumConverter))] public WebhookEventType Type { get; set; } diff --git a/BTCPayServer.Tests/GreenfieldAPITests.cs b/BTCPayServer.Tests/GreenfieldAPITests.cs index 195e80d21..f43a12f1d 100644 --- a/BTCPayServer.Tests/GreenfieldAPITests.cs +++ b/BTCPayServer.Tests/GreenfieldAPITests.cs @@ -687,7 +687,7 @@ namespace BTCPayServer.Tests Assert.NotNull(newDelivery); Assert.Equal(404, newDelivery.HttpCode); var req = await clientProfile.GetWebhookDeliveryRequest(user.StoreId, hook.Id, newDeliveryId); - Assert.Equal(delivery.Id, req.OrignalDeliveryId); + Assert.Equal(delivery.Id, req.OriginalDeliveryId); Assert.True(req.IsRedelivery); Assert.Equal(WebhookDeliveryStatus.HttpError, newDelivery.Status); }); diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index 0dbf55809..f2dadb392 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -3175,6 +3175,18 @@ namespace BTCPayServer.Tests } } + [Trait("Fast", "Fast")] + [Fact] + public void CanFixupWebhookEventPropertyName() + { + string legacy = "{\"orignalDeliveryId\":\"blahblah\"}"; + var obj = JsonConvert.DeserializeObject(legacy, WebhookEvent.DefaultSerializerSettings); + Assert.Equal("blahblah", obj.OriginalDeliveryId); + var serialized = JsonConvert.SerializeObject(obj, WebhookEvent.DefaultSerializerSettings); + Assert.DoesNotContain("orignalDeliveryId", serialized); + Assert.Contains("originalDeliveryId", serialized); + } + [Fact(Timeout = LongRunningTestTimeout)] [Trait("Fast", "Fast")] public async Task CanCreateSqlitedb() diff --git a/BTCPayServer/HostedServices/WebhookNotificationManager.cs b/BTCPayServer/HostedServices/WebhookNotificationManager.cs index bef2fb210..ee4d90f2a 100644 --- a/BTCPayServer/HostedServices/WebhookNotificationManager.cs +++ b/BTCPayServer/HostedServices/WebhookNotificationManager.cs @@ -101,7 +101,7 @@ namespace BTCPayServer.HostedServices webhookEvent.DeliveryId = newDelivery.Id; webhookEvent.WebhookId = webhookDelivery.Webhook.Id; // if we redelivered a redelivery, we still want the initial delivery here - webhookEvent.OrignalDeliveryId ??= deliveryId; + webhookEvent.OriginalDeliveryId ??= deliveryId; webhookEvent.IsRedelivery = true; newDeliveryBlob.Request = ToBytes(webhookEvent); newDelivery.SetBlob(newDeliveryBlob); @@ -125,7 +125,7 @@ namespace BTCPayServer.HostedServices webhookEvent.StoreId = invoiceEvent.Invoice.StoreId; webhookEvent.DeliveryId = delivery.Id; webhookEvent.WebhookId = webhook.Id; - webhookEvent.OrignalDeliveryId = delivery.Id; + webhookEvent.OriginalDeliveryId = delivery.Id; webhookEvent.IsRedelivery = false; webhookEvent.Timestamp = delivery.Timestamp; var context = new WebhookDeliveryRequest(webhook.Id, webhookEvent, delivery, webhookBlob);