Anay Shukla

Anay Shukla

  • NA
  • 24
  • 6.2k

Transaction failed due to incorrectly calculated hash parame

Jun 6 2019 1:11 PM
I tried below code but got error in redirection of payumoney page kindly check , my hash value is not generated properly.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Security.Cryptography;  
  5. using System.Text;  
  6. using System.Web;  
  7. using System.Web.UI;  
  8. using System.Web.UI.WebControls;  
  9. public partial class BuyNow : System.Web.UI.Page  
  10. {  
  11. protected void Page_Load(object sender, EventArgs e)  
  12. {  
  13. if (!IsPostBack)  
  14. {  
  15. Label1.Text = Request.QueryString["Price"].ToString();  
  16. Random random = new Random();  
  17. txnid.Value = (Convert.ToString(random.Next(10000, 20000)));  
  18. txnid.Value = "AVJFINANCE" + txnid.Value.ToString();  
  19. Response.Write(txnid.Value.ToString());  
  20. }  
  21. }  
  22. protected void Button1_Click(object sender, EventArgs e)  
  23. {  
  24. Double amount = Convert.ToDouble(Label1.Text);  
  25. // String text = Key.Value.ToString() + "|" + txnid.Value.ToString() +"|" + amount + "|" + "Wear" + "|" + TextBox1.Text + "|" + TextBox2.Text + "|" + "1" + "|" + "1" + "|" + "1" + "|" + "1" + "|" + "1" + "||||||" + salt.Value.ToString();  
  26. String text = Key.Value.ToString() + "|" + txnid.Value.ToString() +"|" + amount + "|" + "Wear" + "|" + TextBox1.Text + "|" + TextBox2.Text + "|" + "||||||" + salt.Value.ToString();  
  27. //byte[] message = Encoding.UTF8.GetBytes(text);  
  28. //UnicodeEncoding UE = new UnicodeEncoding();  
  29. //byte[] hashValue;  
  30. //SHA512Managed hashString = new SHA512Managed();  
  31. //string hex = "";  
  32. //hashValue = hashString.ComputeHash(message);  
  33. //foreach (byte x in hashValue)  
  34. //{  
  35. // hex += String.Format("{0:x2}", x);  
  36. //}  
  37. byte[] message = Encoding.UTF8.GetBytes(text);  
  38. UnicodeEncoding UE = new UnicodeEncoding();  
  39. byte[] hashValue;  
  40. SHA512Managed hashString = new SHA512Managed();  
  41. string hex = "";  
  42. hashValue = hashString.ComputeHash(message);  
  43. foreach (byte x in hashValue)  
  44. {  
  45. hex += String.Format("{0:x2}", x);  
  46. }  
  47. hash.Value = hex;  
  48. System.Collections.Hashtable data = new System.Collections.Hashtable();  
  49. data.Add("hash", hex.ToString());  
  50. data.Add("txnid", txnid.Value);  
  51. data.Add("Key", Key.Value);  
  52. data.Add("amount", amount);  
  53. data.Add("Firstname", TextBox1.Text.Trim());  
  54. data.Add("email", TextBox2.Text.Trim());  
  55. data.Add("phone", TextBox3.Text.Trim());  
  56. data.Add("productinfo""WEarnew");  
  57. data.Add("ufd1""1");  
  58. data.Add("ufd2""1");  
  59. data.Add("ufd3""1");  
  60. data.Add("ufd4""1");  
  61. data.Add("ufd5""1");  
  62. data.Add("surl""http://localhost:15073/web/Successpayment.aspx");  
  63. data.Add("furl""http://localhost:15073/web/Failar.aspx");  
  64. data.Add("service_provider""");  
  65. string strform = PreparePOSTForm("https://test.payu.in/_payment", data);  
  66. Page.Controls.Add(new LiteralControl(strform));  
  67. }  
  68. private string PreparePOSTForm(string url, System.Collections.Hashtable data) // post form  
  69. {  
  70. //Set a name for the form  
  71. string formID = "PostForm";  
  72. //Build the form using the specified data to be posted.  
  73. StringBuilder strForm = new StringBuilder();  
  74. strForm.Append("<form id=\"" + formID + "\" name=\"" +  
  75. formID + "\" action=\"" + url +  
  76. "\" method=\"POST\">");  
  77. foreach (System.Collections.DictionaryEntry key in data)  
  78. {  
  79. strForm.Append("<input type=\"hidden\" name=\"" + key.Key +  
  80. "\" value=\"" + key.Value + "\">");  
  81. }  
  82. strForm.Append("</form>");  
  83. //Build the JavaScript which will do the Posting operation.  
  84. StringBuilder strScript = new StringBuilder();  
  85. strScript.Append("<script language='javascript'>");  
  86. strScript.Append("var v" + formID + " = document." +  
  87. formID + ";");  
  88. strScript.Append("v" + formID + ".submit();");  
  89. strScript.Append("</script>");  
  90. //Return the form and the script concatenated.  
  91. //(The order is important, Form then JavaScript)  
  92. return strForm.ToString() + strScript.ToString();  
  93. }  
  94. //private string PreparePOSTform (string url, System.Collections.Hashtable data)  
  95. //{  
  96. // string formID = "Postform";  
  97. // StringBuilder strform = new StringBuilder();  
  98. // strform.Append("<form id=\"" + formID + "\" name=\"" + formID + "\" action =\"" + url + "\" + method=\"Post\" > ");  
  99. // foreach (System.Collections.DictionaryEntry key in data)  
  100. // {  
  101. // strform.Append("< input type= \"hidden\" name=\"" + key.Key + "\" value = \"" + Key.Value + "\" > ");  
  102. // }  
  103. // strform.Append("/form");  
  104. // StringBuilder strScript = new StringBuilder();  
  105. // strScript.Append("<Script language = 'javascript'");  
  106. // strScript.Append("var v " + formID + " = documnet." + formID + ";" );  
  107. // strScript.Append("v" + formID + ".submit();");  
  108. // strScript.Append("</script>");  
  109. // return strform.ToString() + strScript.ToString();  
  110. // }  
  111. }  

Answers (1)