紧急求助啊!!
我的网站想和paypal集成,不是国内的贝宝,而是paypal。
我现在已经在我的网站上放了一个按钮,并且可以正常购买东西。我用的buyer账号购买东西,然后用seller账号登陆,已经可以看到正常收到钱了。但是有一个很大的问题,就是我的网站无法正确接收到付款信息,无法存入数据库。
我先说说我的步骤,大家帮帮忙吧:1、我的测试页面代码,仅aspx页面有代码,cs页面为空<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="item_name" value="Item Name Goes Here">
<input type="hidden" name="item_number" value="Item Number Goes Here">
<input type="hidden" name="amount" value="20.00">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="IC_Sample">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" name="submit" alt="Make payments with payPal - it's fast, free and secure!">
<img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
2、paypal官方有两个地方设置返回页面,第一个是“即时付款通知习惯设定”也就是“Instant Payment Notification Preferences ” 我的返回页面设置为Notification URL:ipn.aspx。Message deliveryEnabled。这个设置应该没有问题吧?我的ipn代码为,aspx页面就是几个框,不提了。cs页面如下:public partial class ipn : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (VerifyIPN())//验证成功
{
string ppTx = Request.Form["txn_id"].ToString();
string ppStatus = Request.Form["payment_status"].ToString();
string ppDate = Request.Form["payment_date"].ToString();
string ppItem = Request.Form["item_name"].ToString();
string ppPrice = Request.Form["mc_gross"].ToString();
this.TextBox1.Text = ppTx;
this.TextBox2.Text = ppStatus;
this.TextBox3.Text = ppDate;
this.TextBox4.Text = ppItem;
this.TextBox5.Text = ppPrice;
HttpCookie cookie = new HttpCookie("Info");//定义cookie对象以及名为Info的项
DateTime dt = DateTime.Now;//定义时间对象
TimeSpan ts = new TimeSpan(1, 0, 0, 0);//cookie有效作用时间,具体查msdn
cookie.Expires = dt.Add(ts);//添加作用时间
cookie.Values.Add("ppTx", ppTx);//增加属性
cookie.Values.Add("ppStatus", ppStatus);
cookie.Values.Add("ppDate", ppDate);
cookie.Values.Add("ppItem", ppItem);
cookie.Values.Add("ppPrice", ppPrice);
Response.AppendCookie(cookie);//确定写入cookie中 读取cookie
}
else
{ }
}
//////////////////////////////////////////////////////////////////////////
bool VerifyIPN()
{
string strFormValues = Request.Form.ToString();
string strNewValue;
string strResponse;
string serverURL = "https://www.sandbox.paypal.com/cgi-bin/webscr"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(serverURL);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
strNewValue = strFormValues + "&cmd=_notify-validate";
req.ContentLength = strNewValue.Length; StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close(); StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close(); return strResponse == "VERIFIED";
}
}
3、paypal还有一个设置,“Website Payment Preferences ”,“网站付款习惯设定”。我这里设置的是:自动返回: 开启。返回 URL:OK.html。我的ok.html代码:<body>
<p>
That's OK!</p>
</body>
以上就是全部设置了,我测试的过程是这样的,首先点击购买按钮,然后跳到paypal去,然后输入测试账号付款,然后系统调到这么一个url:http://www.cgunited.com/OK.html?tx=3G514512SP293070L&st=Pending&amt=20.00&cc=USD&cm=&item_number=Item Number Goes Here
页面显示的内容是:That's OK!我登陆paypal发现付款成功了,但是为何我的cookie里面却没有写入任何信息呢?
我的网站想和paypal集成,不是国内的贝宝,而是paypal。
我现在已经在我的网站上放了一个按钮,并且可以正常购买东西。我用的buyer账号购买东西,然后用seller账号登陆,已经可以看到正常收到钱了。但是有一个很大的问题,就是我的网站无法正确接收到付款信息,无法存入数据库。
我先说说我的步骤,大家帮帮忙吧:1、我的测试页面代码,仅aspx页面有代码,cs页面为空<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="item_name" value="Item Name Goes Here">
<input type="hidden" name="item_number" value="Item Number Goes Here">
<input type="hidden" name="amount" value="20.00">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="IC_Sample">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" name="submit" alt="Make payments with payPal - it's fast, free and secure!">
<img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
2、paypal官方有两个地方设置返回页面,第一个是“即时付款通知习惯设定”也就是“Instant Payment Notification Preferences ” 我的返回页面设置为Notification URL:ipn.aspx。Message deliveryEnabled。这个设置应该没有问题吧?我的ipn代码为,aspx页面就是几个框,不提了。cs页面如下:public partial class ipn : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (VerifyIPN())//验证成功
{
string ppTx = Request.Form["txn_id"].ToString();
string ppStatus = Request.Form["payment_status"].ToString();
string ppDate = Request.Form["payment_date"].ToString();
string ppItem = Request.Form["item_name"].ToString();
string ppPrice = Request.Form["mc_gross"].ToString();
this.TextBox1.Text = ppTx;
this.TextBox2.Text = ppStatus;
this.TextBox3.Text = ppDate;
this.TextBox4.Text = ppItem;
this.TextBox5.Text = ppPrice;
HttpCookie cookie = new HttpCookie("Info");//定义cookie对象以及名为Info的项
DateTime dt = DateTime.Now;//定义时间对象
TimeSpan ts = new TimeSpan(1, 0, 0, 0);//cookie有效作用时间,具体查msdn
cookie.Expires = dt.Add(ts);//添加作用时间
cookie.Values.Add("ppTx", ppTx);//增加属性
cookie.Values.Add("ppStatus", ppStatus);
cookie.Values.Add("ppDate", ppDate);
cookie.Values.Add("ppItem", ppItem);
cookie.Values.Add("ppPrice", ppPrice);
Response.AppendCookie(cookie);//确定写入cookie中 读取cookie
}
else
{ }
}
//////////////////////////////////////////////////////////////////////////
bool VerifyIPN()
{
string strFormValues = Request.Form.ToString();
string strNewValue;
string strResponse;
string serverURL = "https://www.sandbox.paypal.com/cgi-bin/webscr"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(serverURL);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
strNewValue = strFormValues + "&cmd=_notify-validate";
req.ContentLength = strNewValue.Length; StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close(); StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close(); return strResponse == "VERIFIED";
}
}
3、paypal还有一个设置,“Website Payment Preferences ”,“网站付款习惯设定”。我这里设置的是:自动返回: 开启。返回 URL:OK.html。我的ok.html代码:<body>
<p>
That's OK!</p>
</body>
以上就是全部设置了,我测试的过程是这样的,首先点击购买按钮,然后跳到paypal去,然后输入测试账号付款,然后系统调到这么一个url:http://www.cgunited.com/OK.html?tx=3G514512SP293070L&st=Pending&amt=20.00&cc=USD&cm=&item_number=Item Number Goes Here
页面显示的内容是:That's OK!我登陆paypal发现付款成功了,但是为何我的cookie里面却没有写入任何信息呢?
而OK页面用户简单的告诉用户购买了什么产品,购买成功与否还有可以告诉用户一些使用注意事项等等。但是为何我的IPN页面接收不到数据啊
参考http://www.chenchen.org/article/10.htm
看看是不是有步骤漏掉了.
请发邮件到