簡體   English   中英

ASP.NET Paypal IPN返回驗證但IPN無法發送

[英]ASP.NET Paypal IPN returning VERIFIED but IPN Fails to Send

我會盡力直截了當。 我目前正在使用PayPal IPN,之前從未見過這個問題。 我使用過PayPal 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中得到了“VERIFIED”。 這反過來導致每個事務最多8個記錄。 paypal報告的錯誤是500 - 內部服務器錯誤。 任何幫助都會被瘋狂地欣賞,因為到目前為止這是一場為期2天的抨擊馬拉松比賽!

感謝您的幫助或解決方案!

PS我幾乎已經閱讀了stackoverflow上的每個IPN問題,並且沒有看到這樣的東西。

如果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();
    }

//你可能知道這一點,但對於其他人來說,這是一個示例流程

  1. PayPal付款/交易
  2. 為PayPal交易配置IPN地址,然后發布到IPN地址,即:http: //yourdomain.com/IPN.aspx
  3. IPN.aspx處理IPN帖子並將PaypalPaymentHistory寫入db。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM