PayPal IPN notify-validate is returning sandbox login HTML for ASP.NET

asp.net, paypal, paypal-ipn, vb.net

Solution

If you receive HTML in return, then the notify-validate is not correctly sent through to PayPal. It needs to be &cmd=_notify-validate (with the underscore directly after the cmd key) I must have somehow accidentally deleted it in my hazy stupor. My IPN listener is now successfully returning VERIFIED :)

Problem

Overview of problem: I have implemented the IPN listener and I know that PayPal is directing to it (because of a generated text file), the correct parameters are sent through to me in the QueryString however when I append "&cmd=notify-validate" to the query string for the validation to take place and send it to PayPal, I get the following HTML response: . When I copy and paste that returned HTML into a blank HTML document I see the following: Initially I thought my session had expired but when I accessed the Sandbox via my browser, I was automatically logged in. I have even tried clicking on the link in my html document to ensure I am logged in and tried processing another test IPN through the simulator in the sandbox but I keep getting this result. I just can't see what I am doing wrong and the sad thing is that it was working correctly about an hour ago :( My IPN listener code to send and get the validation response: ``` Dim payPalUrl As String = PayPalPayment.PayPalURL 'This returns https://www.sandbox.paypal.com/cgi-bin/webscr Dim req As HttpWebRequest = CType(WebRequest.Create(payPalUrl), HttpWebRequest) 'Set values for the request back req.Method = "POST" req.ContentType = "application/x-www-form-urlencoded" Dim params() As Byte = Request.BinaryRead(Request.ContentLength) Dim ipnRequest As String = Encoding.ASCII.GetString(params) Dim ipnPost As String = ipnRequest ipnRequest &= "&cmd=notify-validate" req.ContentLength = ipnRequest.Length myUtility.AuditIPN(filename, ipnRequest) ''for proxy 'Dim proxy As New WebProxy(New System.Uri("http://url:port#")) 'req.Proxy = proxy 'Send the request to PayPal and get the response Dim streamOut As New StreamWriter(req.GetRequestStream(), Encoding.ASCII) streamOut.Write(ipnRequest) streamOut.Close() Dim streamIn As New StreamReader(req.GetResponse().GetResponseStream()) Dim ipnResponse = streamIn.ReadToEnd() streamIn.Close() 'Rest of the code here... not necessary for this problem ``` Posting the payment to PayPal (if needed). NOTE: I build the form and Response.Write() it in a page. This is the form generation: ``` Dim form As New StringBuilder form.AppendLine("<!DOCTYPE html>") form.AppendLine("<html xmlns=""http://www.w3.org/1999/xhtml"">") form.AppendLine("<head runat=""server"">") form.AppendLine(String.Format("<title>{0} {1}</title>", "PayPal payment for", ItemName)) form.AppendLine("<link href=""../css/paypal.css"" rel=""stylesheet"" />") form.AppendLine("</head>") form.AppendLine("<body>") form.AppendLine("<div class=""paypal""></div>") form.AppendLine(String.Format("<p>Accessing PayPal to process your payment for the {0}.</p>", ItemName)) form.AppendLine("<div class=""loading""></div>") form.AppendLine("<form id=""myform"" action=""https://www.sandbox.paypal.com/cgi-bin/webscr"" method=""post"">") form.AppendLine("<input type=""hidden"" name=""cmd"" value=""_xclick"">") form.AppendLine(String.Format("<input type=""hidden"" name=""business"" value=""{0}"">", BusinessEmail)) form.AppendLine(String.Format("<input type=""hidden"" name=""item_name"" value=""{0}"">", ItemName)) form.AppendLine(String.Format("<input type=""hidden"" name=""amount"" value=""{0}"">", Amount)) form.AppendLine(String.Format("<input type=""hidden"" name=""currency_code"" value=""{0}"">", Currency)) form.AppendLine(String.Format("<input type=""hidden"" name=""return"" value=""{0}"">", ReturnURL)) form.AppendLine("<input type=""hidden"" name=""button_subtype"" value=""products"">") form.AppendLine("<input type=""hidden"" name=""bn"" value=""HHMRKWQT8NRTW:PP-BuyNowBF_P"">") form.AppendLine("<input type=""hidden"" name=""no_note"" value=""0"">") form.AppendLine("</form>") form.AppendLine("<script type=""text/javascript"">") form.AppendLine(" document.forms[""myform""].submit();") form.AppendLine("</script>") return form.ToString() ``` If I need to post anything else regarding this issue, please let me know as my brain is completely fried at the moment. Your time and help will greatly be appreciated! NOTE: Although my code is in VB.NET I develop in C# too, so C# sample code will definitely not be frowned upon! Answer: If you receive HTML in return, then the notify-validate is not correctly sent through to PayPal. It needs to be &cmd=_notify-validate (with the underscore directly after the cmd key) I must have somehow identically deleted it in my hazy stupor. My IPN listener is now successfully returning VERIFIED :)

Original source