2011-11-22 91 views
9

我會盡力讓您明白這一點。我目前正在使用PayPal IPN,並且從未見過此問題。我已經使用PayPal IPN,並且我的實施始終如一。但是這次它產生了一些非常奇怪的結果。ASP.NET Paypal IPN返回VERIFIED,但IPN無法發送

我目前正在與WinHost.com託管

代碼中使用:

public void MakeHttpPost() 
    { 

     ErrorLog log = new ErrorLog(); 
     //Post back to either sandbox or live 
     string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr"; 
     string strLive = "https://www.paypal.com/cgi-bin/webscr"; 
     HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox); 

     //Set values for the request back 
     req.Method = "POST"; 
     req.ContentType = "application/x-www-form-urlencoded"; 
     byte[] param = HttpContext.Current.Request.BinaryRead(HttpContext.Current.Request.ContentLength); 
     string strRequest = Encoding.ASCII.GetString(param); 
     strRequest += "&cmd=_notify-validate"; 
     req.ContentLength = strRequest.Length; 

     //for proxy 
     //WebProxy proxy = new WebProxy(new Uri("http://url:port#")); 
     //req.Proxy = proxy; 

     //Send the request to PayPal and get the response 
     StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); 
     streamOut.Write(strRequest); 
     streamOut.Close(); 
     StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); 
     string strResponse = streamIn.ReadToEnd(); 
     streamIn.Close(); 
     log.error = strResponse; 
     log.Insert(); 

     if (strResponse == "VERIFIED") 
     { 
      PaypalPaymentHistory PPH = new PaypalPaymentHistory(); 

      PPH.LastName = HttpContext.Current.Request["last_name"]; 
      PPH.FirstName = HttpContext.Current.Request["first_name"]; 
      PPH.State = HttpContext.Current.Request["address_state"]; 
      PPH.Zipcode = HttpContext.Current.Request["address_zip"]; 
      PPH.Address = HttpContext.Current.Request["address_street"]; 
      PPH.UserName = HttpContext.Current.Request["option_name2"]; 
      PPH.PaymentStatus = HttpContext.Current.Request["payment_status"]; 
      PPH.SelectedPackage = HttpContext.Current.Request["option_selection1"]; 
      PPH.PayerStatus = HttpContext.Current.Request["payer_status"]; 
      PPH.PaymentType = HttpContext.Current.Request["payment_type"]; 
      PPH.PayerEmail = HttpContext.Current.Request["payer_email"]; 
      PPH.ReceiverId = HttpContext.Current.Request["receiver_id"]; 
      PPH.TxnType = HttpContext.Current.Request["txn_type"]; 
      PPH.PaymentGross = HttpContext.Current.Request["payment_gross"]; 

      PPH.Insert(); 

     } 
     else if (strResponse == "INVALID") 
     { 
      //log for manual investigation 
     } 
     else 
     { 
      //log response/ipn data for manual investigation 
     } 

    } 

這裏的想法是,我會檢查訂單的狀態,然後插入或者未插入記錄到數據庫但是這個代碼仍然在測試中,所以沒有任何官方的。

我遇到的問題是,當我通過沙箱運行並通過我的網站付款時,PayPal發出IPN請求。條目被扔到數據庫中,並且所有的數據都被正確地發回,但PayPal顯示IPN發佈「失敗」,並且總是停留在「重試」上。但是我在strResponse中得到了「驗證」。這又導致每筆交易最多8條記錄。 PayPal報告的錯誤是500 - 內部服務器錯誤。任何幫助將被瘋狂讚賞,因爲這是一個爲期兩天的撲頭馬拉松比賽!

感謝您的任何幫助或決議!

P.S我已經閱讀了幾乎每個有關stackoverflow的IPN問題,並沒有見過這樣的東西。

回答

6

如果PayPal報告500,您的控制器操作失敗。您需要調試該代碼並查看失敗的原因。如果您的控制器未返回200,PayPal將繼續嘗試。

我總是這樣做:

public ActionResult IPN() 
    {  
     //try catch log all my payment info 

     //always return blank page so paypal gets a HTTP 200 
     return View(); 
    } 

//你可能知道這一點,但對於其他人,這裏有一個例子處理流程到PayPal

  • IPN地址發

    1. 支付/交易配置爲PayPal交易,然後發佈到IPN地址,即:http://yourdomain.com/IPN.aspx
    2. IPN.aspx處理IPN帖子並將PaypalPaymentHistory寫入數據庫。
  • +0

    我有控制器,調用該功能WWW.site.com/payment/processpayment這是PayPal ipn框中的鏈接 – jhartzell

    +0

    我從貝寶顯示驗證內灣,但是,貝寶顯示失敗,並不斷退休我的控制器操作ProcessPayment調用MakeHttpPost – jhartzell

    +0

    該控制器是非常裸露的骨頭,唯一的是它是我的對象PPIPN PP =新的PPIPN(「測試」),然後PP.MakeHttpPost()。我不明白它可能會失敗。 http://www.mysite.com/payment/processpayment 這是不是一個正確的IPN地址輸入貝寶? 真的很感謝你的幫助瑞克。 – jhartzell