【问题标题】:ASP.NET Paypal IPN returning VERIFIED but IPN Fails to SendASP.NET Paypal IPN 返回已验证但 IPN 无法发送
【发布时间】:2012-01-04 03:53:04
【问题描述】:

我会尽量直截了当。我目前正在使用 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 条记录。贝宝报告的错误是 500 - 内部服务器错误。任何帮助都将不胜感激,因为到目前为止,这是一场为期 2 天的头颅马拉松!

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

P.S 我几乎阅读了有关 stackoverflow 的所有 IPN 问题,但没有看到类似的内容。

【问题讨论】:

    标签: c# asp.net paypal paypal-ipn


    【解决方案1】:

    如果 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. IPN 地址为 PayPal 交易配置然后发布到 IPN 地址,即:http://yourdomain.com/IPN.aspx
    3. IPN.aspx 处理 IPN 帖子并将 PaypalPaymentHistory 写入 db。

    【讨论】:

    • 我有控制器调用该功能 WWW.site.com/payment/processpayment 是贝宝 ipn 框中的链接
    • 我从 paypal 获得内陆地区显示已验证,但 paypal 显示失败并不断将帖子退到我的控制器操作 ProcessPayment 调用 MakeHttpPost
    • 控制器非常简单,里面只有我的对象 PPIPN PP = new PPIPN("TEST") 和 PP.MakeHttpPost()。我不明白它怎么会失败。 mysite.com/payment/processpayment这不是输入paypal的正确IPN地址吗?非常感谢您的帮助 Rick。
    • 取出该代码或尝试捕获它,看看会发生什么,500 是您的服务器代码失败。
    • IPN 发送成功。非常感谢 Rick,你在不知道确切问题的情况下向我展示了我的问题。我觉得自己像个彻头彻尾的白痴,但我想这就是当你在一个问题上看得太久时会发生的事情。问题是我的控制器正在调用 ProcessPayment() 然后返回一个空白视图,但是该视图不是在付款视图文件夹下创建的,这导致它返回 500 而不是 200。问题 110% 已解决。非常感谢!
    猜你喜欢
    • 2017-02-17
    • 1970-01-01
    • 2016-05-27
    • 2014-01-15
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 2016-11-28
    • 2018-08-09
    相关资源
    最近更新 更多