【问题标题】:PayPal IPN Listener - HTTP Response Code 500PayPal IPN 侦听器 - HTTP 响应代码 500
【发布时间】:2021-12-31 16:08:39
【问题描述】:

这个错误经常在我的网站上发生。现在已经正常工作了大约 6 个月,但现在决定再做一次。

我使用 1&1 ionos 托管。该网站使用 asp.net 和 vb.net 作为代码。它是一个在线食品配送网站,我通过复制和更改在另一个网站上为我编写的一些代码来建立自己。该站点仍然可以正常工作,并且由另一家公司托管,因此我不知道它是否与 ionos 有关。当客户订购时,付款在我的 PayPal 中清除,但它没有告诉我的网站它已清除,因为 ipn 正在重试 HTTP 500 错误。

调用贝宝的VB代码

    Dim paypalURLString As String = "https://www.paypal.com/cgi-bin/webscr?" ' Live
    Dim paypalParameterString As New StringBuilder
    paypalParameterString.Append("cmd=_xclick&")
    paypalParameterString.Append("notify_url=https://bozzafodder.co.uk/IPNListener.aspx&") 'POST address for notification
    paypalParameterString.Append("bn=SlikkDesign_BuyNow_WPS_GB&")
    paypalParameterString.Append("amount=" & session("total") + 1 + session("deliveryCharge") + ddlTip.SelectedValue & "&")
    paypalParameterString.Append("item_name=Food Delivery&")
    paypalParameterString.Append("currency_code=GBP&")
    paypalParameterString.Append("custom=" & imgBtnPaypal.CommandArgument.ToString & "&")
    paypalParameterString.Append("custom=" & order.orderID.ToString & "&")
    paypalParameterString.Append("business=E4RYLU66FFE3L&") 'Live
    paypalParameterString.Append("paymentaction=sale&")
    paypalParameterString.Append("return=https://bozzafodder.co.uk/wait.aspx?orderID=" & order.orderID.ToString & "&")
    paypalParameterString.Append("cancel_return=https://bozzafodder.co.uk/placeOrder.aspx?msgID=1&")
    paypalParameterString.Append("rm=2&")
    paypalParameterString.Append("cbt=Return to bozzafodder.co.uk&")

    Dim displayParameters As New StringBuilder
    displayParameters.Append("showHostedThankyouPage=false")

    Response.Redirect(paypalURLString & paypalParameterString.ToString & displayParameters.ToString)

IPN 监听器

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    'Post back to either sandbox or live
    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)

    If LEN(qscoll("custom")) >= 32 Then
        '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 If
End Sub

结束类

在所附照片中,您可以看到 PayPal IPN 历史记录中的错误。发送的那些来自我的其他网站,在不同的网站上运行良好。不过IPN码是一样的,我对比了2个。

【问题讨论】:

    标签: asp.net vb.net paypal-ipn


    【解决方案1】:

    在尝试验证 IPN 时,您的 IPN 侦听器“无法连接到远程服务器”,因此返回 500 HTTP 状态。

    您的 IPN 侦听器必须返回 2xx HTTP 状态,才能将 IPN 标记为成功接收。 PayPal 最多会重试 20 次,直到发生这种情况,然后如果您的听众仍然没有 2xx 成功响应,则将 IPN 标记为失败。

    由于错误是“无法连接到远程服务器”,因此您必须在您的环境(侦听器代码和服务器)中进行调查和调试。为什么连接不上https://ipnpb.paypal.com/cgi-bin/webscr?cmd=_notify-validate

    【讨论】:

    • 感谢您的回复。不确定该去哪里,因为我还在学习。该代码已经工作了几个月,我的目的没有任何改变。这听起来像是 ionos 的问题吗?也许证书或其他东西发生了变化?还是有什么事情改变了 PayPal 的结局?
    • 真的不能说,需要调试连接。为什么连接不上?
    猜你喜欢
    • 2020-06-04
    • 2014-02-26
    • 2012-05-20
    • 2012-05-04
    • 2021-03-13
    • 2012-10-09
    • 2016-04-13
    • 2019-06-22
    • 1970-01-01
    相关资源
    最近更新 更多