2012-04-14 142 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