Compare commits
108
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6248d03ead | ||
|
|
3deae15f5a | ||
|
|
d9f2d32c76 | ||
|
|
1ace61baa5 | ||
|
|
2ed15b548f | ||
|
|
ef2428f8e3 | ||
|
|
b424b24c2e | ||
|
|
cadc5888cc | ||
|
|
92abf6c5be | ||
|
|
37e0d3b93f | ||
|
|
b42c0fcc4f | ||
|
|
9418c77f0e | ||
|
|
2bb1c8c3bc | ||
|
|
388a5f4c87 | ||
|
|
c31dd308a4 | ||
|
|
787507bed9 | ||
|
|
5140da2c6c | ||
|
|
0ad410c64e | ||
|
|
6e580ecdf6 | ||
|
|
4c194c1141 | ||
|
|
41eb4daeb4 | ||
|
|
7fe5f7aef3 | ||
|
|
31254932ae | ||
|
|
5a0aae8182 | ||
|
|
8d8ebffabf | ||
|
|
e2d29261da | ||
|
|
f001b02633 | ||
|
|
de955a96a8 | ||
|
|
c4d3bb4cdf | ||
|
|
cdc80db214 | ||
|
|
3847927ace | ||
|
|
c27aba1954 | ||
|
|
1c946dab26 | ||
|
|
9977cf27b9 | ||
|
|
8e9ac1e1ad | ||
|
|
16dae7c9fb | ||
|
|
f8153e86b4 | ||
|
|
84d33d3607 | ||
|
|
f51cc03327 | ||
|
|
aff6fcabf4 | ||
|
|
8140b5fe65 | ||
|
|
9285cedfa9 | ||
|
|
343874551a | ||
|
|
0eac9d533f | ||
|
|
24ba609e0c | ||
|
|
29f6d66c44 | ||
|
|
bcfc9ef962 | ||
|
|
b4e967acc9 | ||
|
|
205bbb9f3f | ||
|
|
73ef4b04a9 | ||
|
|
780415b6d4 | ||
|
|
879094073a | ||
|
|
b369dad452 | ||
|
|
c938bfec09 | ||
|
|
adc14038db | ||
|
|
61cb6c2228 | ||
|
|
e7a798b5e9 | ||
|
|
41b6b71b31 | ||
|
|
ee6beef603 | ||
|
|
1c3f3eaf0d | ||
|
|
2e77666d9e | ||
|
|
1977b6b301 | ||
|
|
0ab14d8b63 | ||
|
|
466458e230 | ||
|
|
141d32f591 | ||
|
|
d9e7f225ae | ||
|
|
6ae63e2ad1 | ||
|
|
f5efdde37c | ||
|
|
1592d5dc8f | ||
|
|
50a8a59d92 | ||
|
|
b70d9559b0 | ||
|
|
81d5e8f07c | ||
|
|
20a53942b5 | ||
|
|
9edb2aa4aa | ||
|
|
6ed023f2cf | ||
|
|
2c9f5a846c | ||
|
|
41f7c05be3 | ||
|
|
1a03355e84 | ||
|
|
7743c3178e | ||
|
|
ab3d8e6e9a | ||
|
|
db4c348288 | ||
|
|
6683234642 | ||
|
|
6ddbb9479a | ||
|
|
6c7349a0f8 | ||
|
|
e97fd6cd3f | ||
|
|
184c7c252a | ||
|
|
bfe8c458d6 | ||
|
|
e6e0475db1 | ||
|
|
5090c60797 | ||
|
|
9432252e15 | ||
|
|
47111a1a3a | ||
|
|
6eb3d50375 | ||
|
|
4deb732804 | ||
|
|
20d9387d0b | ||
|
|
9f6d0ccaa0 | ||
|
|
1acbc4d213 | ||
|
|
8c99668fac | ||
|
|
ad44f46204 | ||
|
|
49d999c1e3 | ||
|
|
9ed4777a18 | ||
|
|
0cf44f68cc | ||
|
|
41ed5a4288 | ||
|
|
bbcba5e06c | ||
|
|
502cc326dd | ||
|
|
4675d4c5fc | ||
|
|
f80bb2fff9 | ||
|
|
6767906b0d | ||
|
|
a344af4498 |
@@ -1,12 +1,11 @@
|
|||||||
using LiteCharms.Features.Abstractions;
|
using LiteCharms.Features.Abstractions;
|
||||||
using LiteCharms.Features.Browser;
|
|
||||||
using LiteCharms.Features.MidrandBooks.Abstractions;
|
using LiteCharms.Features.MidrandBooks.Abstractions;
|
||||||
|
|
||||||
namespace LiteCharms.Features.MidrandBooks.Extensions;
|
namespace LiteCharms.Features.MidrandBooks.Extensions;
|
||||||
|
|
||||||
public static class Shop
|
public static class Shop
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddShopServices(this IServiceCollection services, bool includeLocalStorage = false)
|
public static IServiceCollection AddShopServices(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
var serviceType = typeof(IService);
|
var serviceType = typeof(IService);
|
||||||
|
|
||||||
@@ -20,9 +19,6 @@ public static class Shop
|
|||||||
|
|
||||||
foreach (var coreImplementation in coreImplementations) services.AddScoped(coreImplementation);
|
foreach (var coreImplementation in coreImplementations) services.AddScoped(coreImplementation);
|
||||||
|
|
||||||
if (includeLocalStorage)
|
|
||||||
services.AddScoped<LocalStorageService>();
|
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,7 +148,6 @@
|
|||||||
|
|
||||||
<!-- Shared Usings -->
|
<!-- Shared Usings -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Using Include="Microsoft.AspNetCore.Http" />
|
|
||||||
<Using Include="System.Net.Sockets" />
|
<Using Include="System.Net.Sockets" />
|
||||||
<Using Include="System.Text.RegularExpressions" />
|
<Using Include="System.Text.RegularExpressions" />
|
||||||
<Using Include="System.Web" />
|
<Using Include="System.Web" />
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using LiteCharms.Features.Api.Configuration;
|
|||||||
using LiteCharms.Features.Hasher;
|
using LiteCharms.Features.Hasher;
|
||||||
using LiteCharms.Features.MidrandBooks.Payments.Models;
|
using LiteCharms.Features.MidrandBooks.Payments.Models;
|
||||||
using LiteCharms.Features.MidrandBooks.Postgres;
|
using LiteCharms.Features.MidrandBooks.Postgres;
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
|
|
||||||
namespace LiteCharms.Features.MidrandBooks.Payments;
|
namespace LiteCharms.Features.MidrandBooks.Payments;
|
||||||
|
|
||||||
@@ -49,35 +48,6 @@ public sealed partial class PayfastService(IDbContextFactory<MidrandBooksDbConte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool VerifyIncomingSignature(HttpRequest request, string passphrase)
|
|
||||||
{
|
|
||||||
var formFields = request.Form.ToDictionary(x => x.Key, x => x.Value.ToString());
|
|
||||||
|
|
||||||
if (!formFields.TryGetValue("signature", out string? incomingSignature))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
|
|
||||||
foreach (var key in formFields.Keys)
|
|
||||||
{
|
|
||||||
if (key.Equals("signature", StringComparison.OrdinalIgnoreCase))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
string encodedVal = HttpUtility.UrlEncode(formFields[key].Trim());
|
|
||||||
string cleanVal = PercentEncodingRegex.Replace(encodedVal, m => m.Value.ToUpperInvariant());
|
|
||||||
|
|
||||||
stringBuilder.Append($"{key}={cleanVal}&");
|
|
||||||
}
|
|
||||||
|
|
||||||
string encodedPassphrase = HttpUtility.UrlEncode(passphrase.Trim());
|
|
||||||
string safePassphrase = PercentEncodingRegex.Replace(encodedPassphrase, m => m.Value.ToUpperInvariant());
|
|
||||||
|
|
||||||
stringBuilder.Append($"passphrase={safePassphrase}");
|
|
||||||
|
|
||||||
string generatedSignature = HashService.ToMd5Hash(stringBuilder.ToString()).Value;
|
|
||||||
return incomingSignature.Equals(generatedSignature, StringComparison.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask<Result<bool>> ValidateReferrerIpAsync(string remoteIpAddress, bool allowLoopback = false, CancellationToken cancellationToken = default)
|
public async ValueTask<Result<bool>> ValidateReferrerIpAsync(string remoteIpAddress, bool allowLoopback = false, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if(payfastOptions.Value?.ValidHosts?.Length == 0)
|
if(payfastOptions.Value?.ValidHosts?.Length == 0)
|
||||||
@@ -177,35 +147,8 @@ public sealed partial class PayfastService(IDbContextFactory<MidrandBooksDbConte
|
|||||||
{
|
{
|
||||||
var pfOutput = new StringBuilder();
|
var pfOutput = new StringBuilder();
|
||||||
|
|
||||||
var mandatorySequence = GetPayfastMandatoryFieldSequence();
|
// Define the exact structural sequence mandated by Payfast's documentation
|
||||||
|
string[] mandatorySequence =
|
||||||
foreach (string key in mandatorySequence)
|
|
||||||
{
|
|
||||||
if (data.TryGetValue(key, out string? rawValue) && !string.IsNullOrEmpty(rawValue))
|
|
||||||
{
|
|
||||||
string encodedVal = HttpUtility.UrlEncode(rawValue.Trim());
|
|
||||||
string val = PercentEncodingRegex.Replace(encodedVal, m => m.Value.ToUpperInvariant());
|
|
||||||
|
|
||||||
pfOutput.Append($"{key}={val}&");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var getString = pfOutput.Length > 0
|
|
||||||
? pfOutput.ToString()[..^1]
|
|
||||||
: string.Empty;
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(passPhrase))
|
|
||||||
{
|
|
||||||
string encodedPassphrase = HttpUtility.UrlEncode(passPhrase.Trim());
|
|
||||||
string safePassphrase = PercentEncodingRegex.Replace(encodedPassphrase, m => m.Value.ToUpperInvariant());
|
|
||||||
|
|
||||||
getString += $"&passphrase={safePassphrase}";
|
|
||||||
}
|
|
||||||
|
|
||||||
return HashService.ToMd5Hash(getString);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string[] GetPayfastMandatoryFieldSequence() =>
|
|
||||||
[
|
[
|
||||||
"merchant_id",
|
"merchant_id",
|
||||||
"merchant_key",
|
"merchant_key",
|
||||||
@@ -239,4 +182,35 @@ public sealed partial class PayfastService(IDbContextFactory<MidrandBooksDbConte
|
|||||||
"frequency",
|
"frequency",
|
||||||
"cycles"
|
"cycles"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// 1. Iterate explicitly by the mandatory positional array sequence instead of the dictionary's internal order
|
||||||
|
foreach (string key in mandatorySequence)
|
||||||
|
{
|
||||||
|
// Only append if the key exists in your source dictionary and contains data
|
||||||
|
if (data.TryGetValue(key, out string? rawValue) && !string.IsNullOrEmpty(rawValue))
|
||||||
|
{
|
||||||
|
// Payfast requires spaces to be '+' signs. HttpUtility does this natively.
|
||||||
|
string encodedVal = HttpUtility.UrlEncode(rawValue.Trim());
|
||||||
|
|
||||||
|
// 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}&");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string getString = pfOutput.Length > 0
|
||||||
|
? pfOutput.ToString()[..^1]
|
||||||
|
: string.Empty;
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(passPhrase))
|
||||||
|
{
|
||||||
|
string encodedPassphrase = HttpUtility.UrlEncode(passPhrase.Trim());
|
||||||
|
string safePassphrase = Regex.Replace(encodedPassphrase, "%[0-9A-Fa-f]{2}", m => m.Value.ToUpperInvariant());
|
||||||
|
|
||||||
|
getString += $"&passphrase={safePassphrase}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return HashService.ToMd5Hash(getString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
"ValidHosts": [
|
"ValidHosts": [
|
||||||
"www.payfast.co.za",
|
"www.payfast.co.za",
|
||||||
"sandbox.payfast.co.za",
|
"sandbox.payfast.co.za",
|
||||||
|
"w1w.payfast.co.za",
|
||||||
|
"w2w.payfast.co.za",
|
||||||
"ips.payfast.co.za",
|
"ips.payfast.co.za",
|
||||||
"api.payfast.co.za",
|
"api.payfast.co.za",
|
||||||
"payment.payfast.io"
|
"payment.payfast.io"
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
using LiteCharms.Features.Api.Configuration;
|
using LiteCharms.Features.Abstractions;
|
||||||
|
using LiteCharms.Features.Api.Configuration;
|
||||||
using LiteCharms.Features.Api.Models;
|
using LiteCharms.Features.Api.Models;
|
||||||
using LiteCharms.Features.Api.Sdk;
|
using LiteCharms.Features.Api.Sdk;
|
||||||
|
|
||||||
namespace LiteCharms.Features.Api;
|
namespace LiteCharms.Features.Api;
|
||||||
|
|
||||||
public sealed class TokenService(IConnectApi connectApi, IOptions<LiteCharmsClientSettings> clientOptions)
|
public sealed class TokenService(IConnectApi connectApi, IOptions<LiteCharmsClientSettings> clientOptions) : IService
|
||||||
{
|
{
|
||||||
private readonly LiteCharmsClientSettings clientSettings = clientOptions.Value;
|
private readonly LiteCharmsClientSettings clientSettings = clientOptions.Value;
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ public static class Api
|
|||||||
options.Retry.BackoffType = Polly.DelayBackoffType.Exponential;
|
options.Retry.BackoffType = Polly.DelayBackoffType.Exponential;
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddScoped<TokenService>();
|
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user