Hello,
I am using Authorized.net with c#. I have getting some problem at the time of transaction. Transaction received hash and generated received hash not matching. Can any one help me regarding this where I am wrong? Thanks in advance.
My code is given below:
Received hash:
string key =Convert.ToString("abc123456");
string value = Convert.ToString(loginID + "^" + seq + "^" + timeStamp + "^" + amount + "^");
string fingerprint = HMACSHA512(key, value);
public string HMACSHA512(string key, string textToHash)
{
if (string.IsNullOrEmpty(key))
throw new ArgumentNullException("HMACSHA512: key", "Parameter cannot be empty.");
if (string.IsNullOrEmpty(textToHash))
throw new ArgumentNullException("HMACSHA512: textToHash", "Parameter cannot be empty.");
if (key.Length % 2 != 0 || key.Trim().Length < 2)
{
throw new ArgumentNullException("HMACSHA512: key", "Parameter cannot be odd or less than 2 characters.");
}
try
{
byte[] k = Enumerable.Range(0, key.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(key.Substring(x, 2), 16))
.ToArray();
HMACSHA512 hmac = new HMACSHA512(k);
byte[] HashedValue = hmac.ComputeHash((new System.Text.ASCIIEncoding()).GetBytes(textToHash));
return BitConverter.ToString(HashedValue).Replace("-", string.Empty);
}
catch (Exception ex)
{
throw new Exception("HMACSHA512: " + ex.Message);
}
}
Received hash is given below: "9037CD31FADCCAD8EDFBAF97E27D58EA354FF3FB29060E09BC7C2BF7BD29F2F7D1E5F3CA96EEC2BB27B8BBA7677970851A0E65867E04BE812EC437A631E6122F"
Now the generated hash value process is given below:
string key = Convert.ToString("abc123456");
string str_generated_hash = HMACSHA512(key, "^" + x_login + "^" + x_trans_id + "^" + x_amount + "^");
I am using same function HMACSHA512 as given above. The generated hash value is "BF904ED074B81754725D1E7E547EBFC5B89EE6A6DEE1A08B79C536E1652D617D8644C7948B269A8C542D5D6783EF748A9000D51DE4BD94CFDF30CA85C4EE8B4B" which is different from received hash value.
04-15-2019 04:26 AM
I'm having the same issue. Using the given function to generate the hash, the received hash and the generated hash are not the same. The issue I'm having is that I don't know the format of the amount that is supposed to be in the message string that is being hashed. The Transaction Hash Upgrade Guide gives this example:
For example, if your API Login ID is "ANet123", the value of transId is "20987654321", and the value of amount is "9.99", the message string would look like this:
^ANet123^20987654321^9.99^
So it seems like the format of the amount should be XXXX.XX, but it could also be X,XXX.XX. I have tried both formats and neither work for me. The documentation also says:
The transaction amount that we send in createTransactionResponse in the amount element.
The other problem here is that I'm not getting an amount back in the createTransactionResponse, so that doesn't help.
I've submitted a support ticket with Authorize.net, but never heard back (submitted it Friday 4/26 and haven't heard back on Thurs. 5/2).
Any help would be appreciated.
John
05-02-2019 10:15 AM
05-02-2019 12:54 PM
05-02-2019 12:55 PM
Thanks for the reply. Glad to know the actual format, though I tried the format you mention (actually tried 12 different formats) but it still didn't work.
I'm not actually sure what you mean by legacy methods. I'm posting XML to the Sandbox with https://apitest.authorize.net/xml/v1/request.api and using createTransactionRequest in the format from the API documentation.
05-03-2019 09:32 AM
05-03-2019 10:06 AM