gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:54:03 25 4
gpt4 key购买 nike

我会尽量开门见山。我目前正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com