0

我已经设置了 IPN 以在 Paypal 中与我的网站进行通信,但由于某种原因,paypal 似乎没有调用它。下面是正在监听的方法,但它似乎没有得到任何东西。

有人可以指出我的写作方向吗?

谢谢

[HttpPost]
    public void paypalipn(string receiver_email, string receiver_id, string test_ipn, string txn_id, string payer_id, string payer_status, string payment_date, string payment_status, string payment_type)
    {
        string subject = "Audit - Paypal IPN ";
        string buildemail = "receiver_email: " + receiver_email;
        buildemail += "receiver_id: "+receiver_id;
        buildemail += "<br>test_ipn: "+test_ipn;
        buildemail += "<br>txn_id: " + txn_id;
        buildemail += "<br>payer_id: " + payer_id;
        buildemail += "<br>payer_status: " + payer_status;
        buildemail += "<br>payment_date: " + payment_date;
        buildemail += "<br>payment_status: " + payment_status;
        buildemail += "<br>payment_type: " + payment_type;

        Libraries.Email.Product.SendAudit(subject, buildemail);



    }
4

3 回答 3

1

如果您在 PayPal 帐户中设置 IPN,请确保它已启用并且 URL 正确。此外,如果您在您的帐户中设置它,您可以检查您的 IPN 历史记录以查看是否正在发送 IPN POST。它们将被标记为已发送、重试或失败。如果它们处于失败或重试状态,您可以单击该消息,如果您的服务器发送回任何错误代码,则应在此处列出。此外,请检查服务器上的错误日志以确保脚本没有出错。

于 2013-05-28T12:29:07.723 回答
1

我做了这样的事情:

public class IPNData
{
    public string Response { get; set; }
    public NameValueCollection Args { get; set; }
}

然后从请求中收集数据的方法,并将数据发送到 Paypal 进行验证。

IPNData GetIPNData()
{
    var ipnData = new IPNData();
    var param = Request.BinaryRead(HttpContext.Request.ContentLength);
    var ipnStr = Encoding.ASCII.GetString(param);
    ipnData.Args = HttpUtility.ParseQueryString(ipnStr);

    // Return the ipn string to paypal for validation
    ipnStr += "&cmd=_notify-validate";

    var request = (HttpWebRequest)WebRequest.Create("https://www.paypal.com/cgi-bin/webscr");
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = strRequest.Length;

    using (var sw = new StreamWriter(request.GetRequestStream(), Encoding.ASCII))
    {
        sw.Write(ipnStr);
    }

    using (var sr = new StreamReader(request.GetResponse().GetResponseStream()))
    {
        // Response should be "VERIFIED"
        ipnData.Response = sr.ReadToEnd();
    }

    return ipnData;
}

订阅支付的 PaymentController.cs 示例,或者如果用户取消订阅。

public ActionResult PaypalIPNExample()
{
    var ipn = GetIPNData();
    if (ipn.Response != "VERIFIED")
    {
        // Do some logging
        return null;
    }

    var type = ipn.Args["txn_type"];
    var email = ipn.Args["payer_email"];
    var transactionId = ipn.Args["txn_id"];

    switch (type)
    {
        case "subscr_cancel":
            UserService.CancelSubscription(email);
            break;
        case "subscr_payment":
            if (ipn.Args["payment_status"].Equals("Completed"))
            {
                LogPayment(email, transactionId);
                UserService.ExtendMembership(email);
            }
            break;
        default:
            // Do some logging?
            break;                    
    }

    return Json("ok");
}
于 2016-01-23T15:33:51.103 回答
0

当我调试 PayPal IPN 响应时,我做了这样的事情:

string keysReceived = "";
foreach (string key in Request.Params.AllKeys)
   keysReceived += "\r\nKey: " + key + ", Val: " + Request.Params[key];
string debugLogPath = HttpContext.Server.MapPath("/") + "debug_PayPalNotify.log";
System.IO.File.AppendAllText(debugLogPath, keysReceived);

注意全局对象 Request 的使用。你可以用它来做很多调试。

于 2013-10-16T06:10:29.220 回答