Been working on this for a couple weeks with no love. Winhost staff have told me they can no longer offer me any guidance, so I'm posting here. Here is the issue. I have a paypal account that posts an Instant Payment Notification to a page on my site (www.masterappears.com). A few weeks ago, the site stopped working properly (without any code changes from me) and now PayPal claims there is a 500 error when trying to post to my page. Here are the steps I've taken to try to narrow down this problem. 1. Surf to my service page without posting and it shows up fine, so it's not a permissions problem. 2. Remove my custom code from my aspx.vb page and replace it with PayPal's sample script. Then post to it from my own machine. Works. Post to it from my machine to production. Works. Try to post to it from PayPal's server - 500 error. 3. Check with Winhost that they are not blocking any of the listed IP's on this page. They say...nope. 4. Check with Winhost to confirm port 443 and 80 are open. Check. Arg. Any chance someone out there can look at this code and give me a clue how it could suddenly stop working? Code: Imports System.Net Imports System.IO Partial Class test Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'Post back to either sandbox or live Dim strSandbox As String = "https://www.sandbox.paypal.com/cgi-bin/webscr" Dim strLive As String = "https://www.paypal.com/cgi-bin/webscr" Dim req As HttpWebRequest = CType(WebRequest.Create(strSandbox), HttpWebRequest) 'Set values for the request back req.Method = "POST" req.ContentType = "application/x-www-form-urlencoded" Dim Param() As Byte = Request.BinaryRead(HttpContext.Current.Request.ContentLength) Dim strRequest As String = Encoding.ASCII.GetString(Param) strRequest = strRequest + "&cmd=_notify-validate" req.ContentLength = strRequest.Length '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 StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII) streamOut.Write(strRequest) streamOut.Close() Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream()) Dim strResponse As String = streamIn.ReadToEnd() streamIn.Close() If strResponse = "VERIFIED" Then 'check the payment_status is Completed 'check that txn_id has not been previously processed 'check that receiver_email is your Primary PayPal email 'check that payment_amount/payment_currency are correct 'process payment ElseIf strResponse = "INVALID" Then 'log for manual investigation Else 'Response wasn't VERIFIED or INVALID, log for manual investigation End If End Sub End Class
I have told both sides point #2. PayPal's test page just reports a 500 error. The specific error is: IPN delivery failed. HTTP error code 500: Internal Server Error
Don't know why I hadn't found this before, but I think the essence of this issue is discussed here: https://www.x.com/thread/42429;jsessionid=6BE1685553A53F0FBD7104E9BC138B2B.node0?start=15&tstart=0 Sounds like the problem is PayPal refusing "empty" posted fields. Will update and test my code tonight and post the working version for anyone who stumbles upon this.
Still getting the 500 error. To clarify: If I POST from a <form> from some other place but use all the variables PayPal is using, everything works. When PayPal posts, they get the 500 response. So, I'm almost certain it has nothing to do with my code. PayPal assures me that it's your servers returning the 500 error. I can force the post from PayPal world. If we could coordinate a time when you could then check your logs, that might shed some light.
BTW. The link I posted a few back IS NOT the issue. That discussion was talking about a different issue.
--IPN delivery failed. HTTP error code 500: Internal Server Error Is this the full error or are there more stuff to it like a stack trace?
My code never even executes. I have peppered the code with error handling all over the place and not a thing.
Is there a way you can check with PayPal what network problems can they see on there end. If the code does not even execute it does not even sound like PayPal is reaching your account.
Just pulled this off my ticket with PayPal: If you're script is processing the IPNs when they POST it is likely a server configuration that's returning a 500 instead of a 200. Our live IPNs are sent from: 216.113.188.202 - Live IPN - notify.paypal.com 216.113.188.203 - Live IPN - notify.paypal.com 216.113.188.204 - Live IPN - notify.paypal.com 64.4.241.140 - Live IPN - notify.paypal.com (back up) Using your string I a was also to verify the IPN as well.
Troubleshooting a full blown application is hard to do. What I suggest is starting from a simple test app without all the objects around it. Set it up to simply capture PayPal's IPN post to your test script. Start from there and start building the app from there. Hopefully it may give you a better clue on where the elusive 500 error is coming from. Remember there are two major components here. Your code and PayPal's code. We can review your code and everything in it looks fine. But we don't know on what PayPal is doing on there backup end. Bottom line, a 500 error is some kind of app error. On which end we don't know. If the error is related to a connection it would surely not result in some kind of 500 error. It would definitely say some sort of connection error.
Ray - thank you very much. I have solved the issue. First, let me say that I've been programming for a long time and this was yet another example of why you NEVER get snippy when people on forums are trying to help you. I was really bothered by this problem and was SURE it was either Winhost or PayPal jacking with me. If you have any sense of narrative, I'm sure you've guessed already that the whole thing was my fault. I added the following method in my Global.asax file without a Try/Catch or test for existence: When PayPal posts their data, there is no HttpContext. *sigh* Thanks so much for taking the time to share. It's your insistence that a 500 error MUST be an application error that whacked me on the head. Others had said it but for whatever reason, I listened when you did. We can call this issue dead.
Ha - hey, no worries, that's the default belief of pretty much everyone when they have a problem. It's human nature. Thanks for this: "When PayPal posts their data, there is no HttpContext." That will no doubt help someone else down the road.
I'm having the same issue. I built on their provided sample code, but for whatever reason I can't get any values from the form post. I've tried. Request.QueryString["txn_id"].ToString() Request.Form["txn_id"].ToString() HttpContext.Current.Request.QueryString["txn_id"].ToString() HttpContext.Current.Request.Form["txn_id"].ToString() nothing. what am i doing wrong?