2012-04-14 138 views
0
{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沙箱帐户测试该网址时,会显示以下消息: “IPN已成功发送。” 但是,当我检查我的日志文件在服务器上,然后显示INVALID从贝宝沙箱网址的响应。没有VALID回应我的其他代码将无法正常工作。 请帮忙!!Paypal IPN返回INVALID响应

+0

当PayPal交易发生任何事件时发送IPN消息。 IPN消息如何以及在哪里出现“IPN成功发送”。 – irfanmcsd 2012-04-14 03:55:22

+0

当我用贝宝沙箱模拟器测试它。那时我正在收到“IPN成功发送”的消息。 – 2012-04-14 04:08:31

+0

在PayPal沙盒上做一次测试交易,这样PayPal会发送给您有效状态的ipn响应。 – irfanmcsd 2012-04-14 04:46:40

回答

0

生成PayPal交易就像现在e.g通过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链接,当你点击链接,你会重定向到贝宝沙箱或活链接。一旦你完成交易,你将被重定向到网站和后台贝宝将通过ipn发送交易事件。

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

+0

我已经完成了所有这些代码,并且工作正常,现在问题出现在我付款后,我收到了IPN响应为“payment_status = Pending”。没有获得“完成”的地位,我不能继续前进。 – 2012-04-14 06:22:18

+0

well payment_status =贝宝发送的待处理邮件,则交易应处于待处理状态。检查贝宝交易详情页面中的交易状态。 – irfanmcsd 2012-04-14 06:31:08

+0

交易处于pending_reason =单边的待处理阶段。我用谷歌搜索来整理它。 – 2012-04-14 07:04:12