【发布时间】:2015-02-18 00:09:49
【问题描述】:
我正在尝试让 IPN 为我的网站工作,但到目前为止没有任何成功。
我已将所有 PayPals 文档涂红,并设置了所有必需的配置以使 IPN 正常工作。
这是我到目前为止所做的:
1、创建开发账号;
2. 将我的网站支付偏好更新为自动退货:开启;
3. 在我的个人资料属性中开启即时付款通知;
4. 创建了一个测试支付选项事件:
protected void btCheckout_Click(object sender, EventArgs e)
{
var queryString = System.Web.HttpUtility.ParseQueryString(string.Empty);
queryString["cmd"] = "_cart";
queryString["business"] = "xpto-facilitator@xpto.com";
queryString["upload"] = "1";
queryString["item_name_1"] = "My Cart Item 1";
queryString["quantity_1"] = "1";
queryString["amount_1"] = "100.00";
queryString["shopping_url"] = "http://xpto.com/Client/Checkout";
queryString["return"] = "http://xpto.com/Client/Checkout";
queryString["notify_url"] = "http://xpto.com/CheckoutResult.aspx";
Response.Redirect("https://www.sandbox.paypal.com/cgi-bin/webscr?" + queryString.ToString());
}
5.创建IPN页面:
protected void Page_Load(object sender, EventArgs e)
{
//Post back to either sandbox or live
string strSandbox = "https://www.sandbox.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 = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
//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();
if (strResponse == "VERIFIED")
{
//log for debugging purposes
LogManager.Error("CheckoutResult VERIFIED:" + strResponse);
}
else if (strResponse == "INVALID")
{
//log for debugging purposes
LogManager.Error("CheckoutResult INVALID: " + strResponse);
}
else
{
//log for debugging purposes
LogManager.Error("CheckoutResult something else: " + strResponse);
}
}
- 我设法继续结帐并成功支付了物品;
- 我的 IPN 页面未执行,因为我没有记录任何内容;
- 用即时付款通知 (IPN) 模拟器测试了我的处理程序,我总是收到以下错误:
由于 HTTP 错误,我们无法发送 IPN:401:未经授权
我究竟做错了什么?我错过了什么吗?
【问题讨论】:
标签: c# asp.net paypal paypal-ipn