0

MVC コントローラー アクションから IPN メッセージを取得しようとしましたが、IPN をアクション コントローラーに送信できません

以下は私のコントローラーアクションです:

                string strLive = "https://www.paypal.com/cgi-bin/webscr";
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strLive);

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

                //for proxy
                //Dim proxy As New WebProxy(New System.Uri("http://url:port#"))
                //req.Proxy = proxy

                //Send the request to PayPal and get the response
                StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
                streamOut.Write(strRequest);
                streamOut.Close();
                StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
                string strResponse = streamIn.ReadToEnd();
                streamIn.Close();

                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
                } else if (strResponse == "INVALID") {
                    //log for manual investigation
                } else {
                    //Response wasn't VERIFIED or INVALID, log for manual investigation
                }

以下は、私が使用したペイパル情報です。

<add key="paypalAccount"    value="abc@abc.com" />
<add key="PayPalSubmitUrl" value="https://www.paypal.com/cgi-bin/webscr"/>
<add key="PDTToken" value="asdfwlfti2Rc_Kskwsdfc7uK26FmT1pdAkhSdLb8FvS2kQ-ZQp6VoF2SqYem"/>
<add key="FromMail" value="myat@abc.com"/>
<add key="return_Url" value="http://testing/Purchase/PayPalResult"/>
<add key="cancel_return" value="http://testing/Purchase/Purchase"/>
<add key="notify_url" value="http://testing/Purchase/PayPalPaymentNotification"/>
<add key="Test_Live" value="live"/>
<add key="BCC" value="myat@abc.com"/>

しかし、paypal の IPN メッセージはまだ再試行中で、何も受信してません。

ありがとうございました

4

3 に答える 3

1

これは、IPN メッセージを取得するための私の完全なアクションです

    public ActionResult PayPalPaymentNotification()
    {
        string strLog = "";
        string currentTime = "";


        currentTime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year + "|" + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();

        strLog = "Insert into CPLog(Log,LogTime) values('Start IPN request','" + currentTime + "')";
        InsertData(strLog);
        string strLive = "https://www.paypal.com/cgi-bin/webscr";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strLive);

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

        //for proxy
        //Dim proxy As New WebProxy(New System.Uri("http://url:port#"))
        //req.Proxy = proxy

        //Send the request to PayPal and get the response
        StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
        streamOut.Write(strRequest);
        streamOut.Close();
        StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
        string strResponse = streamIn.ReadToEnd();
        streamIn.Close();

        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
            currentTime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year + "|" + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();

            strLog = "Insert into CPLog(Log,LogTime) values('Status - Verified','" + currentTime + "')";
            InsertData(strLog);
        }
        else if (strResponse == "INVALID")
        {
            //log for manual investigation
            currentTime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year + "|" + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();

            strLog = "Insert into CPLog(Log,LogTime) values('Status - Invalid','" + currentTime + "')";
            InsertData(strLog);
        }
        else
        {
            //Response wasn't VERIFIED or INVALID, log for manual investigation
        }
        currentTime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year + "|" + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();

        strLog = "Insert into CPLog(Log,LogTime) values('Finish IPN Request','" + currentTime + "')";
        InsertData(strLog);
        return View();
    }
于 2013-08-13T09:42:46.697 に答える
0

リターン URL が正しくありません。メッセージを返すことはできません。

[AllowAnonymous]コントローラー アクションの上に追加します。

于 2013-08-13T08:44:18.707 に答える
0

Paypal は、IPN の送信先を示すリスナー サービスの URL を知る必要があります。Paypal アカウントの IPN 通知セクションを確認し、URL を設定する必要があります。これについては、次のセクションを確認できます: Paypal 開発者と通知 URL の設定。

その後、受け取るには支払い通知が必要です。私のお勧めは、最初に、このアプリケーションのテストに使用できる偽のアカウントの王様であるサンドボックスでPaypal 開発者セクションを使用することです。

于 2016-02-18T23:37:53.840 に答える