我有一个在线交易网站,使用 Paypal 作为支付选项。 Paypal 端的结帐和购物车计算正常,但我没有收到来自 Paypal 沙箱的任何 IPN 消息。写入日志后,我发现参数 formdata 为空。即使检查了 IPN 历史记录,它也显示 IPN 消息的状态为正在重试... IPN 通知 url 也已设置。 下面是监听器代码。
[Route("IPN")]
public IHttpActionResult IPN(FormDataCollection formData)
{
var formVals = new Dictionary<string, string>();
formVals.Add("cmd", "_notify-validate");
string response = GetPayPalResponse(formVals, formData);
if (response.ToUpper().Trim() == "VERIFIED")
{
//entry into database
}
else
{
return InternalServerError();
}
return InternalServerError();
}
string GetPayPalResponse(Dictionary<string, string> formVals, FormDataCollection formData)
{
string paypalUrl = GetPayPalURL();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(paypalUrl);
// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
Encoding encoding = Encoding.UTF8;
StringBuilder sb = new StringBuilder();
foreach (var entry in formData.ToList())
{
sb.AppendFormat("{0}={1}&", entry.Key, encoding.GetString(encoding.GetBytes(entry.Value)));
}
string strRequest = sb.ToString();
strRequest += "cmd=_notify-validate";
req.ContentLength = strRequest.Length;
//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream());
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
return strResponse;
}
这之前是有效的,但不知道是什么阻止了它。 作为 paypal 支付网关的新手,我们将不胜感激任何帮助。
最佳答案
从昨天开始,paypal 就出现了一定的问题。我希望这是一个暂时性的问题,它会尽快得到解决。我自己在沙盒方面遇到了问题,但以前也发生过。
关于asp.net-web-api - Paypal :IPN 监听器未收到 IPN 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38589960/