【发布时间】:2016-11-30 02:33:24
【问题描述】:
我有一个使用贝宝作为付款选项的在线交易网站。 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;
}
这以前可以工作,但不知道是什么阻止了它。 作为贝宝支付网关的新手,我们将不胜感激。
【问题讨论】:
-
有没有人得到这个工作...
标签: asp.net-web-api paypal paypal-ipn paypal-sandbox