简体   繁体   English

贝宝IPN集成问题

[英]Paypal IPN integration issues

I am trying to process the response from paypal on my page. 我正在尝试处理我的页面上来自贝宝的响应。 I found this code from paypal documentation itself. 我从贝宝文档本身中找到了此代码。 When the response is valid, some parameters needs to be processed like txn_id and payment_completed . 当响应有效时,需要处理一些参数,例如txn_idpayment_completed How should i do that?? 我该怎么办? the code is as follows 代码如下

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();
        }
    }

Give me some inputs please. 请给我一些意见。 Thanks 谢谢

After you get the response and you know that is valid, the parameters have been posted to you and you can get them using the .Form For example: 在获得响应并且知道它是有效的之后,参数已经发布给您,您可以使用.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
}

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

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