本文介绍了贝宝IPN的集成问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想处理来自贝宝我的网页上的响应。我发现来自PayPal的文档本身这个code。当响应是有效的,有些参数需要像 txn_id
和 payment_completed
进行处理。我应该怎么做?
在code是如下:
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
. 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:
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
}
这篇关于贝宝IPN的集成问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!