PayPal IPN - 500 Error

Discussion in 'General troubleshooting' started by skrile, Jun 6, 2011.

  1. 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 ( 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?

    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 = ""
            Dim strLive As String = ""
            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)
            Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
            Dim strResponse As String = streamIn.ReadToEnd()
            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
                'Response wasn't VERIFIED or INVALID, log for manual investigation
            End If
        End Sub
    End Class
    Last edited by a moderator: Oct 14, 2015
  2. Have you told them this? What did they say?

    Does their test page give you any other information?
  3. 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
  4. Let us know if you're still getting that 500 error.
  5. 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.
  6. BTW. The link I posted a few back IS NOT the issue. That discussion was talking about a different issue. :(
  7. Ray


    --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?
  8. My code never even executes. I have peppered the code with error handling all over the place and not a thing.
  9. Ray


    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.
  10. 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: - Live IPN - - Live IPN - - Live IPN - - Live IPN - (back up)

    Using your string I a was also to verify the IPN as well.
  11. Ray


    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.
  12. 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.


    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.
    Last edited by a moderator: Oct 14, 2015
  13. 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.
    Last edited: Oct 14, 2015
  14. 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.



    what am i doing wrong?

Share This Page