Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db0715ceca | |||
| fc2f457add | |||
| 60e916d972 | |||
| 851ca72b46 | |||
| 27418322f4 | |||
| 99a307527a | |||
| b731ebdcea | |||
| 3deffab351 |
+2
-1
@@ -360,4 +360,5 @@ MigrationBackup/
|
||||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
FodyWeavers.xsd
|
||||
/MidrandBooksApi/http/http-client.env.json
|
||||
|
||||
@@ -53,13 +53,13 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LiteCharms.Features" Version="1.61.0" />
|
||||
<PackageReference Include="LiteCharms.Features" Version="1.64.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- UI -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ANM.Blazored.Toast" Version="0.1.1" />
|
||||
<PackageReference Include="LiteCharms.Features.MidrandBooks" Version="1.61.0" />
|
||||
<PackageReference Include="LiteCharms.Features.MidrandBooks" Version="1.64.0" />
|
||||
|
||||
<!-- Global Usings -->
|
||||
<Using Include="Blazored.Toast.Services" />
|
||||
@@ -85,6 +85,7 @@
|
||||
|
||||
<!-- Shared Global Usings -->
|
||||
<ItemGroup>
|
||||
<Using Include="System.Diagnostics" />
|
||||
<Using Include="System.Reflection" />
|
||||
<Using Include="Microsoft.Extensions.DependencyInjection.Extensions" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -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) =>
|
||||
builder.MapPost("payments/payfast/confirm", async (HttpRequest request, HashService hashService,
|
||||
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())
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Asp.Versioning.Builder;
|
||||
using k8s.Models;
|
||||
using LiteCharms.Features.Extensions;
|
||||
using LiteCharms.Features.Mediator;
|
||||
using LiteCharms.Features.MidrandBooks.Extensions;
|
||||
@@ -74,6 +75,10 @@ app.UseHealthChecks("/ready");
|
||||
|
||||
app.MapOpenApi();
|
||||
|
||||
var apiVersions = app.DescribeApiVersions()
|
||||
.OrderByDescending(o => o.ApiVersion.MajorVersion)
|
||||
.ToList();
|
||||
|
||||
foreach (var description in app.DescribeApiVersions().OrderByDescending(o => o.ApiVersion.MajorVersion))
|
||||
app.MapScalarApiReference($"/openapi/{description.GroupName}", (options, context) =>
|
||||
{
|
||||
@@ -84,6 +89,10 @@ foreach (var description in app.DescribeApiVersions().OrderByDescending(o => o.A
|
||||
options.Authentication = new ScalarAuthenticationOptions { PreferredSecuritySchemes = ["Bearer"] };
|
||||
});
|
||||
|
||||
var latestVersionGroup = apiVersions.FirstOrDefault()?.GroupName ?? "v1";
|
||||
|
||||
app.MapGet("/", () => Results.Redirect($"/openapi/{latestVersionGroup}"))
|
||||
.ExcludeFromDescription();
|
||||
|
||||
if (!app.Environment.IsDevelopment())
|
||||
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7196;http://localhost:5159",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
## 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}}
|
||||
Reference in New Issue
Block a user