Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db0715ceca | |||
| fc2f457add | |||
| 60e916d972 | |||
| 851ca72b46 | |||
| 27418322f4 | |||
| 99a307527a | |||
| b731ebdcea | |||
| 3deffab351 |
@@ -361,3 +361,4 @@ MigrationBackup/
|
|||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
|
/MidrandBooksApi/http/http-client.env.json
|
||||||
|
|||||||
@@ -53,13 +53,13 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="LiteCharms.Features" Version="1.61.0" />
|
<PackageReference Include="LiteCharms.Features" Version="1.64.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.61.0" />
|
<PackageReference Include="LiteCharms.Features.MidrandBooks" Version="1.64.0" />
|
||||||
|
|
||||||
<!-- Global Usings -->
|
<!-- Global Usings -->
|
||||||
<Using Include="Blazored.Toast.Services" />
|
<Using Include="Blazored.Toast.Services" />
|
||||||
@@ -85,6 +85,7 @@
|
|||||||
|
|
||||||
<!-- 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,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.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/confirm", async (HttpRequest request, HashService hashService,
|
builder.MapPost("payments/payfast/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);
|
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()))
|
||||||
@@ -28,9 +35,13 @@ public sealed class ConfirmationEndpoint : IEndpoint
|
|||||||
|
|
||||||
var validationResult = hashService.VerifyPayfastWebhookSignature(payload, incomingSignature);
|
var validationResult = hashService.VerifyPayfastWebhookSignature(payload, incomingSignature);
|
||||||
|
|
||||||
return validationResult.IsFailed || !validationResult.Value
|
if (validationResult.IsFailed || !validationResult.Value) return Results.Unauthorized();
|
||||||
? Results.Unauthorized()
|
|
||||||
: Results.Ok();
|
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.")
|
.WithDescription("Securely confirm and process an incoming Payfast merchant payment callback.")
|
||||||
.WithName(typeof(ConfirmationEndpoint).ToEndpointName())
|
.WithName(typeof(ConfirmationEndpoint).ToEndpointName())
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Asp.Versioning.Builder;
|
using Asp.Versioning.Builder;
|
||||||
|
using k8s.Models;
|
||||||
using LiteCharms.Features.Extensions;
|
using LiteCharms.Features.Extensions;
|
||||||
using LiteCharms.Features.Mediator;
|
using LiteCharms.Features.Mediator;
|
||||||
using LiteCharms.Features.MidrandBooks.Extensions;
|
using LiteCharms.Features.MidrandBooks.Extensions;
|
||||||
@@ -74,6 +75,10 @@ app.UseHealthChecks("/ready");
|
|||||||
|
|
||||||
app.MapOpenApi();
|
app.MapOpenApi();
|
||||||
|
|
||||||
|
var apiVersions = app.DescribeApiVersions()
|
||||||
|
.OrderByDescending(o => o.ApiVersion.MajorVersion)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
foreach (var description in app.DescribeApiVersions().OrderByDescending(o => o.ApiVersion.MajorVersion))
|
foreach (var description in app.DescribeApiVersions().OrderByDescending(o => o.ApiVersion.MajorVersion))
|
||||||
app.MapScalarApiReference($"/openapi/{description.GroupName}", (options, context) =>
|
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"] };
|
options.Authentication = new ScalarAuthenticationOptions { PreferredSecuritySchemes = ["Bearer"] };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var latestVersionGroup = apiVersions.FirstOrDefault()?.GroupName ?? "v1";
|
||||||
|
|
||||||
|
app.MapGet("/", () => Results.Redirect($"/openapi/{latestVersionGroup}"))
|
||||||
|
.ExcludeFromDescription();
|
||||||
|
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
||||||
|
|||||||
@@ -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