Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 95dc2e2da2 | |||
| 59fc0432b4 | |||
| 99c0508f6f | |||
| b984dab2be | |||
| 157f097dfb | |||
| 630e74814b | |||
| 6248d03ead | |||
| 9b474a398b | |||
| 3deae15f5a | |||
| 8e1df7938b | |||
| d9f2d32c76 | |||
| 9296f0331e | |||
| 1ace61baa5 | |||
| e3e49b8db2 | |||
| 2ed15b548f | |||
| 7d2bc7f1f2 | |||
| ef2428f8e3 | |||
| 5edff5e272 |
@@ -11,20 +11,12 @@ public class CustomerServiceFeatureTests(Fixture fixture) : IClassFixture<Fixtur
|
||||
[IntegrationFact]
|
||||
public async Task CreateCustomerAsync_ShouldReturn_ResultWithCustomerId()
|
||||
{
|
||||
//var request = new CreateCustomer
|
||||
//{
|
||||
// Company = "Book Lovers",
|
||||
// Email = "hank@booklovers.com",
|
||||
// Phone = "555 1245 8577",
|
||||
// Website = "https://www.booklovers.com"
|
||||
//};
|
||||
|
||||
var request = new CreateCustomer
|
||||
{
|
||||
//Company = "Book Lovers",
|
||||
Company = "Book Lovers",
|
||||
Email = "hank@booklovers.com",
|
||||
//Phone = "555 1245 8577",
|
||||
//Website = "https://www.booklovers.com"
|
||||
Phone = "555 1245 8577",
|
||||
Website = "https://www.booklovers.com"
|
||||
};
|
||||
|
||||
var result = await customerService.CreateCustomerAsync(request, fixture.CancellationToken);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using LiteCharms.Features.Abstractions;
|
||||
using LiteCharms.Features.Browser;
|
||||
using LiteCharms.Features.MidrandBooks.Abstractions;
|
||||
|
||||
namespace LiteCharms.Features.MidrandBooks.Extensions;
|
||||
|
||||
public static class Shop
|
||||
{
|
||||
public static IServiceCollection AddShopServices(this IServiceCollection services)
|
||||
public static IServiceCollection AddShopServices(this IServiceCollection services, bool includeLocalStorage = false)
|
||||
{
|
||||
var serviceType = typeof(IService);
|
||||
|
||||
@@ -19,6 +20,9 @@ public static class Shop
|
||||
|
||||
foreach (var coreImplementation in coreImplementations) services.AddScoped(coreImplementation);
|
||||
|
||||
if (includeLocalStorage)
|
||||
services.AddScoped<LocalStorageService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,6 +148,7 @@
|
||||
|
||||
<!-- Shared Usings -->
|
||||
<ItemGroup>
|
||||
<Using Include="Microsoft.AspNetCore.Http" />
|
||||
<Using Include="System.Net.Sockets" />
|
||||
<Using Include="System.Text.RegularExpressions" />
|
||||
<Using Include="System.Web" />
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using LiteCharms.Features.Abstractions;
|
||||
using LiteCharms.Features.Browser;
|
||||
using LiteCharms.Features.Browser;
|
||||
using LiteCharms.Features.Hasher;
|
||||
using LiteCharms.Features.MidrandBooks.Authors.Models;
|
||||
using LiteCharms.Features.MidrandBooks.Payments.Models;
|
||||
@@ -7,7 +6,7 @@ using LiteCharms.Features.MidrandBooks.Products.Models;
|
||||
|
||||
namespace LiteCharms.Features.MidrandBooks.Payments;
|
||||
|
||||
public sealed class CartService(LocalStorageService localStorage) : IService
|
||||
public sealed class CartService(LocalStorageService localStorage)
|
||||
{
|
||||
private readonly string CartStorageKey = HashService.ToMd5Hash(nameof(Cart)).Value;
|
||||
|
||||
|
||||
@@ -48,6 +48,41 @@ public sealed partial class PayfastService(IDbContextFactory<MidrandBooksDbConte
|
||||
}
|
||||
}
|
||||
|
||||
public static bool VerifyIncomingSignature(HttpRequest request, string passphrase)
|
||||
{
|
||||
var formFields = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
|
||||
foreach (var file in request.Form)
|
||||
formFields.Add(file.Key, file.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 rawValue = formFields[key] ?? string.Empty;
|
||||
|
||||
string encodedVal = HttpUtility.UrlEncode(rawValue.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)
|
||||
{
|
||||
if(payfastOptions.Value?.ValidHosts?.Length == 0)
|
||||
@@ -147,33 +182,66 @@ public sealed partial class PayfastService(IDbContextFactory<MidrandBooksDbConte
|
||||
{
|
||||
var pfOutput = new StringBuilder();
|
||||
|
||||
foreach (var kvp in data)
|
||||
var mandatorySequence = GetPayfastMandatoryFieldSequence();
|
||||
|
||||
foreach (string key in mandatorySequence)
|
||||
{
|
||||
if (string.IsNullOrEmpty(kvp.Value))
|
||||
continue;
|
||||
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());
|
||||
|
||||
string key = kvp.Key;
|
||||
|
||||
string encodedVal = HttpUtility.UrlEncode(kvp.Value.Trim());
|
||||
|
||||
string val = PercentEncodingRegex.Replace(encodedVal, m => m.Value.ToLowerInvariant());
|
||||
|
||||
pfOutput.Append($"{key}={val}&");
|
||||
pfOutput.Append($"{key}={val}&");
|
||||
}
|
||||
}
|
||||
|
||||
string getString = pfOutput.Length > 0
|
||||
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.ToLowerInvariant());
|
||||
string safePassphrase = PercentEncodingRegex.Replace(encodedPassphrase, m => m.Value.ToUpperInvariant());
|
||||
|
||||
getString += $"&passphrase={safePassphrase}";
|
||||
}
|
||||
|
||||
return HashService.ToMd5Hash(getString);
|
||||
}
|
||||
}
|
||||
|
||||
private static string[] GetPayfastMandatoryFieldSequence() =>
|
||||
[
|
||||
"merchant_id",
|
||||
"merchant_key",
|
||||
"return_url",
|
||||
"cancel_url",
|
||||
"notify_url",
|
||||
"name_first",
|
||||
"name_last",
|
||||
"email_address",
|
||||
"cell_number",
|
||||
"m_payment_id",
|
||||
"amount",
|
||||
"item_name",
|
||||
"item_description",
|
||||
"custom_int1",
|
||||
"custom_int2",
|
||||
"custom_int3",
|
||||
"custom_int4",
|
||||
"custom_int5",
|
||||
"custom_str1",
|
||||
"custom_str2",
|
||||
"custom_str3",
|
||||
"custom_str4",
|
||||
"custom_str5",
|
||||
"email_confirmation",
|
||||
"confirmation_address",
|
||||
"payment_method",
|
||||
"subscription_type",
|
||||
"billing_date",
|
||||
"recurring_amount",
|
||||
"frequency",
|
||||
"cycles"
|
||||
];
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
"ValidHosts": [
|
||||
"www.payfast.co.za",
|
||||
"sandbox.payfast.co.za",
|
||||
"w1w.payfast.co.za",
|
||||
"w2w.payfast.co.za",
|
||||
"ips.payfast.co.za",
|
||||
"api.payfast.co.za",
|
||||
"payment.payfast.io"
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using LiteCharms.Features.Abstractions;
|
||||
using LiteCharms.Features.Api.Configuration;
|
||||
using LiteCharms.Features.Api.Configuration;
|
||||
using LiteCharms.Features.Api.Models;
|
||||
using LiteCharms.Features.Api.Sdk;
|
||||
|
||||
namespace LiteCharms.Features.Api;
|
||||
|
||||
public sealed class TokenService(IConnectApi connectApi, IOptions<LiteCharmsClientSettings> clientOptions) : IService
|
||||
public sealed class TokenService(IConnectApi connectApi, IOptions<LiteCharmsClientSettings> clientOptions)
|
||||
{
|
||||
private readonly LiteCharmsClientSettings clientSettings = clientOptions.Value;
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using LiteCharms.Features.Abstractions;
|
||||
namespace LiteCharms.Features.Browser;
|
||||
|
||||
namespace LiteCharms.Features.Browser;
|
||||
|
||||
public sealed class LocalStorageService(ProtectedLocalStorage storage) : IService
|
||||
public sealed class LocalStorageService(ProtectedLocalStorage storage)
|
||||
{
|
||||
public async ValueTask<Result> DeleteAsync(string key)
|
||||
{
|
||||
|
||||
@@ -46,6 +46,8 @@ public static class Api
|
||||
options.Retry.BackoffType = Polly.DelayBackoffType.Exponential;
|
||||
});
|
||||
|
||||
services.AddScoped<TokenService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user