当有人在 Ebay 上付款时,我网站上的 PayPal IPN Listener 开始抛出 Guid 错误

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

下面是我的 IPN 侦听器,它在我的网站上一直运行良好,用于客户 PayPal 付款。它以 Guid 格式(32 位数字和 4 个破折号)为我的网站设置订单。但是,我使用相同的 PayPal 帐户进行 Ebay 销售,并且我刚刚售出一件商品,付款后导致以下错误:

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

在 IPN 历史记录中,付款状态为已完成,但 HTTP 响应代码为 500,交付状态为 'Retrying'。我收到了来自 PayPal 的电子邮件警告,这让我很担心,因为我的网站需要 IPN。

我检查了 Ebay 交易,'Custom' 是 EBAY_ENSDX00001030330553110,所以我猜我的 IPN 代码不喜欢那样。有没有办法让我在 PayPal 内的 IPN 监听器远离 Ebay 交易?或者有什么方法可以编辑下面的 IPN 代码来处理非 32 位格式的自定义 ID?

IPN 侦听器..

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

在EBAY交易的情况下,您可以跳过验证并成功退出,因为您不需要对其进行任何操作。

PayPal 需要您做的只是 return HTTP 200,这样他们就可以将 IPN 标记为已成功发送。 (问题是您当前正在 returning HTTP 500 或类似的请求,导致 PayPal 将交付标记为失败。)


另一种解决方案是在您网站的交易级别指定您网站的 notify_url,作为每个交易的 API 设置中的参数(或者 HTML 重定向,如果没有 API),它会覆盖您 PayPal 帐户中的任何设置(或缺少设置)。然后在您的 PayPal 帐户中,您可以清空 IPN 侦听器 URL,您将不会再获得任何用于 Ebay 交易的 IPN。