From 7d2bc7f1f248edbc2e64b4c37197a61928ec6d58 Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Fri, 12 Jun 2026 23:26:54 +0200 Subject: [PATCH] Refactored PayfastService.GenerateSignature() --- .../Payments/PayfastService.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/LiteCharms.Features.MidrandBooks/Payments/PayfastService.cs b/LiteCharms.Features.MidrandBooks/Payments/PayfastService.cs index 1208667..8aa1eec 100644 --- a/LiteCharms.Features.MidrandBooks/Payments/PayfastService.cs +++ b/LiteCharms.Features.MidrandBooks/Payments/PayfastService.cs @@ -157,9 +157,11 @@ public sealed partial class PayfastService(IDbContextFactory m.Value.ToLowerInvariant()); + // 2. Payfast requires all OTHER percent-encoded hex arrays to be UPPERCASE (e.g., %3A instead of %3a) + string val = Regex.Replace(encodedVal, "%[0-9A-Fa-f]{2}", m => m.Value.ToUpperInvariant()); pfOutput.Append($"{key}={val}&"); } @@ -170,8 +172,9 @@ public sealed partial class PayfastService(IDbContextFactory m.Value.ToLowerInvariant()); + // Apply the exact same encoding rule to your passphrase + string encodedPassphrase = HttpUtility.UrlEncode(passPhrase.Trim()); + string safePassphrase = Regex.Replace(encodedPassphrase, "%[0-9A-Fa-f]{2}", m => m.Value.ToUpperInvariant()); getString += $"&passphrase={safePassphrase}"; }