1
Answer

Paypal url return FAIL after order complete in Mvc 4

Paypal return id comes fail.what should i do?? I have tried a lot..but not working..
 
  1. public string Cart_ConfirmOrder(string UnitId)  
  2.            {  
  3.                int Quantity = 0;              
  4.                string name = "";  
  5.                try  
  6.                {  
  7.    Session["Quantity"] = Quantity;  
  8.                    Session["UnitID"] = name;  
  9.                    Session["payamount"] = ConfigurationManager.AppSettings["payamount"].ToString();  
  10.                    //Session["payamount"] = AmountCount.ToString();  
  11.                    //Session["msg"] = " You Tag request has been submitted";  
  12.                    string redirecturl = "";  
  13.                    redirecturl +=  
  14.                    redirecturl += "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" + ConfigurationManager.AppSettings["BusinessEmail"].ToString();  
  15.                    ////Product Name  
  16.                    //redirecturl += "&item_name=" + model.UnitId;  
  17.                    redirecturl += "&item_name=" + name;  
  18.                    ////Payment Section  
  19.                    //redirecturl += "&amount=" + AmountCount.ToString();  
  20.                    redirecturl += "&amount=" + ConfigurationManager.AppSettings["payamount"].ToString();  
  21.   
  22.                    ////Add quatity i added one only statically   
  23.                    redirecturl += "&quantity=" + Quantity;  
  24.                    ////Currency code   
  25.                    ////redirecturl += "¤cy=";  
  26.                    ////Tax charges if any, or available or using shopping cart system  
  27.                    redirecturl += "&tax=" + 0;  
  28.                    ////Success return page url  
  29.                    redirecturl += "&return=" +  
  30.                      ConfigurationManager.AppSettings["ReturnUrl"].ToString();  
  31.                    ////Failed return page url  
  32.                    redirecturl += "&cancel_return=" +  
  33.                    ConfigurationManager.AppSettings["CancelPurchaseUrl"].ToString();  
  34.   
  35.                    ////return Redirect(redirecturl);  
  36.   
  37.                    return redirecturl;  
  38.                    //return retval;  
  39.                }  
  40.                catch (Exception ex)  
  41.                {  
  42.                    throw ex;  
  43.                }  
  44.    }      
  45.    public ActionResult GetResponse()  
  46.                {   
  47.        string TransactionIDc = Request.QueryString.Get("tx");  
  48.                        string transactionID = "";  
  49.                        var formVals = new Dictionary<stringstring>();  
  50.                        formVals.Add("cmd""_notify-synch"); //_notify-synch_notify-validate  
  51.                        formVals.Add("at""AO6pILVgzXKfGZ4XyTdge9Zgmio.AbNUckZNoSqVHzWaFf8gWR0BPzqP"); // this has to be adjusted  
  52.                        formVals.Add("tx", Request["tx"]);  
  53.   
  54.                        string response = GetPayPalResponse(formVals, true);  
  55.                        if (response.Contains("SUCCESS"))  
  56.                        {  
  57.                            transactionID = GetPDTValue(response, "txn_id"); // txn_id //d  
  58.                            string sAmountPaid = GetPDTValue(response, "mc_gross"); // d  
  59.                            string deviceID = GetPDTValue(response, "custom"); // d  
  60.                            string payerEmail = GetPDTValue(response, "payer_email"); // d  
  61.                            string Item = GetPDTValue(response, "item_name");                                          
  62.                        }  
  63.                        else  
  64.                        {                      
  65.                        }  
  66.         }  
  67.        string GetPayPalResponse(Dictionary<stringstring> formVals, bool useSandbox)  
  68.                {  
  69.   
  70.                    string paypalUrl = useSandbox ? "https://www.sandbox.paypal.com/cgi-bin/webscr"  
  71.                        : "https://www.paypal.com/cgi-bin/webscr";  
  72.   
  73.                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(paypalUrl);  
  74.   
  75.                    // Set values for the request back  
  76.                    req.Method = "POST";  
  77.                    req.ContentType = "application/x-www-form-urlencoded";  
  78.   
  79.                    byte[] param = Request.BinaryRead(Request.ContentLength);  
  80.                    string strRequest = Encoding.ASCII.GetString(param);  
  81.   
  82.                    StringBuilder sb = new StringBuilder();  
  83.                    sb.Append(strRequest);  
  84.   
  85.                    foreach (string key in formVals.Keys)  
  86.                    {  
  87.                        sb.AppendFormat("&{0}={1}", key, formVals[key]);  
  88.                    }  
  89.                    strRequest += sb.ToString();  
  90.                    req.ContentLength = strRequest.Length;  
  91.   
  92.                    //for proxy  
  93.                    //WebProxy proxy = new WebProxy(new Uri("http://urlort#");  
  94.                    //req.Proxy = proxy;  
  95.                    //Send the request to PayPal and get the response  
  96.                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;  
  97.                    string response = "";  
  98.                    using (StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))  
  99.                    {  
  100.   
  101.                        streamOut.Write(strRequest);  
  102.                        streamOut.Close();  
  103.                        using (StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()))  
  104.                        {  
  105.                            response = streamIn.ReadToEnd();  
  106.                        }  
  107.                    }  
  108.   
  109.                    return response;  
  110.                }  
  111.                string GetPDTValue(string pdt, string key)  
  112.                {  
  113.   
  114.                    string[] keys = pdt.Split('\n');  
  115.                    string thisVal = "";  
  116.                    string thisKey = "";  
  117.                    foreach (string s in keys)  
  118.                    {  
  119.                        string[] bits = s.Split('=');  
  120.                        if (bits.Length > 1)  
  121.                        {  
  122.                            thisVal = bits[1];  
  123.                            thisKey = bits[0];  
  124.                            if (thisKey.Equals(key, StringComparison.InvariantCultureIgnoreCase))  
  125.                                break;  
  126.                        }  
  127.                    }  
  128.                    return thisVal;  
  129.   
  130.                }  
 

here "response" return FAIL after order complete.

I have changed the IPN notification setting in paypal also

 
 
 
Answers (1)