From 630e74814b0664c0a5f21fb0eacb6c09ee4bddce Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Sat, 13 Jun 2026 10:45:31 +0200 Subject: [PATCH] Catering for service registration of non-UI apps --- .../Extensions/Shop.cs | 6 +- .../Payments/PayfastService.cs | 62 +++++++++---------- LiteCharms.Features/Api/TokenService.cs | 5 +- LiteCharms.Features/Extensions/Api.cs | 2 + 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/LiteCharms.Features.MidrandBooks/Extensions/Shop.cs b/LiteCharms.Features.MidrandBooks/Extensions/Shop.cs index 254f236..892c282 100644 --- a/LiteCharms.Features.MidrandBooks/Extensions/Shop.cs +++ b/LiteCharms.Features.MidrandBooks/Extensions/Shop.cs @@ -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(); + return services; } } diff --git a/LiteCharms.Features.MidrandBooks/Payments/PayfastService.cs b/LiteCharms.Features.MidrandBooks/Payments/PayfastService.cs index 8d440d8..5cb585c 100644 --- a/LiteCharms.Features.MidrandBooks/Payments/PayfastService.cs +++ b/LiteCharms.Features.MidrandBooks/Payments/PayfastService.cs @@ -147,8 +147,35 @@ public sealed partial class PayfastService(IDbContextFactory 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_key", @@ -182,35 +209,4 @@ public sealed partial class PayfastService(IDbContextFactory 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); - } } diff --git a/LiteCharms.Features/Api/TokenService.cs b/LiteCharms.Features/Api/TokenService.cs index c2dcdfc..a1872c5 100644 --- a/LiteCharms.Features/Api/TokenService.cs +++ b/LiteCharms.Features/Api/TokenService.cs @@ -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 clientOptions) : IService +public sealed class TokenService(IConnectApi connectApi, IOptions clientOptions) { private readonly LiteCharmsClientSettings clientSettings = clientOptions.Value; diff --git a/LiteCharms.Features/Extensions/Api.cs b/LiteCharms.Features/Extensions/Api.cs index f6857bb..ae57c25 100644 --- a/LiteCharms.Features/Extensions/Api.cs +++ b/LiteCharms.Features/Extensions/Api.cs @@ -46,6 +46,8 @@ public static class Api options.Retry.BackoffType = Polly.DelayBackoffType.Exponential; }); + services.AddScoped(); + return services; }