diff --git a/MidrandBooksApi/MidrandBooksApi.csproj b/MidrandBooksApi/MidrandBooksApi.csproj
index 057e90a..72eea12 100644
--- a/MidrandBooksApi/MidrandBooksApi.csproj
+++ b/MidrandBooksApi/MidrandBooksApi.csproj
@@ -53,13 +53,13 @@
-
+
-
+
@@ -85,6 +85,7 @@
+
diff --git a/MidrandBooksApi/Payments/Endpoints/ConfirmationEndpoint.cs b/MidrandBooksApi/Payments/Endpoints/ConfirmationEndpoint.cs
index 62a0d5c..f250c5a 100644
--- a/MidrandBooksApi/Payments/Endpoints/ConfirmationEndpoint.cs
+++ b/MidrandBooksApi/Payments/Endpoints/ConfirmationEndpoint.cs
@@ -1,17 +1,24 @@
-using LiteCharms.Features.Extensions;
-using LiteCharms.Features.Hasher;
+using LiteCharms.Features.Hasher;
+using LiteCharms.Features.MidrandBooks.Payments.Events;
using LiteCharms.Features.Models;
+using LiteCharms.Features.Quartz.Abstractions;
namespace MidrandBooksApi.Payments.Endpoints;
[ApiVersionTarget(1)]
public sealed class ConfirmationEndpoint : IEndpoint
{
+ private static readonly ActivitySource PaymentActivitySource = new("MidrandBooksApi.Payments");
+
public void Map(IEndpointRouteBuilder builder)
{
builder.MapPost("payments/confirm", async (HttpRequest request, HashService hashService,
- CancellationToken cancellationToken) =>
+ IJobOrchestrator jobOrchestrator, CancellationToken cancellationToken) =>
{
+ using Activity? activity = PaymentActivitySource.StartActivity("ReceivePayfastWebhook", ActivityKind.Server);
+ activity?.SetTag("messaging.system", "payfast");
+ activity?.SetTag("messaging.destination.name", "payments/confirm");
+
var formCollection = await request.ReadFormAsync(cancellationToken);
if (!formCollection.TryGetValue("signature", out var signatureValues) || string.IsNullOrWhiteSpace(signatureValues.ToString()))
@@ -28,9 +35,13 @@ public sealed class ConfirmationEndpoint : IEndpoint
var validationResult = hashService.VerifyPayfastWebhookSignature(payload, incomingSignature);
- return validationResult.IsFailed || !validationResult.Value
- ? Results.Unauthorized()
- : Results.Ok();
+ if (validationResult.IsFailed || !validationResult.Value) return Results.Unauthorized();
+
+ await jobOrchestrator.SendAsync(PayfastPaymentConfirmationReceivedEvent.Create(payload, payload.MPaymentId!), cancellationToken);
+
+ activity?.SetStatus(ActivityStatusCode.Ok);
+
+ return Results.Ok();
})
.WithDescription("Securely confirm and process an incoming Payfast merchant payment callback.")
.WithName(typeof(ConfirmationEndpoint).ToEndpointName())