0

我正在尝试将PayUMoney支付网关集成到我的客户站点中。

1) 我的帐户已经激活。
2) Merchant key & Salt key 是对的。
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;
    }
4

1 回答 1

0

请检查您计算的哈希值是否与 payu 服务器生成的哈希值匹配。

于 2017-06-03T20:47:24.963 回答