NOW I GOING TO START PAY U MONEY PAYMENT INTEGRATION .NET MVC
STEP:--1
GET THE KEY FOR TEST MODE WHEN YOUR SITE GOING LIVE SET URL AS LIVE.
STEP:--2
put merchant key on key place given below
put salt on salt place given below
ADD SUM FIELD IN WEB.CONFIGS
CREATE A HTML FOR PASS THE DYNAMIC AMOUNT FOR PAYMENTS
LIKE THIS:
WHEN CLICK ON BUTTON THEN REDIRECT TO PAY U MONEY PAYMENT GATEWAY.
VIEW OF THIS HTML
---------------------------------
--------------------------------------------------------------------------------------------------------------
CLICK ON PAY NOW AND HITS THE CONTROLLER.
C# code
---------------------
[HttpPost]
public ActionResult CheckoutPayu(Property P)
{
EncryptDecrypt enc = new EncryptDecrypt();
HttpCookie loginCookie = Request.Cookies["cookie"];
if (loginCookie != null)
{
P.UserID = enc.Decrypt(loginCookie["Uid"].ToString());
}
if (Request.Cookies["CartIdCookie"] != null)
{
P.cartid = Request.Cookies["CartIdCookie"].Value.ToString();
}
else
{
HttpCookie CartIdCookie = new HttpCookie("CartIdCookie");
P.cartid = Guid.NewGuid().ToString("N");
CartIdCookie.Value = P.cartid;
Response.Cookies.Add(CartIdCookie);
}
P.Amount = Session["Total"].ToString();
P.productinfo = "Demo";
//P.productinfo = Session["ProductName"].ToString();
string[] hashVarsSeq;
string hash_string = string.Empty;
var key = ConfigurationManager.AppSettings["MERCHANT_KEY"];
if (string.IsNullOrEmpty(Request.Form["txnid"])) // generating txnid
{
Random rnd = new Random();
string strHash = Generatehash512(rnd.ToString() + DateTime.Now);
txnid1 = strHash.ToString().Substring(0, 20);
}
else
{
txnid1 = Request.Form["txnid"];
}
if (string.IsNullOrEmpty(Request.Form["hash"]))
{
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["MERCHANT_KEY"]) ||
string.IsNullOrEmpty(txnid1) ||
string.IsNullOrEmpty(Request.Form["Amount"]) ||
string.IsNullOrEmpty(Request.Form["firstname"]) ||
string.IsNullOrEmpty(Request.Form["email"]) ||
string.IsNullOrEmpty(Request.Form["phone"]) ||
string.IsNullOrEmpty(Request.Form["DeliveryZip"]) ||
string.IsNullOrEmpty(Request.Form["surl"]) ||
string.IsNullOrEmpty(Request.Form["furl"]) ||
string.IsNullOrEmpty(Request.Form["service_provider"])
)
{
hashVarsSeq = ConfigurationManager.AppSettings["hashSequence"].Split('|'); // spliting hash sequence from config
hash_string = "";
foreach (string hash_var in hashVarsSeq)
{
if (hash_var == "key")
{
hash_string = hash_string + ConfigurationManager.AppSettings["MERCHANT_KEY"];
hash_string = hash_string + '|';
}
else if (hash_var == "txnid")
{
hash_string = hash_string + txnid1;
hash_string = hash_string + '|';
}
else if (hash_var == "amount")
{
hash_string = hash_string + P.Amount;//hash_string + Convert.ToDecimal(Request.Form[hash_var]).ToString("g29");
hash_string = hash_string + '|';
}
else
{
//hash_string = hash_string + (Request.Form[hash_var] != null ? Request.Form[hash_var] : "");// isset if else
//hash_string = hash_string + '|';
}
}
hash_string = hash_string + P.productinfo + '|' + P.FirstName + '|' + P.EmailID + '|' + "f1" + '|' + "f2" + '|' + "f3" + '|' + "f4" + '|' + "f5" + '|' + "" + '|' + "" + '|' + "" + '|' + "" + '|' + "" + '|';
hash_string += ConfigurationManager.AppSettings["SALT"];// appending SALT
hash1 = Generatehash512(hash_string).ToLower(); //generating hash
action1 = ConfigurationManager.AppSettings["PAYU_BASE_URL"] + "/_payment";// setting URL
}
}
else if (!string.IsNullOrEmpty(Request.Form["hash"]))
{
hash1 = Request.Form["hash"];
action1 = ConfigurationManager.AppSettings["PAYU_BASE_URL"] + "/_payment";
}
if (!string.IsNullOrEmpty(hash1))
{
string Zip = P.DeliveryZip;
string pho = P.ContactNo;
string Country = P.Country;
string City = P.City;
string Addr = P.Address;
string surl = "http://XXXX/Payment/Success";
string furl = "http://XXXXX/Payment/Cancle";
string curl = "http://XXXXX/Payment/Cancle";
string lastname = "sURAJ";
string service_provider = "payu_paisa";
System.Collections.Hashtable data = new System.Collections.Hashtable(); // adding values in gash table for data post
data.Add("hash", hash1);
data.Add("txnid", txnid1);
data.Add("key", key);
string AmountForm = P.Amount;// eliminating trailing zeros
data.Add("amount", AmountForm);
data.Add("firstname", P.FirstName);
data.Add("email", P.EmailID);
data.Add("phone", P.ContactNo);
data.Add("productinfo", P.productinfo);
data.Add("surl", surl);
data.Add("furl", furl);
data.Add("lastname", lastname);
data.Add("curl", curl);
data.Add("address1", P.Address);
data.Add("address2", P.Address);
data.Add("city", P.City);
data.Add("state", "WB");
data.Add("country", P.Country);
data.Add("zipcode", P.DeliveryZip);
data.Add("udf1", "f1");
data.Add("udf2", "f2");
data.Add("udf3", "f3");
data.Add("udf4", "f4");
data.Add("udf5", "f5");
data.Add("pg", "pg");
data.Add("service_provider", service_provider);
P.paymentStatus ="Pending";
if (Dl.InsertOrder(P) > 0)
{
TempData["MSG"] = "Data Save Successfully";
}
else
{
TempData["MSG"] = "Data Not Saved!!!";
}
ViewBag.strForm = PreparePOSTForm(action1, data);
}
return View();
}
------------------------------------create in same controller for hash creating -----------------------------------
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;
}
------------------------------------create in same controller----------------------------------
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("<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>");
return strForm.ToString();
}
NOTE:-DO NOT REMOVE ANY KEYWORD
AFTER CLICK YOU CAN REDIRECT ON PAYMENT PAGE
I THINK THIS DOCUMENT HELP TO YOU INTEGRATE THIS PAYMENT GATEWAY.IF YOU FACE ANY ISSUE PLEASE COMMENT US
THANK YOU