gpt4 book ai didi

c# - PayPal 即时付款通知 (IPN) 不工作 ASP.NET C#

转载 作者:太空宇宙 更新时间:2023-11-03 13:13:15 25 4
gpt4 key购买 nike

我正在尝试让 IPN 为我的网站工作,但直到现在都没有成功。

我已经修改了所有 PayPal 文档,并且设置了所有必需的配置以使 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);
}
}
  1. 我设法继续结帐并成功支付了元素;
  2. 我的 IPN 页面没有执行,因为我没有任何记录;
  3. 使用即时支付通知 (IPN) 模拟器测试了我的处理程序,我总是收到以下错误:

We could not send an IPN due to an HTTP error: 401: Unauthorized


我究竟做错了什么?我错过了什么吗?

最佳答案

您为 IPN 指定的 notify_url 设置为需要登录的端点。

queryString["notify_url"] = "http://xpto.com/CheckoutResult.aspx";

此 URL 必须设置为可以接受和处理来自 IPN 服务的 POST 请求而无需任何登录的端点(我似乎找不到任何专门提到此要求的文档)。这就是为什么必须验证您的监听器收到的 IPN(您看起来做得正确)的主要原因,因为在验证之前,无法完全相信收到的请求是由 PayPal 发送的。

关于c# - PayPal 即时付款通知 (IPN) 不工作 ASP.NET C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27559565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com