|
|
|
@@ -16,7 +16,8 @@ public sealed class PayfastConfirmationEndpoint : IEndpoint
|
|
|
|
|
public void Map(IEndpointRouteBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.MapPost("payments/payfast/confirm", async (HttpRequest request, PayfastService payfastService,
|
|
|
|
|
IJobOrchestrator jobOrchestrator, IConfiguration configuration, IHostEnvironment hostEnvironment, CancellationToken cancellationToken) =>
|
|
|
|
|
IJobOrchestrator jobOrchestrator, IConfiguration configuration, IHostEnvironment hostEnvironment,
|
|
|
|
|
ILogger<PayfastConfirmationEndpoint> logger, CancellationToken cancellationToken) =>
|
|
|
|
|
{
|
|
|
|
|
using Activity? activity = PaymentActivitySource.StartActivity("ReceivePayfastWebhook", ActivityKind.Server);
|
|
|
|
|
|
|
|
|
@@ -39,7 +40,11 @@ public sealed class PayfastConfirmationEndpoint : IEndpoint
|
|
|
|
|
var signatureCheck = PayfastService.GenerateSignature(paramDictionary, passphrase);
|
|
|
|
|
|
|
|
|
|
if (signatureCheck.IsFailed || !string.Equals(signatureCheck.Value, incomingSignature, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
logger.LogCritical($"Incoming sugnature failed validation: {incomingSignature}, {signatureCheck.Errors.Select(e => e.Message).ToList()}");
|
|
|
|
|
|
|
|
|
|
return Results.Unauthorized();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var formPairs = formCollection.Select(kvp => $"{kvp.Key}={HttpUtility.UrlEncode(kvp.Value.ToString())}");
|
|
|
|
|
|
|
|
|
@@ -50,7 +55,11 @@ public sealed class PayfastConfirmationEndpoint : IEndpoint
|
|
|
|
|
var serverConfirmation = await payfastService.ValidateServerConfirmationAsync(rawQueryParamString, isSandbox, cancellationToken);
|
|
|
|
|
|
|
|
|
|
if (serverConfirmation.IsFailed || !serverConfirmation.Value)
|
|
|
|
|
{
|
|
|
|
|
logger.LogCritical($"Server confirmation failed: {rawQueryParamString}, {serverConfirmation.Errors.Select(e => e.Message).ToList()}");
|
|
|
|
|
|
|
|
|
|
return Results.Unauthorized();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var notification = PayfastPaymentConfirmationReceivedEvent.Create(payload, payload.MerchantPaymentId!,
|
|
|
|
|
allowLoopback: !hostEnvironment.IsProduction(), performBackgroundChecks: false);
|
|
|
|
|