【问题标题】:Paypal IPN integration issuesPaypal IPN 集成问题
【发布时间】:2012-04-08 18:41:15
【问题描述】:

我正在尝试在我的页面上处理来自贝宝的响应。我从贝宝文档本身找到了这段代码。当响应有效时,需要处理一些参数,如txn_idpayment_completed。我该怎么做? 代码如下

string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
        // string strLive = "https://www.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;

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

        //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")
        {

            //UPDATE YOUR DATABASE

            //TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt");
            //txWriter.WriteLine(strResponse);
            //txWriter.Close();

            //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")
        {
            //UPDATE YOUR DATABASE

            //TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt");
            //txWriter.WriteLine(strResponse);
            ////log for manual investigation
            //txWriter.Close();
        }
        else
        {  //UPDATE YOUR DATABASE

            //TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt");
            //txWriter.WriteLine("Invalid");
            ////log response/ipn data for manual investigation
            //txWriter.Close();
        }
    }

请给我一些意见。谢谢

【问题讨论】:

    标签: asp.net c#-4.0 paypal-ipn


    【解决方案1】:

    在您得到响应并且您知道这是有效的之后,参数已经发布给您,您可以使用.Form 获取它们例如:

    if (strResponse == "VERIFIED")
    {
        // Now All informations are on
        HttpContext.Current.Request.Form;
        // for example you get the invoice like this
        HttpContext.Current.Request.Form["invoice"] 
        // or the payment_status like
        HttpContext.Current.Request.Form["payment_status"] 
    }
    else
    {
      //log for manual investigation
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-06
      • 2016-12-30
      • 2010-12-09
      • 2011-09-01
      • 1970-01-01
      • 2017-12-26
      • 2014-07-31
      • 2011-08-19
      • 2018-04-12
      相关资源
      最近更新 更多