When my transactionRequest.amount equal a 100.00 I can't match in X-Anet-Signature , if it is 100.11, or other amount with two decimal points can match X-Anet-Signature:like 155.94 ,it is ok
This is my C# Get HPP Code:
var transactionRequest = new transactionRequestType
{
transactionType = !ispreauth ? transactionTypeEnum.authCaptureTransaction.ToString() : transactionTypeEnum.authOnlyTransaction.ToString(), // authorize capture only
amount = amount,
profile = new customerProfilePaymentType()
{
customerProfileId = myprofileid,
},
order = new orderType()
{
invoiceNumber = formid,
description = ""
},
};
var request = new getHostedPaymentPageRequest();
request.transactionRequest = transactionRequest;
request.hostedPaymentSettings = settingslist.ToArray();
request.merchantAuthentication = merchantAuthentication;
// instantiate the controller that will call the service
var controller = new getHostedPaymentPageController(request);
controller.Execute(runEnvironment);
This is my webhook CheckToken Code:
public static bool CheckTokens(string signatureKey, string jsonRawBody, string AnetSignature)
{
if (String.IsNullOrEmpty(jsonRawBody)) return false;
if (String.IsNullOrEmpty(AnetSignature)) return false;
if (String.IsNullOrEmpty(signatureKey)) return false;
// generate the shaw token
var token = GetSHAToken(jsonRawBody, signatureKey);
if (String.IsNullOrEmpty(token)) return false;
return AnetSignature.Equals(token, StringComparison.OrdinalIgnoreCase);
}
static private string GetSHAToken(string data, string key)
{
// use Encoding.ASCII.GetBytes or Encoding.UTF8.GetBytes
byte[] keyBytes = Encoding.ASCII.GetBytes(key);
byte[] bodyBytes = Encoding.ASCII.GetBytes(data);
using (var hmac = new HMACSHA512(keyBytes))
{
byte[] hashBytes = hmac.ComputeHash(bodyBytes);
string computedSignature = BitConverter.ToString(hashBytes).Replace("-", "");
return computedSignature;
}
}
Success response:
X-Anet-Signature:
sha512=8B681B20F71C03A1EF29AD143FA69208DE30AE3B3479B1DA3B145574792AC8B1BDC65CBA8AE4BB33A43D153346DB8BE59C328CCF0219C90E202AB2CB7114356C
Body:
Error Reponse:
X-Anet-Signature:sha512=D636BEE76B7FB85079E95347000C8689C44026745A9123A588768273CD4FE43228ED472A34AFFCD30FA743793A30FA479C536CEC51FBADF46D2E85B3BE614FF1
Body:
I promise to use the same signatureKey,I don't quite understand if I set amount to 100.00, but the webhook returns 100.0 to me has anything to do with it,I've also tried replacing C# requests with HTTP POST methods and I tried to set amount to 100 or 100.0 or 100.00 , But it never matched.
04-24-2023 01:01 PM - edited 04-24-2023 01:14 PM