【发布时间】: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