我有一個網站,使用貝寶作爲付款選項的在線交易。結賬和貝寶方面的購物車計算工作正常,但我沒有收到來自貝寶沙箱的任何IPN消息。寫完日誌後,我發現參數formdata爲空。即使使用IPN歷史記錄進行檢查,它也會顯示IPN消息的狀態爲正在重試... IPN通知網址也已設置。 以下是偵聽器代碼。Paypal:IPN監聽器沒有收到IPN消息
[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支付網關的新手,任何幫助將不勝感激。
有沒有人得到這個工作... –