我试图在我的客户端网站中集成 PayUMoney 支付网关。
1)我的帐户已被激活。
2)商家密钥&盐键是对的。
3)我已在服务提供商字段中添加了 payu_paisa 。
当添加超过700个金额时,它会给出消息:抱歉发生了一些错误。
以下是代码:
public ActionResult PaymentWithPayuMoney()
{
var objOrderBal = new OrderBal();
var objOrderDetail = objOrderBal.GetOrderDetail(User.Identity.GetUserId());
//var userDetails = UserManager.FindById(User.Identity.GetUserId());
var userDetails = objOrderBal.GetOrder(User.Identity.GetUserId());
var ordersubTotal = 0.00m;
var shipping = 0;
foreach (var objOrder in objOrderDetail)
{
ordersubTotal = objOrder.TotalPrice * objOrder.Quantity + ordersubTotal;
shipping = Convert.ToInt32(shipping) + Convert.ToInt32(objOrder.ShippingCharge);
}
var orderTotal = Convert.ToString(Convert.ToDouble(shipping) + Convert.ToDouble(ordersubTotal), CultureInfo.InvariantCulture);
var key = ConfigurationManager.AppSettings["MERCHANT_KEY"];
var myremotepost = new RemotePost { Url = ConfigurationManager.AppSettings["PAYU_BASE_URL"] + "/_payment" };
myremotepost.Add("key", key);
myremotepost.Add("txnid", Generatetxnid());
myremotepost.Add("amount", orderTotal);
myremotepost.Add("productinfo", "productname");
myremotepost.Add("firstname", userDetails.Name);
myremotepost.Add("phone", userDetails.MobileNo);
myremotepost.Add("email", userDetails.Email);
if (Request.Url != null)
{
myremotepost.Add("surl", "" + Request.Url.Scheme + "://" + Request.Url.Authority + "/Order/Return");
myremotepost.Add("furl", "" + Request.Url.Scheme + "://" + Request.Url.Authority + "/Order/Return");
}
myremotepost.Add("service_provider", "payu_paisa");
string hashString = key + "|" + Generatetxnid() + "|" + orderTotal + "|productname|" + userDetails.Name + "|" + userDetails.Email + "|||||||||||" + ConfigurationManager.AppSettings["SALT"];
string hash = Generatehash512(hashString);
myremotepost.Add("hash", hash);
myremotepost.Post();
return View("SuccessView");
}
public class RemotePost
{
public readonly System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();
public string Url = "";
public string Method = "post";
public string FormName = "form1";
public void Add(string name, string value)
{
Inputs.Add(name, value);
}
public void Post()
{
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Write("<html><head>");
System.Web.HttpContext.Current.Response.Write($"</head><body onload=\"document.{FormName}.submit()\">");
System.Web.HttpContext.Current.Response.Write($"<form name=\"{FormName}\" method=\"{Method}\" action=\"{Url}\" >");
for (var i = 0; i < Inputs.Keys.Count; i++)
{
System.Web.HttpContext.Current.Response.Write($"<input name=\"{Inputs.Keys[i]}\" type=\"hidden\" value=\"{Inputs[Inputs.Keys[i]]}\">");
}
System.Web.HttpContext.Current.Response.Write("</form>");
System.Web.HttpContext.Current.Response.Write("</body></html>");
System.Web.HttpContext.Current.Response.End();
}
}
public string Generatehash512(string text)
{
var message = Encoding.UTF8.GetBytes(text);
var hashString = new SHA512Managed();
var hashValue = hashString.ComputeHash(message);
return hashValue.Aggregate("", (current, x) => current + $"{x:x2}");
}
public string Generatetxnid()
{
var rnd = new Random();
var strHash = Generatehash512(rnd.ToString() + DateTime.Now);
var txnid1 = strHash.Substring(0, 20);
return txnid1;
}
答案 0 :(得分:0)
请检查您计算的哈希值与payu服务器生成的哈希值匹配。