Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear sir/madam

c# - PayUMoney Integration in MVC and calling using ajax - Stack Overflow[^]

i am facing the same problem mentioned in the above link.
so respected members provider your advice and help.
thanks for your help in advance

What I have tried:

the gateway provide have provide the code in asp.net and i wanted to use it in mvc
when i use this code in mvc
Page.Controls.Add(new LiteralControl(strForm));//this line give me error.

public string Generatehash512(string text)
{

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);
}
return hex;

}

public string Generatetxnid()
{
Random rnd = new Random();
string strHash = Generatehash512(rnd.ToString() + DateTime.Now);
return strHash.ToString().Substring(0, 20);
}

[HttpPost]
public void demo(string amt, string name, string emaill, string phno, string prod)
{
string firstName = name;
string amount = amt;
string productInfo = prod;
string email = emaill;
string phone = phno;

string key = "";
string salt = "";
string txnid = Generatetxnid();
string hashString = key + "|" + txnid + "|" + amount + "|" + productInfo + "|" + firstName + "|" + email + "|||||||||||" + salt;
string hash = Generatehash512(hashString).ToLower();
System.Collections.Hashtable data = new System.Collections.Hashtable(); // adding values in gash table for data post
data.Add("hash", hash);
data.Add("txnid", txnid);
data.Add("key", key);
data.Add("amount", amount);
data.Add("firstname", name);
data.Add("email", email);
data.Add("phone", phone);
data.Add("productinfo", productInfo);
data.Add("surl", "http://localhost:61818/Default/Sucess");
data.Add("furl", "http://localhost:61818/Default/Failure");
data.Add("service_provider", "payu_paisa");
action1 = "https://sandboxsecure.payu.in/_payment";
string strForm = PreparePOSTForm(action1, data);
// Page.Controls.Add(new LiteralControl(strForm));//Giving Error
}
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("");

foreach (System.Collections.DictionaryEntry key in data)
{

strForm.Append("");
}
strForm.Append("");
// Build the JavaScript which will do the Posting operation.
StringBuilder strScript = new StringBuilder();
strScript.Append("");
strScript.Append("var v" + formID + " = document." +
formID + ";");
strScript.Append("v" + formID + ".submit();");
strScript.Append("");
// Return the form and the script concatenated.
// (The order is important, Form then JavaScript)
return strForm.ToString() + strScript.ToString();
}
}
Posted
Updated 15-Feb-18 9:51am

1 solution

MVC doesn't use a control tree; you just need to return the raw HTML to the user:
C#
[HttpPost]
public ActionResult demo(string amt, string name, string emaill, string phno, string prod)
{
    ...
    string strForm = PreparePOSTForm(action1, data);
    return Content(strForm, System.Net.Mime.MediaTypeNames.Text.Html);
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900