Compare commits

...

2 Commits

Author SHA1 Message Date
khwezi ef2428f8e3 Merge pull request 'Refactored GenerateSignature' (#103) from payments into master
Reviewed-on: #103
2026-06-12 23:20:08 +02:00
Khwezi Mngoma 5edff5e272 Refactored GenerateSignature
continuous-integration/drone/pr Build is passing
2026-06-12 23:19:40 +02:00
2 changed files with 9 additions and 15 deletions
@@ -11,20 +11,12 @@ public class CustomerServiceFeatureTests(Fixture fixture) : IClassFixture<Fixtur
[IntegrationFact] [IntegrationFact]
public async Task CreateCustomerAsync_ShouldReturn_ResultWithCustomerId() 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 var request = new CreateCustomer
{ {
//Company = "Book Lovers", Company = "Book Lovers",
Email = "hank@booklovers.com", Email = "hank@booklovers.com",
//Phone = "555 1245 8577", Phone = "555 1245 8577",
//Website = "https://www.booklovers.com" Website = "https://www.booklovers.com"
}; };
var result = await customerService.CreateCustomerAsync(request, fixture.CancellationToken); var result = await customerService.CreateCustomerAsync(request, fixture.CancellationToken);
@@ -152,9 +152,12 @@ public sealed partial class PayfastService(IDbContextFactory<MidrandBooksDbConte
if (string.IsNullOrEmpty(kvp.Value)) if (string.IsNullOrEmpty(kvp.Value))
continue; continue;
if (kvp.Key.Equals("signature", StringComparison.OrdinalIgnoreCase))
continue;
string key = kvp.Key; string key = kvp.Key;
string encodedVal = HttpUtility.UrlEncode(kvp.Value.Trim()); string encodedVal = Uri.EscapeDataString(kvp.Value.Trim());
string val = PercentEncodingRegex.Replace(encodedVal, m => m.Value.ToLowerInvariant()); string val = PercentEncodingRegex.Replace(encodedVal, m => m.Value.ToLowerInvariant());
@@ -167,13 +170,12 @@ public sealed partial class PayfastService(IDbContextFactory<MidrandBooksDbConte
if (!string.IsNullOrWhiteSpace(passPhrase)) if (!string.IsNullOrWhiteSpace(passPhrase))
{ {
string encodedPassphrase = HttpUtility.UrlEncode(passPhrase.Trim()); string encodedPassphrase = Uri.EscapeDataString(passPhrase.Trim());
string safePassphrase = PercentEncodingRegex.Replace(encodedPassphrase, m => m.Value.ToLowerInvariant()); string safePassphrase = PercentEncodingRegex.Replace(encodedPassphrase, m => m.Value.ToLowerInvariant());
getString += $"&passphrase={safePassphrase}"; getString += $"&passphrase={safePassphrase}";
} }
return HashService.ToMd5Hash(getString); return HashService.ToMd5Hash(getString);
} }
} }