Compare commits

..
3 Commits
5 changed files with 11 additions and 32 deletions
+1 -2
View File
@@ -360,5 +360,4 @@ MigrationBackup/
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
/MidrandBooksApi/http/http-client.env.json
FodyWeavers.xsd
+2 -3
View File
@@ -53,13 +53,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="LiteCharms.Features" Version="1.64.0" />
<PackageReference Include="LiteCharms.Features" Version="1.61.0" />
</ItemGroup>
<!-- UI -->
<ItemGroup>
<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 -->
<Using Include="Blazored.Toast.Services" />
@@ -85,7 +85,6 @@
<!-- Shared Global Usings -->
<ItemGroup>
<Using Include="System.Diagnostics" />
<Using Include="System.Reflection" />
<Using Include="Microsoft.Extensions.DependencyInjection.Extensions" />
</ItemGroup>
@@ -1,24 +1,17 @@
using LiteCharms.Features.Hasher;
using LiteCharms.Features.MidrandBooks.Payments.Events;
using LiteCharms.Features.Extensions;
using LiteCharms.Features.Hasher;
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/payfast/confirm", async (HttpRequest request, HashService hashService,
IJobOrchestrator jobOrchestrator, CancellationToken cancellationToken) =>
builder.MapPost("payments/confirm", async (HttpRequest request, HashService hashService,
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()))
@@ -35,13 +28,9 @@ public sealed class ConfirmationEndpoint : IEndpoint
var validationResult = hashService.VerifyPayfastWebhookSignature(payload, incomingSignature);
if (validationResult.IsFailed || !validationResult.Value) return Results.Unauthorized();
await jobOrchestrator.SendAsync(PayfastPaymentConfirmationReceivedEvent.Create(payload, payload.MPaymentId!), cancellationToken);
activity?.SetStatus(ActivityStatusCode.Ok);
return Results.Ok();
return validationResult.IsFailed || !validationResult.Value
? Results.Unauthorized()
: Results.Ok();
})
.WithDescription("Securely confirm and process an incoming Payfast merchant payment callback.")
.WithName(typeof(ConfirmationEndpoint).ToEndpointName())
@@ -13,7 +13,7 @@
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"launchBrowser": false,
"applicationUrl": "https://localhost:7196;http://localhost:5159",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
-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}}