c# - ASP.NET Paypal IPN 返回 VERIFIED 但 IPN 发送失败

标签 c# asp.net paypal paypal-ipn

我会尽量开门见山。我目前正在使用 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 中得到“已验证”。这反过来导致每笔交易最多 8 条记录。 paypal 报告的错误是 500 - Internal Server Error。任何帮助将不胜感激,因为到目前为止,这是一场为期 2 天的猛烈抨击马拉松!

感谢任何帮助或解决方案!

P.S 我已经阅读了关于 stackoverflow 的几乎所有 IPN 问题,但从未见过这样的问题。

最佳答案

如果 PayPal 报告 500,您的 Controller 操作将失败。您需要调试该代码并查看失败的原因。如果您的 Controller 没有发回 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 post 并将 PaypalPaymentHistory 写入数据库。

关于c# - ASP.NET Paypal IPN 返回 VERIFIED 但 IPN 发送失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8232309/

相关文章:

c# - 如何检索路径为动态的属性的 json 值

c# - Datagridview 到特定的 excel 单元格

asp.net - 有条件地在 HTML 元素上设置 Disabled 和 Checked 属性

c# - Linq to XML - 将 CDATA 呈现为 HTML

php - 如何使用 MySQL 手动跟踪 Wordpress 中的沙箱 Paypal 重复交易

javascript - Paypal 与 Braintree 的集成

c# - 按 namespace 对列表进行排序

asp.net - pubxml web 发布工具 事件生命周期

paypal - paypal order id的有效期是多久?

c# - XAML - ListViewItem - IsEnabled 绑定(bind)