Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 the 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


What I have tried:

I have tried looking for any settings on PayPal but unsure if it is possible to exclude transactions outside of my webisite from the IPN Listener. Could I do a check for Guid in the IPN code ?
Posted
Comments
F-ES Sitecore 5-Jun-20 8:28am    
Which line throws the exception?
Member 13779417 5-Jun-20 9:14am    
In the orders.vb code which it calls and then also the line above: order.UpdateOrderFromPaypal(qscoll("custom"), qscoll("txn_id"), qscoll("payment_status"))
F-ES Sitecore 5-Jun-20 9:16am    
Can't you just check if the transaction id begins "EBAY" and not run any of your code if it does?
Member 13779417 6-Jun-20 5:23am    
Thanks for your help. Yes that's an idea. I've added IF LEN(qscoll("custom")) >= 32 THEN to the code to see how that goes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900