diff --git a/BTCPayServer.Client/Models/WebhookEventType.cs b/BTCPayServer.Client/Models/WebhookEventType.cs index ed2d431c4..b7c1e6bcb 100644 --- a/BTCPayServer.Client/Models/WebhookEventType.cs +++ b/BTCPayServer.Client/Models/WebhookEventType.cs @@ -17,5 +17,6 @@ public static class WebhookEventType public const string PaymentRequestCreated = nameof(PaymentRequestCreated); public const string PaymentRequestArchived = nameof(PaymentRequestArchived); public const string PaymentRequestStatusChanged = nameof(PaymentRequestStatusChanged); + public const string PaymentRequestCompleted = nameof(PaymentRequestCompleted); } diff --git a/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookDeliveryRequest.cs b/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookDeliveryRequest.cs index 7130442d2..ef587f950 100644 --- a/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookDeliveryRequest.cs +++ b/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookDeliveryRequest.cs @@ -47,7 +47,8 @@ public class PaymentRequestWebhookDeliveryRequest : WebhookSender.WebhookDeliver .Replace("{PaymentRequest.Currency}", data.Currency) .Replace("{PaymentRequest.Title}", blob.Title) .Replace("{PaymentRequest.Description}", blob.Description) - .Replace("{PaymentRequest.Status}", data.Status.ToString()); + .Replace("{PaymentRequest.ReferenceNumber}", blob.ReferenceNumber) + .Replace("{PaymentRequest.Status}", _evt.Data.Status.ToString()); res = InterpolateJsonField(res, "PaymentRequest.FormResponse", blob.FormResponse); return res; diff --git a/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookProvider.cs b/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookProvider.cs index c018b3ea4..4df461544 100644 --- a/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookProvider.cs +++ b/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookProvider.cs @@ -22,6 +22,7 @@ public class PaymentRequestWebhookProvider: WebhookProvider {WebhookEventType.PaymentRequestUpdated, "Payment Request - Updated"}, {WebhookEventType.PaymentRequestArchived, "Payment Request - Archived"}, {WebhookEventType.PaymentRequestStatusChanged, "Payment Request - Status Changed"}, + {WebhookEventType.PaymentRequestCompleted, "Payment Request - Completed"}, }; } @@ -42,6 +43,7 @@ public class PaymentRequestWebhookProvider: WebhookProvider PaymentRequestEvent.Updated => new WebhookPaymentRequestEvent(WebhookEventType.PaymentRequestUpdated, evt.Data.StoreDataId), PaymentRequestEvent.Archived => new WebhookPaymentRequestEvent(WebhookEventType.PaymentRequestArchived, evt.Data.StoreDataId), PaymentRequestEvent.StatusChanged => new WebhookPaymentRequestEvent(WebhookEventType.PaymentRequestStatusChanged, evt.Data.StoreDataId), + PaymentRequestEvent.Completed => new WebhookPaymentRequestEvent(WebhookEventType.PaymentRequestCompleted, evt.Data.StoreDataId), _ => null }; } diff --git a/BTCPayServer/Services/PaymentRequests/PaymentRequestRepository.cs b/BTCPayServer/Services/PaymentRequests/PaymentRequestRepository.cs index a20271c82..f8fce82f8 100644 --- a/BTCPayServer/Services/PaymentRequests/PaymentRequestRepository.cs +++ b/BTCPayServer/Services/PaymentRequests/PaymentRequestRepository.cs @@ -15,6 +15,7 @@ namespace BTCPayServer.Services.PaymentRequests public const string Updated = nameof(Updated); public const string Archived = nameof(Archived); public const string StatusChanged = nameof(StatusChanged); + public const string Completed = nameof(Completed); public PaymentRequestData Data { get; set; } public string Type { get; set; } } @@ -99,9 +100,7 @@ namespace BTCPayServer.Services.PaymentRequests { await using var context = _ContextFactory.CreateContext(); var paymentRequestData = await context.FindAsync(paymentRequestId); - if (paymentRequestData == null) - return; - if( paymentRequestData.Status == status) + if (paymentRequestData == null || paymentRequestData.Status == status) return; paymentRequestData.Status = status; @@ -112,6 +111,15 @@ namespace BTCPayServer.Services.PaymentRequests Data = paymentRequestData, Type = PaymentRequestEvent.StatusChanged }); + + if (status == Client.Models.PaymentRequestData.PaymentRequestStatus.Completed) + { + _eventAggregator.Publish(new PaymentRequestEvent() + { + Data = paymentRequestData, + Type = PaymentRequestEvent.Completed + }); + } } public async Task GetExpirablePaymentRequests(CancellationToken cancellationToken = default) {