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 + "|" + "||||||" + 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);
- }
- 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)
- {
-
- string formID = "PostForm";
-
- StringBuilder strForm = new StringBuilder();
- strForm.Append("<form id=\"" + formID + "\" name=\"" +
- formID + "\" action=\"" + url +
- "\" method=\"POST\">");
- 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("<script language='javascript'>");
- strScript.Append("var v" + formID + " = document." +
- formID + ";");
- strScript.Append("v" + formID + ".submit();");
- strScript.Append("</script>");
-
-
- return strForm.ToString() + strScript.ToString();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }