Search code examples
asp.netvb.netpaypalpaypal-ipn

PayPal IPN Listener on my website has started throwing a Guid error when someone pays me on Ebay


Below is my IPN Listener which has always worked fine on my website for customer PayPal payments. It sets up orders for my site in the Guid format (32 digits with 4 dashes). However, I use the same PayPal account for my Ebay selling and I have just sold an item which when paid for, caused the following error:

System.FormatException
Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

In the IPN history the Payment Status is COMPLETED but the HTTP Response Code is 500 and Delivery Status is 'Retrying'. I'm getting email warnings from PayPal about this, which worry me as I need IPN for my website.

I have checked the Ebay transaction and 'Custom' is EBAY_ENSDX00001030330553110 so I'm guessing my IPN code doesn't like that. Is there a way I can keep Ebay transactions away from my IPN Listener within PayPal? Or is there a way I can edit my IPN code below to deal with a custom ID which isn't in the 32 digit format?

IPN Listener..

Imports System.Net
Imports System.IO
Imports System.Net.Cache

Partial Class IPNListener
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, 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://ipnpb.paypal.com/cgi-bin/webscr"

        'SSL Error Code
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

        Dim req As HttpWebRequest = CType(WebRequest.Create(strLive), 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

        '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()

        Dim qscoll As NameValueCollection = HttpUtility.ParseQueryString(strRequest)

        'Insert the paypal response
        Dim order As New orders
        order.InsertPaypalResponse(qscoll("txn_id"), qscoll("custom"), strRequest)

        If strResponse = "VERIFIED" Then
            order.UpdateOrderFromPaypal(qscoll("custom"), qscoll("txn_id"), qscoll("payment_status"))

        ElseIf strResponse = "INVALID" Then
            'log for manual investigation
            order.UpdateOrderFromPaypal(qscoll("custom"), qscoll("txn_id"), qscoll("payment_status"))
        Else
            'Response wasn't VERIFIED or INVALID, log for manual investigation
            order.UpdateOrderFromPaypal(qscoll("custom"), qscoll("txn_id"), "ERROR")
        End If
    End Sub
End Class

Solution

  • In the case of an EBAY transaction, you can simply skip over the verification and exit successfully, since you don't need to do anything with it.

    All PayPal needs you to do is return HTTP 200, so they can mark the IPN as successfully delivered. (The problem is you are currently returning HTTP 500 or similar, causing PayPal to mark the delivery as failed.)


    An alternative solution is to specify your site's notify_url at your website's transaction level, as a parameter in each transaction's API setup (or HTML redirect if no API), which overrides any setting (or lack of a setting) in your PayPal account. Then in your PayPal account you can blank out the IPN listener URL, and you won't get any more IPNs for Ebay transactions.