Tests and package name updated

This commit is contained in:
Savya Bikram Shah
2026-05-07 17:42:48 +05:45
commit 270d6a69ae
92 changed files with 2169 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
using System.Security.Cryptography;
using System.Text;
internal sealed class HmacSha512Signer
{
private readonly byte[] _keyBytes;
internal HmacSha512Signer(string secretKey)
{
_keyBytes = Encoding.UTF8.GetBytes(secretKey);
}
internal string SignQrRequest(
string amount, string prn, string merchantCode,
string remarks1, string remarks2)
=> Compute($"{amount},{prn},{merchantCode},{remarks1},{remarks2}");
internal string SignQrRequestWithTax(
string amount, string prn, string merchantCode,
string remarks1, string remarks2,
string taxAmount, string taxRefund)
=> Compute($"{amount},{prn},{merchantCode},{remarks1},{remarks2},{taxAmount},{taxRefund}");
internal string SignStatusCheck(string prn, string merchantCode)
=> Compute($"{prn},{merchantCode}");
internal string SignTaxRefund(
string fonepayTraceId, string merchantPrn,
string invoiceNumber, string invoiceDate,
string transactionAmount, string merchantCode)
=> Compute($"{fonepayTraceId},{merchantPrn},{invoiceNumber},{invoiceDate},{transactionAmount},{merchantCode}");
private string Compute(string message)
{
using var hmac = new HMACSHA512(_keyBytes);
byte[] hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(message));
return BytesToHexLower(hash);
}
private static string BytesToHexLower(byte[] bytes)
{
var sb = new StringBuilder(bytes.Length * 2);
foreach (byte b in bytes)
sb.Append(b.ToString("x2"));
return sb.ToString();
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 93fb47df723f74372b0fa6e228e4dd73