I tried below code but got error in redirection of payumoney page kindly check , my hash value is not generated properly.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class BuyNow : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- Label1.Text = Request.QueryString["Price"].ToString();
- Random random = new Random();
- txnid.Value = (Convert.ToString(random.Next(10000, 20000)));
- txnid.Value = "AVJFINANCE" + txnid.Value.ToString();
- Response.Write(txnid.Value.ToString());
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- Double amount = Convert.ToDouble(Label1.Text);
- // String text = Key.Value.ToString() + "|" + txnid.Value.ToString() +"|" + amount + "|" + "Wear" + "|" + TextBox1.Text + "|" + TextBox2.Text + "|" + "1" + "|" + "1" + "|" + "1" + "|" + "1" + "|" + "1" + "||||||" + salt.Value.ToString();
- String text = Key.Value.ToString() + "|" + txnid.Value.ToString() +"|" + amount + "|" + "Wear" + "|" + TextBox1.Text + "|" + TextBox2.Text + "|" + "||||||" + salt.Value.ToString();
- //byte[] message = Encoding.UTF8.GetBytes(text);
- //UnicodeEncoding UE = new UnicodeEncoding();
- //byte[] hashValue;
- //SHA512Managed hashString = new SHA512Managed();
- //string hex = "";
- //hashValue = hashString.ComputeHash(message);
- //foreach (byte x in hashValue)
- //{
- // hex += String.Format("{0:x2}", x);
- //}
- byte[] message = Encoding.UTF8.GetBytes(text);
- UnicodeEncoding UE = new UnicodeEncoding();
- byte[] hashValue;
- SHA512Managed hashString = new SHA512Managed();
- string hex = "";
- hashValue = hashString.ComputeHash(message);
- foreach (byte x in hashValue)
- {
- hex += String.Format("{0:x2}", x);
- }
- hash.Value = hex;
- System.Collections.Hashtable data = new System.Collections.Hashtable();
- data.Add("hash", hex.ToString());
- data.Add("txnid", txnid.Value);
- data.Add("Key", Key.Value);
- data.Add("amount", amount);
- data.Add("Firstname", TextBox1.Text.Trim());
- data.Add("email", TextBox2.Text.Trim());
- data.Add("phone", TextBox3.Text.Trim());
- data.Add("productinfo", "WEarnew");
- data.Add("ufd1", "1");
- data.Add("ufd2", "1");
- data.Add("ufd3", "1");
- data.Add("ufd4", "1");
- data.Add("ufd5", "1");
- data.Add("surl", "http://localhost:15073/web/Successpayment.aspx");
- data.Add("furl", "http://localhost:15073/web/Failar.aspx");
- data.Add("service_provider", "");
- string strform = PreparePOSTForm("https://test.payu.in/_payment", data);
- Page.Controls.Add(new LiteralControl(strform));
- }
- private string PreparePOSTForm(string url, System.Collections.Hashtable data) // post form
- {
- //Set a name for the form
- string formID = "PostForm";
- //Build the form using the specified data to be posted.
- StringBuilder strForm = new StringBuilder();
- strForm.Append("
- formID + "\" action=\"" + url +
- "\" method=\"POST\">");
- foreach (System.Collections.DictionaryEntry key in data)
- {
- strForm.Append(" + key.Key +
- "\" value=\"" + key.Value + "\">");
- }
- strForm.Append("");
- //Build the JavaScript which will do the Posting operation.
- StringBuilder strScript = new StringBuilder();
- strScript.Append("");
- //Return the form and the script concatenated.
- //(The order is important, Form then JavaScript)
- return strForm.ToString() + strScript.ToString();
- }
- //private string PreparePOSTform (string url, System.Collections.Hashtable data)
- //{
- // string formID = "Postform";
- // StringBuilder strform = new StringBuilder();
- // strform.Append("
- // foreach (System.Collections.DictionaryEntry key in data)
- // {
- // strform.Append("< input type= \"hidden\" name=\"" + key.Key + "\" value = \"" + Key.Value + "\" > ");
- // }
- // strform.Append("/form");
- // StringBuilder strScript = new StringBuilder();
- // strScript.Append("");
- // return strform.ToString() + strScript.ToString();
- // }
- }
Balbir BhuriaPosted Aug 10, 2021, 3:33 PM
i m also tired use this code every time its shown
"Transaction failed due to incorrectly calculated hash parame" error kindly resolve it