简体   繁体   English

PayPal IPN侦听器不起作用

[英]PayPal IPN Listener not working

So, I've read the IPN documentation and I've read tons of examples that I've found. 因此,我阅读了IPN文档,并阅读了许多示例。 I've tried a few different solutions, and after them not working, I've simply copy and pasted exactly what is documented on the PayPal IPN page. 我尝试了几种不同的解决方案,但在它们无法使用后, 我只复制并粘贴了PayPal IPN页面上记录的内容。 As such, it's STILL not working. 因此,它仍然无法正常工作。 My IPN History shows that it's continuing to resend the message. 我的IPN历史记录表明它正在继续重新发送消息。 Code below - what is missing? 下面的代码-缺少什么?

protected void Page_Load(object sender, EventArgs e)
    {
        const string postUrl = "https://www.paypal.com/cgi-bin/webscr";
        var req = (HttpWebRequest)WebRequest.Create(postUrl);

        //Set values for the request back
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        var param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
        var strRequest = Encoding.ASCII.GetString(param);
        var ipnPost = strRequest;
        strRequest += "&cmd=_notify-validate";
        req.ContentLength = strRequest.Length;

        //for proxy
        //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
        //req.Proxy = proxy;

        //Send the request to PayPal and get the response
        var streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
        streamOut.Write(strRequest);
        streamOut.Close();

        // ReSharper disable AssignNullToNotNullAttribute
        var streamIn = new StreamReader(req.GetResponse().GetResponseStream());
        // ReSharper restore AssignNullToNotNullAttribute
        var strResponse = streamIn.ReadToEnd();
        streamIn.Close();

        // logging ipn messages... be sure that you give write
        // permission to process executing this code
        //

        if (strResponse == "VERIFIED")
        {
            //check the payment_status is Completed
            //check that txn_id has not been previously processed
            //check that receiver_email is your Primary PayPal email
            //check that payment_amount/payment_currency are correct
            //process payment
            var mailer = new Emailer();
            mailer.SendMail("from@domain.com", "to@domain.com", "Thank you!",
                            "Thank you for your sponsorship. Good luck on your results!<br /><br />" + ipnPost);
        }
        else if (strResponse == "INVALID")
        {
            //log for manual investigation
        }
    }

Turns out it was an error with my email sender. 原来这是我的电子邮件发件人的错误。 The address I was sending from was not verified in my AWS account. 我发送的地址未在我的AWS账户中得到验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM