The following C# methods may prove useful whilst integrating your site with Paynow.

1. CreateHash

This method will create a hash value sent in any HTTP POST between the merchant site and Paynow.

  • private static string GenerateTwoWayHash(Dictionary items, Guid guid)
    {
         string concat = string.Join("", items.Select(c => (c.Value != null && c.Key.ToLower() != "hash" ? c.Value.Trim() : "")).ToArray());
         SHA512 check = SHA512.Create();
         byte[] resultArr = check.ComputeHash(Encoding.UTF8.GetBytes(concat + guid));
         return ByteArrayToString (resultArr);
    }
    
    public static string ByteArrayToString(byte[] ba)
    {
         StringBuilder hex = new StringBuilder(ba.Length * 2);
         foreach (byte b in ba)
         hex.AppendFormat("{0:x2}", b);
         return hex.ToString().ToUpper();
    }
    

That’s all for C#, catch you later!