Merge pull request 'Refactored PayfastService.GenerateSignature()' (#104) from payments into master
Reviewed-on: #104
This commit was merged in pull request #104.
This commit is contained in:
@@ -157,9 +157,11 @@ public sealed partial class PayfastService(IDbContextFactory<MidrandBooksDbConte
|
|||||||
|
|
||||||
string key = kvp.Key;
|
string key = kvp.Key;
|
||||||
|
|
||||||
string encodedVal = Uri.EscapeDataString(kvp.Value.Trim());
|
// 1. Payfast requires spaces to be '+' signs. HttpUtility does this perfectly.
|
||||||
|
string encodedVal = HttpUtility.UrlEncode(kvp.Value.Trim());
|
||||||
|
|
||||||
string val = PercentEncodingRegex.Replace(encodedVal, m => 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}&");
|
pfOutput.Append($"{key}={val}&");
|
||||||
}
|
}
|
||||||
@@ -170,8 +172,9 @@ public sealed partial class PayfastService(IDbContextFactory<MidrandBooksDbConte
|
|||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(passPhrase))
|
if (!string.IsNullOrWhiteSpace(passPhrase))
|
||||||
{
|
{
|
||||||
string encodedPassphrase = Uri.EscapeDataString(passPhrase.Trim());
|
// Apply the exact same encoding rule to your passphrase
|
||||||
string safePassphrase = PercentEncodingRegex.Replace(encodedPassphrase, m => m.Value.ToLowerInvariant());
|
string encodedPassphrase = HttpUtility.UrlEncode(passPhrase.Trim());
|
||||||
|
string safePassphrase = Regex.Replace(encodedPassphrase, "%[0-9A-Fa-f]{2}", m => m.Value.ToUpperInvariant());
|
||||||
|
|
||||||
getString += $"&passphrase={safePassphrase}";
|
getString += $"&passphrase={safePassphrase}";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user