diff --git a/BTCPayServer/Controllers/StoresController.Integrations.cs b/BTCPayServer/Controllers/StoresController.Integrations.cs index b21addc63..fa66e6f93 100644 --- a/BTCPayServer/Controllers/StoresController.Integrations.cs +++ b/BTCPayServer/Controllers/StoresController.Integrations.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using BTCPayServer.Data; using BTCPayServer.Models; using BTCPayServer.Models.StoreViewModels; +using BTCPayServer.Client.Models; using Microsoft.AspNetCore.Mvc; using NBitcoin; using NBitcoin.DataEncoders; @@ -18,17 +19,31 @@ namespace BTCPayServer.Controllers return View("Integrations", new IntegrationsViewModel()); } + private async Task LastDeliveryForWebhook(string webhookId) + { + return (await _Repo.GetWebhookDeliveries(CurrentStore.Id, webhookId, 1)).ToList().FirstOrDefault(); + } + [HttpGet("{storeId}/webhooks")] public async Task Webhooks() { var webhooks = await _Repo.GetWebhooks(CurrentStore.Id); return View(nameof(Webhooks), new WebhooksViewModel() - { - Webhooks = webhooks.Select(w => new WebhooksViewModel.WebhookViewModel() { - Id = w.Id, - Url = w.GetBlob().Url - }).ToArray() + Webhooks = webhooks.Select(async w => { + var lastDelivery = await LastDeliveryForWebhook(w.Id); + var lastDeliveryBlob = lastDelivery?.GetBlob(); + + return new WebhooksViewModel.WebhookViewModel() + { + Id = w.Id, + Url = w.GetBlob().Url, + LastDeliveryErrorMessage = lastDeliveryBlob?.ErrorMessage, + LastDeliveryTimeStamp = lastDelivery?.Timestamp, + LastDeliverySuccessful = lastDeliveryBlob == null ? true : lastDeliveryBlob.Status == WebhookDeliveryStatus.HttpSuccess, + }; + } + ).Select(t => t.Result).ToArray() }); } diff --git a/BTCPayServer/Models/StoreViewModels/WebhooksViewModel.cs b/BTCPayServer/Models/StoreViewModels/WebhooksViewModel.cs index b46bec728..f19b4fa87 100644 --- a/BTCPayServer/Models/StoreViewModels/WebhooksViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/WebhooksViewModel.cs @@ -1,7 +1,5 @@ +#nullable enable using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace BTCPayServer.Models.StoreViewModels { @@ -11,6 +9,9 @@ namespace BTCPayServer.Models.StoreViewModels { public string Id { get; set; } public string Url { get; set; } + public bool LastDeliverySuccessful { get; set; } = true; + public DateTimeOffset? LastDeliveryTimeStamp { get; set; } = null; + public string? LastDeliveryErrorMessage { get; set; } = null; } public WebhookViewModel[] Webhooks { get; set; } } diff --git a/BTCPayServer/Views/Stores/Webhooks.cshtml b/BTCPayServer/Views/Stores/Webhooks.cshtml index 54200edfb..c321fbfb2 100644 --- a/BTCPayServer/Views/Stores/Webhooks.cshtml +++ b/BTCPayServer/Views/Stores/Webhooks.cshtml @@ -17,19 +17,39 @@ { - - - - + + + + + @foreach (var wh in Model.Webhooks) { + @@ -45,5 +65,5 @@ else } @section PageFootContent { - + }
UrlActions
StatusUrlActions
+ @if (wh.LastDeliverySuccessful) + { + + } + else + { + + } + @wh.Url Test - - Modify - + Modify - Delete