-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Add notification handler (#20)
- Loading branch information
Showing
15 changed files
with
135 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
{ | ||
"axepta-paywall": { | ||
"merchantId": "ir49nkdgnuex458f6wnq", | ||
"authToken": "ttfc9ve4zeseca4egs0pguk15c3yckkwf7d1n1ts8e55y5hs68886ujt76z5glbl", | ||
"merchantId": "5n3bxvzoxife15djkmpa", | ||
"service": { | ||
"id": "bf1efa70-a6d8-4c08-a512-52e8aa025952", | ||
"key": "XrvZlCclg45zOOBtANK5reKo4onNlMrKAwgM" | ||
}, | ||
"authToken": "rc9wg0rosqzfx4dcdh1epzloemn5fhuis62gy37faxhd7iojhhop6eb341jbqfpw", | ||
"sandbox": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
{ | ||
"axepta-paywall": { | ||
"merchantId": "ir49nkdgnuex458f6wnq", | ||
"authToken": "ttfc9ve4zeseca4egs0pguk15c3yckkwf7d1n1ts8e55y5hs68886ujt76z5glbl", | ||
"sandbox": false | ||
"merchantId": "5n3bxvzoxife15djkmpa", | ||
"service": { | ||
"id": "bf1efa70-a6d8-4c08-a512-52e8aa025952", | ||
"key": "XrvZlCclg45zOOBtANK5reKo4onNlMrKAwgM" | ||
}, | ||
"authToken": "rc9wg0rosqzfx4dcdh1epzloemn5fhuis62gy37faxhd7iojhhop6eb341jbqfpw", | ||
"sandbox": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Axepta.SDK.Entities.Response; | ||
|
||
internal sealed record NotificationHeaderDto( | ||
[property: JsonPropertyName("merchantid")] string MerchantId, | ||
[property: JsonPropertyName("serviceid")] string ServiceId, | ||
[property: JsonPropertyName("signature")] string Signature, | ||
[property: JsonPropertyName("alg")] string Algorithm | ||
) | ||
{ | ||
public static NotificationHeaderDto FromString(string input) | ||
{ | ||
var keyValuePairs = input.Split(';') | ||
.Select(part => part.Split('=')) | ||
.ToDictionary(split => split[0], split => split[1]); | ||
|
||
return new NotificationHeaderDto( | ||
keyValuePairs["merchantid"], | ||
keyValuePairs["serviceid"], | ||
keyValuePairs["signature"], | ||
keyValuePairs["alg"] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ public enum PaymentMethodChannel | |
Oneclick, | ||
Recurring, | ||
#endregion | ||
#region Blik | ||
#region blik | ||
Blik | ||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Axepta.SDK.Options; | ||
|
||
internal sealed record ServiceOptions | ||
{ | ||
public required string Id { get; init; } | ||
public required string Key { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Axepta.SDK; | ||
|
||
public interface IAxeptaNotification | ||
{ | ||
Task<bool> HasValidSignature(HttpContext ctx); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Axepta.SDK.Services; | ||
|
||
internal sealed class AxeptaNotification(IOptions<AxeptaPaywallOptions> options) : IAxeptaNotification | ||
Check warning on line 3 in src/Axepta.SDK/Services/AxeptaNotification.cs
|
||
{ | ||
public async Task<bool> HasValidSignature(HttpContext ctx) | ||
{ | ||
var dto = NotificationHeaderDto.FromString(ctx.Request.Headers["X-Axepta-Signature"].ToString()); | ||
|
||
using var reader = new StreamReader(ctx.Request.Body); | ||
|
||
var body = await reader.ReadToEndAsync(); | ||
|
||
reader.Close(); | ||
|
||
return dto.Signature == ComputeSha256Hash(body + "XrvZlCclg45zOOBtANK5reKo4onNlMrKAwgM"); | ||
} | ||
|
||
private string ComputeSha256Hash(string data) | ||
{ | ||
using SHA256 sha256Hash = SHA256.Create(); | ||
var bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(data)); | ||
|
||
var builder = new StringBuilder(); | ||
foreach (var t in bytes) | ||
{ | ||
builder.Append(t.ToString("x2")); | ||
} | ||
return builder.ToString(); | ||
} | ||
} |