在我的Asp.net Web API应用程序中实现Payumoney的付款网关时遇到错误

时间:2018-09-25 19:32:20

标签: asp.net-web-api

大家好,我只是在实现payumoney付款网关,但是我遇到了一些错误,我将显示我的所有代码,请帮助我 我的Ajax按钮的前端代码不正确

$("#btnDebitPay").click(function () {

              alert("I am On");
              var Amount = "500";
              var FirstName = "Akshay";
              var Phone = "7275216984";
              var Email = "akshaytomar.com@gmail.com";
              var ProductDetails = "Nikeshoe";


              $.ajax({
                  url: '/api/PaymentGateway/Paynow', //Demo method in Home Controller is for payumoney payment gateway.
                  type: "POST",
                  data: "{'Amount':'" + Amount + "'FirstName':'" + FirstName + "''Phone':'" + Phone + "''Email':'" + Email + "'ProductDetails':'" + ProductDetails + "'}",
                  async: false,
                  success: function (result) {
                     // window.location.href = result;
                      if (result > 0) {

                          window.location.href = 'http://localhost:50371/PayResult/Succes.html';
                      }
                      else {

                          alert("Some error occurred." + result);
                      }
                  },
                  error: function (result) {
                      $("#WebName").text(result.responseText);
                  }
              });

          });

并且我的控制器按钮代码无效

public void Paynow(PaymentDetails PD)
        {
            //string firstName = PD.FirstName;
            //string amount = PD.Amount;
            //string productInfo = PD.ProductDetails;
            //string email = PD.Email;
            //string phone = PD.Phone;

            string firstName = "akshay";
            string amount = "100";
            string productInfo ="NikeShoe";
            string email = "akshaytomar.com@gmail.com";
            string phone = "1815216984";

            //string surl;
            //string furl;


            RemotePost myremotepost = new RemotePost();
            string key = "MyKey";
            string salt = "Mysalt";

            //posting all the parameters required for integration.

            myremotepost.Url = "https://secure.payu.in/_payment";
            myremotepost.Add("key", key);
            string txnid = Generatetxnid();
            myremotepost.Add("txnid", txnid);
            myremotepost.Add("amount", amount);
            myremotepost.Add("productinfo", productInfo);
            myremotepost.Add("firstname", firstName);
            myremotepost.Add("phone", phone);
            myremotepost.Add("email", email);
            myremotepost.Add("surl", "http://localhost:50371/PayResult/Succes.html");//Change the success url here depending upon the port number of your local system.
            myremotepost.Add("furl", "http://localhost:50371/PayResult/PayFailed.html");//Change the failure url here depending upon the port number of your local system.
            myremotepost.Add("service_provider", "payu_paisa");
            string hashString = key + "|" + txnid + "|" + PD.Amount + "|" + PD.ProductDetails + "|" + PD.FirstName + "|" + PD.Email + "|||||||||||" + salt;
            string hash = Generatehash512(hashString);
            myremotepost.Add("hash", hash);
            myremotepost.Post();
        }

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

        private 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 class RemotePost
        {
            private 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 AddAmount(string name, float 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(string.Format("</head><body onload=\"document.{0}.submit()\">", FormName));
                System.Web.HttpContext.Current.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, Url));
                for (int i = 0; i < Inputs.Keys.Count; i++)
                {
                    System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", Inputs.Keys[i], 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();
            }
        }

    }

我发现错误在消遣

<html><head></head><body onload="document.form1.submit()"><form name="form1" method="post" action="https://secure.payu.in/_payment" ><input name="key" type="hidden" value="ZRp9sBFq"><input name="txnid" type="hidden" value="4d1be7ff0266b3f08496"><input name="amount" type="hidden" value="100"><input name="productinfo" type="hidden" value="NikeShoe"><input name="firstname" type="hidden" value="akshay"><input name="phone" type="hidden" value="1815216984"><input name="email" type="hidden" value="akshaytomar.com@gmail.com"><input name="surl" type="hidden" value="http://localhost:50371/PayResult/Succes.html"><input name="furl" type="hidden" value="http://localhost:50371/PayResult/PayFailed.html"><input name="service_provider" type="hidden" value="payu_paisa"><input name="hash" type="hidden" value="2b45d9219112c055ba11f37b44f944477c18e5d313a0d43922171573645662e77d9ed059f26163bd2d9e700347f07b1b1ed147ac9202990e9f2d3d5b88e3d836"></form></body></html>
 Login

我从payumoney样本工具包中获得了上述代码,但它给我带来了错误,我非常不高兴,因此请帮助我寻找解决方法

0 个答案:

没有答案