string strFormValues;
string strNewValue;
string strResponse;
//创建回复的request
//在Sandbox 情况下,设置:
// WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr");
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr");
//设置request 的属性
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param =HttpContext.Current.Request.BinaryRead( HttpContext.Current.Request.ContentLength);
strFormValues = Encoding.ASCII.GetString(param);
//建议在此将接受到的信息记录到日志文件中以确认是否收到IPN 信息
//我写入日志
strNewValue = strFormValues + "&cmd=_notify-validate";
req.ContentLength = strNewValue.Length;
//发送request
StreamWriter stOut = new StreamWriter (req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();
//回复IPN 并接受反馈信息
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close();
//确认IPN 是否合法
if (strResponse == "VERIFIED")
{
//检查付款状态
if (Request.Form["payment_status"] == "Completed")
{
//检查交易号txn_id 是否已经处理过
//Request.Form["txn_id"]
//检查receiver_email 是否是您的PayPal 账户中的EMAIL 地址,yourbesiness是商家帐号,对比看有没有被改
if (Request.Form["receiver_email"].ToString() == "[email protected]")
{
//检查付款金额和货币单位是否正确,amount是你从数据库定单查询出来,进行比对
//if (Request.Form["mc_gross"].ToString() == "amount")
//{
if (Request.Form["mc_currency"].ToString() == "USD")//对比币种
{
string ppTx = Request.Form["txn_id"].ToString();
string ppStatus = Request.Form["payment_status"].ToString();
string ppItem = Request.Form["item_name"].ToString();
string ppPrice = Request.Form["mc_gross"].ToString();
string ppDate = Request.Form["payment_date"].ToString();
int Bit=0;
int check = conn.saveorder(ppTx, ppStatus, ppItem, ppPrice, ppDate, Bit); if (check <= 0)
{ Response.Write("Error");
}
//处理这次付款,包括写数据库
}
}
}
以上是网上查找的代码,想调用方法conn类的方法, conn.saveorder(ppTx, ppStatus, ppItem, ppPrice, ppDate, Bit),将信息存入数据库,可是没有实现,不知道问题在哪??是不是哪里错了???希望有经验的高手指点下,谢谢,还有就是 "检查付款金额和货币单位是否正确,amount是你从数据库定单查询出来,进行比对"在本地如何获取购物车上物品总金额呢? 我获取不到,就没办法对比了!!
谢谢了
string strNewValue;
string strResponse;
//创建回复的request
//在Sandbox 情况下,设置:
// WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr");
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr");
//设置request 的属性
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param =HttpContext.Current.Request.BinaryRead( HttpContext.Current.Request.ContentLength);
strFormValues = Encoding.ASCII.GetString(param);
//建议在此将接受到的信息记录到日志文件中以确认是否收到IPN 信息
//我写入日志
strNewValue = strFormValues + "&cmd=_notify-validate";
req.ContentLength = strNewValue.Length;
//发送request
StreamWriter stOut = new StreamWriter (req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();
//回复IPN 并接受反馈信息
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close();
//确认IPN 是否合法
if (strResponse == "VERIFIED")
{
//检查付款状态
if (Request.Form["payment_status"] == "Completed")
{
//检查交易号txn_id 是否已经处理过
//Request.Form["txn_id"]
//检查receiver_email 是否是您的PayPal 账户中的EMAIL 地址,yourbesiness是商家帐号,对比看有没有被改
if (Request.Form["receiver_email"].ToString() == "[email protected]")
{
//检查付款金额和货币单位是否正确,amount是你从数据库定单查询出来,进行比对
//if (Request.Form["mc_gross"].ToString() == "amount")
//{
if (Request.Form["mc_currency"].ToString() == "USD")//对比币种
{
string ppTx = Request.Form["txn_id"].ToString();
string ppStatus = Request.Form["payment_status"].ToString();
string ppItem = Request.Form["item_name"].ToString();
string ppPrice = Request.Form["mc_gross"].ToString();
string ppDate = Request.Form["payment_date"].ToString();
int Bit=0;
int check = conn.saveorder(ppTx, ppStatus, ppItem, ppPrice, ppDate, Bit); if (check <= 0)
{ Response.Write("Error");
}
//处理这次付款,包括写数据库
}
}
}
以上是网上查找的代码,想调用方法conn类的方法, conn.saveorder(ppTx, ppStatus, ppItem, ppPrice, ppDate, Bit),将信息存入数据库,可是没有实现,不知道问题在哪??是不是哪里错了???希望有经验的高手指点下,谢谢,还有就是 "检查付款金额和货币单位是否正确,amount是你从数据库定单查询出来,进行比对"在本地如何获取购物车上物品总金额呢? 我获取不到,就没办法对比了!!
谢谢了
通过下面方式是否能获取信息??? 在Ipn中,就回这一个问题就好,如果不能,怎么获取!
string ppTx = Request.Form["txn_id"].ToString();
string ppStatus = Request.Form["payment_status"].ToString();
string ppItem = Request.Form["item_name"].ToString();
string ppPrice = Request.Form["mc_gross"].ToString();
string ppDate = Request.Form["payment_date"].ToString();
你這個方式是可以獲取信息的!
如果你獲取不到信息,
請檢查下以下三點:1.你調用接口的方法是否傳對參數,或者說有沒有遺漏,
2.PayPal帳戶里面有沒設置好買賣雙方帳號,特別是賣方的一些特殊設置,如指定返回頁面等。
3.你最頂上寫的一些判斷是否有問題?就在最上層 if (strResponse == "VERIFIED") 記錄信息看看有沒有?
當初我也是參照你找的這個例子來試,其實最終問題還是出在自己沒有設置好 PayPal 帳戶
能成功发送和接改返回后, 再做测试的工作。我不多说,其实你懂的