0

On button click I want the user to redirect to payumoney gateway and if payment has been done successfully, the data of user to be store in database and redirect user to success page vice a versa..

Currently I am saving data using AJAX call and redirect user on ajax success:function.

AJAX

$('#payNowButton').on("click", function () {

    var total = $('#main_total_s5').html();
    console.log("Total : " + total);
    $.ajax({
        url: '/Home/Demo?total=' + total, //Demo method in Home Controller is for payumoney payment gateway.
        type: "POST",
        data: total,
        async: false,
        success: function (result) {
            window.location.href = result;
            if (result > 0) {
                PlaceOrder(); //after successful payment, it will call this function to save data in database.
                window.location.href = '@Url.Action("Sucess", "Home")';
            }
            else {
                alert("Some error occurred." + result);
            }
        },
        error: function (result) {
            window.location.href = '@Url.Action("Failure", "Home")';
        }
    });
});

Controller

[HttpPost]
    public void Demo(OrderCustom orderCustom)
    {
        string firstName = "";
        string amount = "";
        string productInfo = "";
        string email = "";
        string phone = "";
        string surl;
        string furl;


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

        //posting all the parameters required for integration.

        myremotepost.Url = "https://secure.payu.in/_payment";
        myremotepost.Add("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:/Home/Sucess");//Change the success url here depending upon the port number of your local system.
        myremotepost.Add("furl", "http://localhost:/Home/Failure");//Change the failure url here depending upon the port number of your local system.
        myremotepost.Add("service_provider", "payu_paisa");
        string hashString = key + "|" + txnid + "|" + amount + "|" + productInfo + "|" + firstName + "|" + email + "|||||||||||" + salt;
        string hash = Generatehash512(hashString);
        myremotepost.Add("hash", hash);
        myremotepost.Post();
    }

    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 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();
        }
    }

When I click on button it shows this error : Error Image

4

2 回答 2

0
myremotepost.Add("service_provider", "payu_paisa");

这是必填字段,最近我正在与服务台联系,他们要求进行一些定制。然后它会工作

于 2020-04-22T09:53:17.643 回答
0

我昨天也遇到了同样的问题。我做了什么,我删除了myremotepost.Add("service_provider", "payu_paisa");它,它起作用了!

还要检查一次 URL,如果您在测试服务器上进行,那么 URL 将是https://test.payu.in/_payment

“Key”和“SALT”值不能为空,这些值将由 payumoney 自己共享给您。

 string key = "";
 string salt = "";
于 2017-07-24T06:03:33.837 回答