【问题标题】:Paypal IPN returns INVALID responsePaypal IPN 返回无效响应
【发布时间】:2012-04-26 09:46:20
【问题描述】:
{Following is the vb.net code for IPN listener:
    If Me.TestMode = True Then
            Me.RequestUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr"
        Else
            Me.RequestUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr" '"https://www.paypal.com/cgi-bin/webscr"
        End If



        '====================================Test======================================'
        Dim startTime As String = String.Format("{0:MM-dd-yyyy hh:mm:ss:tt}", Now)
        '=============================================================================='

        Dim req As HttpWebRequest = CType(WebRequest.Create(Me.RequestUrl), HttpWebRequest)
        req.Method = "POST"
        req.ContentType = "application/x-www-form-urlencoded"
        Dim Param() As Byte = HttpContext.Current.Request.BinaryRead(HttpContext.Current.Request.ContentLength)
        Dim strRequest As String = Encoding.ASCII.GetString(Param)
        strRequest = strRequest & "&cmd=_notify-validate"
        req.ContentLength = strRequest.Length
        ' Dim pairs() As String = strRecieved.Split("&")
        Using streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
            streamOut.Write(strRequest.ToString)
            streamOut.Close()
        End Using
        Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
        Dim strResponse As String = streamIn.ReadToEnd()
        streamIn.Close()
        WriteLog(strResponse)

我已经在 vb.net 中完成了 paypal IPN 监听器的代码。当我使用 paypal 沙盒帐户测试该 url 时,它显示以下消息: “IPN发送成功。” 但是当我在服务器上检查我的日志文件时,它会显示来自贝宝沙箱 url 的无效响应。如果没有 VALID 响应,我的其他代码将无法工作。 请帮忙!!

【问题讨论】:

  • IPN 消息会在 paypal 交易发生任何事件时发送。 ipn 消息出现“IPN 成功发送”的方式和位置。
  • 当我用贝宝沙盒模拟器测试它时。当时我收到“IPN 成功发送”消息。
  • 在paypal沙箱上做一个测试交易,这样paypal就会给你发送有效状态的ipn响应。
  • 当我在将控制权从我的网站迁移到贝宝时指定“notify_url(IPN url here)”时它开始工作。但是通过这样做,我得到了 payment_status=pending,虽然我已经付款了。你能帮我解决这个问题吗?
  • 我正在发布代码,它可以帮助您生成 paypal 支付链接,一旦交易完成,您将得到正确的 ipn 响应。

标签: vb.net paypal-ipn


【解决方案1】:

生成 paypal 交易,例如通过 vb.net 立即购买按钮

Public Shared Function GetPayPalPaymentUrl(item_name As String, item_number As String, amount As String, quantity As String, username As String) As String
Dim strURL As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
If PaypalBLL.Paypal_Live_Status() = 1 Then
    strURL = "https://www.paypal.com/cgi-bin/webscr"
End If
Dim BaseUrl As String = Config.GetUrl()
Dim cancel_url As String = BaseUrl + "paypal/cancel.aspx"
Dim return_url As String = BaseUrl + "paypal/confirmation.aspx"
Dim notifyUrl As String = BaseUrl + "paypal/ipn.aspx"
'string image_url = ""
Dim image_url As String = ""
' paypal header url
Dim paypal_logo As String = HttpUtility.UrlEncode(BaseUrl + "images/logo.png")
Dim Url As New StringBuilder()
Dim CustomFieldValue As String = username
'User-defined field which PayPal passes through the system and returns to you in your merchant payment notification email. Subscribers do not see this field.
Url.Append(strURL + "?cmd=_xclick&upload=1&rm=2&no_shipping=1&no_note=1&currency_code=USD&business=" + PaypalBLL.Paypal_Receiver_Email() + "&item_number=" + item_number + "&item_name=" + item_name + "&amount=" + amount + "&quantity=" + quantity + "&undefined_quantity=0&notify_url=" + notifyUrl + "&return=" + return_url + "&cancel_return=" + cancel_url + "&cpp_header_Image=" + image_url + "&cpp_headerback_color=ECDFDF&cpp_headerborder_color=A02626&cpp_payflow_color=ECDFDF&image_url=" + paypal_logo + "&custom=" + CustomFieldValue + "")
Return Url.ToString()
End Function

生成 paypal 链接,当您点击链接时,您将被重定向到 paypal 沙箱或实时链接。完成交易后,您将被重定向回网站,并且在后台 paypal 将通过 ipn 发送交易事件。

希望您能收到正确的 ipn 响应。

【讨论】:

  • 我已经完成了所有这些代码并且工作正常,现在问题来了,当我付款时我收到 IPN 响应为“payment_status=Pending”。如果没有“完成”状态,我将无法继续。
  • well payment_status=paypal发送的pending,那么trasaction应该处于pending状态。在贝宝交易详情页面查看交易状态。
  • 交易处于待处理阶段,pending_reason=unilateral。我正在谷歌上搜索它来解决它。
  • 单方面:付款待处理,因为它是发送到一个尚未注册或确认的电子邮件地址。请确保您通过 developer.paypal.com 创建了测试电子邮件地址并正确使用它进行交易。
  • 是的,Irfan 这是唯一的原因,非常感谢您的及时支持。
猜你喜欢
  • 2011-10-26
  • 2018-10-29
  • 2016-11-28
  • 2017-12-15
  • 2010-12-01
  • 2014-10-21
  • 1970-01-01
  • 2013-01-20
相关资源
最近更新 更多