Compare commits

..
3 Commits
5 changed files with 11 additions and 32 deletions
-1
View File
@@ -361,4 +361,3 @@ MigrationBackup/
# Fody - auto-generated XML schema # Fody - auto-generated XML schema
FodyWeavers.xsd FodyWeavers.xsd
/MidrandBooksApi/http/http-client.env.json
+2 -3
View File
@@ -53,13 +53,13 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="LiteCharms.Features" Version="1.64.0" /> <PackageReference Include="LiteCharms.Features" Version="1.61.0" />
</ItemGroup> </ItemGroup>
<!-- UI --> <!-- UI -->
<ItemGroup> <ItemGroup>
<PackageReference Include="ANM.Blazored.Toast" Version="0.1.1" /> <PackageReference Include="ANM.Blazored.Toast" Version="0.1.1" />
<PackageReference Include="LiteCharms.Features.MidrandBooks" Version="1.64.0" /> <PackageReference Include="LiteCharms.Features.MidrandBooks" Version="1.61.0" />
<!-- Global Usings --> <!-- Global Usings -->
<Using Include="Blazored.Toast.Services" /> <Using Include="Blazored.Toast.Services" />
@@ -85,7 +85,6 @@
<!-- Shared Global Usings --> <!-- Shared Global Usings -->
<ItemGroup> <ItemGroup>
<Using Include="System.Diagnostics" />
<Using Include="System.Reflection" /> <Using Include="System.Reflection" />
<Using Include="Microsoft.Extensions.DependencyInjection.Extensions" /> <Using Include="Microsoft.Extensions.DependencyInjection.Extensions" />
</ItemGroup> </ItemGroup>
@@ -1,24 +1,17 @@
using LiteCharms.Features.Hasher; using LiteCharms.Features.Extensions;
using LiteCharms.Features.MidrandBooks.Payments.Events; using LiteCharms.Features.Hasher;
using LiteCharms.Features.Models; using LiteCharms.Features.Models;
using LiteCharms.Features.Quartz.Abstractions;
namespace MidrandBooksApi.Payments.Endpoints; namespace MidrandBooksApi.Payments.Endpoints;
[ApiVersionTarget(1)] [ApiVersionTarget(1)]
public sealed class ConfirmationEndpoint : IEndpoint public sealed class ConfirmationEndpoint : IEndpoint
{ {
private static readonly ActivitySource PaymentActivitySource = new("MidrandBooksApi.Payments");
public void Map(IEndpointRouteBuilder builder) public void Map(IEndpointRouteBuilder builder)
{ {
builder.MapPost("payments/payfast/confirm", async (HttpRequest request, HashService hashService, builder.MapPost("payments/confirm", async (HttpRequest request, HashService hashService,
IJobOrchestrator jobOrchestrator, CancellationToken cancellationToken) => 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); var formCollection = await request.ReadFormAsync(cancellationToken);
if (!formCollection.TryGetValue("signature", out var signatureValues) || string.IsNullOrWhiteSpace(signatureValues.ToString())) if (!formCollection.TryGetValue("signature", out var signatureValues) || string.IsNullOrWhiteSpace(signatureValues.ToString()))
@@ -35,13 +28,9 @@ public sealed class ConfirmationEndpoint : IEndpoint
var validationResult = hashService.VerifyPayfastWebhookSignature(payload, incomingSignature); var validationResult = hashService.VerifyPayfastWebhookSignature(payload, incomingSignature);
if (validationResult.IsFailed || !validationResult.Value) return Results.Unauthorized(); return validationResult.IsFailed || !validationResult.Value
? Results.Unauthorized()
await jobOrchestrator.SendAsync(PayfastPaymentConfirmationReceivedEvent.Create(payload, payload.MPaymentId!), cancellationToken); : Results.Ok();
activity?.SetStatus(ActivityStatusCode.Ok);
return Results.Ok();
}) })
.WithDescription("Securely confirm and process an incoming Payfast merchant payment callback.") .WithDescription("Securely confirm and process an incoming Payfast merchant payment callback.")
.WithName(typeof(ConfirmationEndpoint).ToEndpointName()) .WithName(typeof(ConfirmationEndpoint).ToEndpointName())
-8
View File
@@ -1,8 +0,0 @@
## Payfast Payment Confirmation
# This endpoint is used by Payfast to confirm the payment status of a transaction.
# It receives a POST request with the payment details and updates the order status accordingly.
POST {{baseUrl}}/v1/payments/payfast/confirm
Content-Type: application/x-www-form-urlencoded
amount={{amount}}&item_name={{item_name}}&m_payment_id={{paymentId}}&signature={{signature}}