3

I need to update the Expiry Date and update the Cardholder Name on an existing card in Realex payments.

The hash value syntax should be in the following format:

Timestamp.merchantID.payerref.ref.expirydate.cardnumber

And here is an example of how it should look

20030516175919.yourmerchantid.mypayer.card01.1015.

When I run the following method I get the error:

"sha1hash incorrect - check your code and the Developers Documentation"

private string ReturnHash(string timeStamp, string merchantId, string payerRef, string reference, string expDate, string cardNum )
{
    SHA1 hash = new SHA1Managed();
    StringBuilder builder = new StringBuilder();

    builder.Append(timeStamp).Append(".");
    builder.Append(merchantId).Append(".");
    builder.Append(payerRef).Append(".");
    builder.Append(reference).Append(".");
    builder.Append(expDate).Append(".");
    builder.Append(cardNum );

    string resultingHash = BitConverter.ToString(hash.ComputeHash(Encoding.UTF8.GetBytes(builder.ToString())));
    resultingHash = BitConverter.ToString(hash.ComputeHash(Encoding.UTF8.GetBytes(resultingHash)));

    return resultingHash;
}

What am I doing wrong?

Master Yoda
  • 4,334
  • 10
  • 43
  • 77
  • What product are you using? I know that with Realex RealAuth the hash has to be in lower case (see page 16). Your code doesn't seem to be doing this. https://resourcecentre.realexpayments.com/documents/pdf.html?id=137 – Damien Dennehy Feb 18 '16 at 12:53
  • @DamienDennehy Its realvault. Is that the same thing? Im quite new to the whole payments thing. – Master Yoda Feb 18 '16 at 13:13
  • 2
    Separate product, but there's documentation on it. https://resourcecentre.realexpayments.com/documents/pdf.html?id=152 There is a sample SHA1 hash on page 18 and 19 that you should try and replicate with your code. If it doesn't match Realex's sample value then your method might be doing something incorrect. – Damien Dennehy Feb 18 '16 at 14:01
  • @DamienDennehy Excellent, thank you for the documentation. One step further – Master Yoda Feb 18 '16 at 14:02

2 Answers2

0

Thank you for your message.

Could you try before running this line of code:

string resultingHash = BitConverter.ToString(hash.ComputeHash(Encoding.UTF8.GetBytes(builder.ToString())));

To make "resultingHash" all lowercase?

Also before running:

resultingHash = BitConverter.ToString(hash.ComputeHash(Encoding.UTF8.GetBytes(resultingHash)));

make "resultingHash" to lowercase as well.

Thanks, Borja

Borja
  • 1
  • 1
0
 var timeStamp = RealexDateFormatter.DateFormatForRealex();

 var orderid = model.ORDER_ID;
 var secret = ConfigurationManager.AppSettings["Appsecretkey"];
 var merchantId = ConfigurationManager.AppSettings["AppMerchantId"];

 var temp1 = FormsAuthentication.HashPasswordForStoringInConfigFile(
 timeStamp + "." +
 merchantId + "." +
 orderid + "." +
 model.AMOUNT + "." + "EUR", "sha1");
 temp1 = temp1.ToLower();
 var temp2 = temp1 + "." + secret;
 var sha1hash = FormsAuthentication.HashPasswordForStoringInConfigFile(temp2, "sha1");
 sha1hash = sha1hash.ToLower();`enter code here`
 var url = "https://hpp.sandbox.realexpayments.com/pay?MERCHANT_ID="
                + ConfigurationManager.AppSettings["AppMerchantId"] +
                "&ORDER_ID=" + orderid + "&CURRENCY=EUR" + "&AMOUNT=" + model.AMOUNT + "&TIMESTAMP=" + timeStamp + "&SHA1HASH=" + sha1hash + "&MERCHANT_RESPONSE_URL=http://deposit.projectstatus.in/Payment/Response";