C# ASP.NET Paypal IPN返回已验证,但IPN无法发送
我会尽量直截了当地说。我目前与PayPal IPN合作,以前从未见过这个问题。我使用了PayPal IPN,我的实现一直都是一样的。然而,这一次它产生了一些非常奇怪的结果 我目前在WinHost.com上托管 使用的代码:C# ASP.NET Paypal IPN返回已验证,但IPN无法发送,c#,asp.net,paypal,paypal-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 strS
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 Post“失败”,并且总是停留在“重试”状态。然而,我得到了“验证”回复。这反过来又会导致每个事务最多8条记录。paypal报告的错误是500-内部服务器错误。任何帮助都将被疯狂地感谢,因为到目前为止,这是一场为期2天的打击头部的马拉松
谢谢你的帮助和决心
另外,我已经阅读了几乎所有关于stackoverflow的IPN问题,但没有看到类似的问题。如果PayPal报告
500
,您的控制器操作将失败。您需要调试该代码并查看失败的地方。如果您的控制器没有发回200
,贝宝将继续尝试
我总是这样做:
public ActionResult IPN()
{
//try catch log all my payment info
//always return blank page so paypal gets a HTTP 200
return View();
}
//您可能知道这一点,但对于其他人来说,这里是一个流程流程示例
我有一个调用该函数的控制器WWW.site.com/payment/processpayment,它是paypal ipn框中的链接我正在从paypal获取outback showing验证,但是paypal显示失败,并不断取消向我的控制器发送操作processpayment,它调用MakeHttpPost控制器非常简单,其中唯一包含的是我的对象PPIPN PP=new PPIPN(“TEST”),然后是PP.MakeHttpPost()。我不明白它怎么会失败。这不是输入paypal的正确IPN地址吗?真的很感谢你的帮助,瑞克。拿出代码,或者尝试捕获它,看看会发生什么,500是你的服务器代码失败。IPN成功发送。非常感谢你,瑞克,你在不知道确切问题的情况下向我展示了我的问题。我觉得自己是个十足的白痴,但我想,当你对一个问题的眼光太长的时候,就会发生这种情况。问题是我的控制器调用ProcessPayment(),然后返回一个空白视图,但是该视图不是在Payment View文件夹下创建的,这导致它返回的是500而不是200。问题解决了110%。非常感谢你!