I am trying to test my paypal application and specified my paypal notify_url as www.xx.com/paypal.aspx. I should be getting response from the sandbox paypal. But I am not getting anything on the paypal.aspx page. My repsonse processing code is:
protected void Page_Load(object sender, EventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
con = new SqlConnection(connStr);
con.Open();
//Post back to either sandbox or live
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
// string strLive = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
if (strResponse == "VERIFIED")
{
//Insert statement
}
else if (strResponse == "INVALID")
{
//UPDATE YOUR DATABASE
StreamWriter swr = new StreamWriter(Server.MapPath("Textfile.txt"));
swr.WriteLine("---- not verified(" + DateTime.Now.ToString() + ")--");
swr.Dispose();
}
else
{ //UPDATE YOUR DATABASE
//TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt");
//txWriter.WriteLine("Invalid");
////log response/ipn data for manual investigation
//txWriter.Close();
}
The payment is processed fully. I am also directed to the thank you page. Please HELP
Thanks
First, you have to make sure that the URL you are passing to PayPal as the notify_url value is a publicly valid and resolvable URL. Meaning, make sure you are not sending it an internal network URL or machine name (i.e. localhost, my_computer_name, mypcname.mynetwork.com ). Easy way to check that and make sure you haven't created a bad name or have an incorrect network configuration, is take whatever URL you are sending to PayPal as the notify_url value, and have a friend that is external to your network try to access the URL in their browser. If they get a connection error, you have to rethink your network configuration or naming before you can get PayPal to see your machine.
Second, if you are running the above code in Visual Studio using the debugger and build in web server, you might be limited to it only responding to requests if the requested site name is "localhost". See the following Microsoft article on how to setup your code to run in an actual instance of IIS.