Asp.net 实时贝宝错误
我在ASP.net中使用PayPal,当我在沙盒中测试时,一切都是正确的,但当我使用live part时,我遇到以下错误: 此付款无法完成,您的帐户尚未收费。有关更多信息,请联系您的商户。 目前我们无法使用您的PayPal帐户处理您的付款。请返回商户网站,尝试使用其他付款方式(如果可用) 这是我的网络配置Asp.net 实时贝宝错误,asp.net,paypal,paypal-ipn,paypal-sandbox,Asp.net,Paypal,Paypal Ipn,Paypal Sandbox,我在ASP.net中使用PayPal,当我在沙盒中测试时,一切都是正确的,但当我使用live part时,我遇到以下错误: 此付款无法完成,您的帐户尚未收费。有关更多信息,请联系您的商户。 目前我们无法使用您的PayPal帐户处理您的付款。请返回商户网站,尝试使用其他付款方式(如果可用) 这是我的网络配置 <add key="token" value="*************************"/> <add key="paypalemail" value="*
<add key="token" value="*************************"/>
<add key="paypalemail" value="*************@gmail.com"/>
<add key="PayPalSubmitUrl" value="https://www.paypal.com/cgi-bin/webscr"/>
<add key="FailedURL" value="http://www.stockholmsbygg.net/Failed.aspx"/>
<add key="SuccessURL" value="http://www.stockholmsbygg.net/FindOpenRequests.aspx"/>
<add key="Notification" value="http://www.stockholmsbygg.net/Notification.aspx"/>
这是我从paypal返回我的地址后检查的所有内容
if (Request.QueryString["cm"] != null)
{
const string authToken = "*********************************";
string txToken = Request.QueryString["tx"];
string query = "cmd=_notify-synch&tx=" + txToken + "&at=" + authToken;
//const string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
string strSandbox = "https://www.paypal.com/cgi-bin/webscr";
var req = (HttpWebRequest)WebRequest.Create(strSandbox);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = query.Length;
var streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(query);
streamOut.Close();
var streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
var results = new Dictionary<string, string>();
if (strResponse != "")
{
var reader = new StringReader(strResponse);
string line = reader.ReadLine();
if (line == "SUCCESS")
{
while ((line = reader.ReadLine()) != null)
{
results.Add(line.Split('=')[0], line.Split('=')[1]);
}
var userId = Convert.ToInt64(Session["UserID"]);
var item = Convert.ToInt64(Request.QueryString["cm"]);
context = new entities();
var existUser = context.Payments.Where(u => u.UserID == userId).ToList();
var existItem = existUser.Where(i => i.RequestID == item).ToList();
var paypalInvoice = results["invoice"];
var txn_id = results["txn_id"];
var sameInvoice =
existItem.Where(i => i.invoice== paypalInvoice).FirstOrDefault();
if (sameInvoice != null)
{
var currentAmount = Request.QueryString["amt"];
var dbAmount = Convert.ToDecimal(sameInvoice.Amount).ToString();
var currentIp = HttpContext.Current.Request.UserHostAddress;
if (dbAmount != null)
{
if (currentAmount == dbAmount)
{
if (currentIp == sameInvoice.IP)
{
sameInvoice.Status = true;
sameInvoice.PaypalTX = txn_id;
pnlSearch.Visible = false;
pnlShowDetail.Visible = true;
ShowDetail(Request.QueryString["cm"], true);
btnBack.Visible = false;
PrivateDetail.Visible = true;
interested.Visible = false;
context.SaveChanges();
}
}
}
}
}
else if (line == "FAIL")
{
// Log for manual investigation
Response.Write("Unable to retrive transaction detail");
}
}
else
{
//unknown error
Response.Write("ERROR");
}
}
if(Request.QueryString[“cm”!=null)
{
常量字符串authToken=“****************************************”;
字符串txToken=Request.QueryString[“tx”];
string query=“cmd=”notify-synch&tx=“+txToken+”&at=“+authToken;
//常量字符串strSandbox=”https://www.sandbox.paypal.com/cgi-bin/webscr";
字符串strSandbox=”https://www.paypal.com/cgi-bin/webscr";
var req=(HttpWebRequest)WebRequest.Create(strSandbox);
请求方法=“POST”;
req.ContentType=“应用程序/x-www-form-urlencoded”;
req.ContentLength=query.Length;
var streamOut=newstreamwriter(req.GetRequestStream(),System.Text.Encoding.ASCII);
streamOut.Write(查询);
streamOut.Close();
var streamIn=newstreamreader(req.GetResponse().GetResponseStream());
字符串strResponse=streamIn.ReadToEnd();
streamIn.Close();
var results=newdictionary();
如果(strResponse!=“”)
{
变量读取器=新的StringReader(strResponse);
字符串行=reader.ReadLine();
如果(行==“成功”)
{
而((line=reader.ReadLine())!=null)
{
结果.添加(line.Split('=')[0],line.Split('=')[1]);
}
var userId=Convert.ToInt64(会话[“userId]”);
var item=Convert.ToInt64(Request.QueryString[“cm]”);
上下文=新实体();
var existUser=context.Payments.Where(u=>u.UserID==UserID.ToList();
var existItem=existUser.Where(i=>i.RequestID==item.ToList();
var paypalInvoice=结果[“发票”];
var txn_id=结果[“txn_id”];
var sameInvoice=
existItem.Where(i=>i.invoice==paypalInvoice.FirstOrDefault();
if(sameInvoice!=null)
{
var currentAmount=Request.QueryString[“amt”];
var dbAmount=Convert.ToDecimal(sameInvoice.Amount).ToString();
var currentIp=HttpContext.Current.Request.UserHostAddress;
if(dbAmount!=null)
{
如果(currentAmount==dbAmount)
{
if(currentIp==sameInvoice.IP)
{
sameInvoice.Status=true;
sameInvoice.PaypalTX=txn_id;
pnlSearch.Visible=false;
pnlShowDetail.Visible=true;
ShowDetail(Request.QueryString[“cm”],true);
btnBack.Visible=false;
PrivateDetail.Visible=true;
感兴趣。可见=假;
SaveChanges();
}
}
}
}
}
否则如果(行==“失败”)
{
//人工调查日志
响应。写入(“无法检索交易明细”);
}
}
其他的
{
//未知错误
响应。写入(“错误”);
}
}
有什么问题?
也是在第一次测试时,我付了钱,但什么也没发生。发票状态wad仍然为假,但自从我付款后它本应变为真 此函数是一个100%错误
RedirectToPaypal()
没有重定向到贝宝。只有带有post参数的post
地址,而不是get
(重定向)
这是合乎逻辑的,因为如果你把所有的敏感数据放在url上,那么它就会暴露给任何一个需要它的人
if (Request.QueryString["cm"] != null)
{
const string authToken = "*********************************";
string txToken = Request.QueryString["tx"];
string query = "cmd=_notify-synch&tx=" + txToken + "&at=" + authToken;
//const string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
string strSandbox = "https://www.paypal.com/cgi-bin/webscr";
var req = (HttpWebRequest)WebRequest.Create(strSandbox);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = query.Length;
var streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(query);
streamOut.Close();
var streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
var results = new Dictionary<string, string>();
if (strResponse != "")
{
var reader = new StringReader(strResponse);
string line = reader.ReadLine();
if (line == "SUCCESS")
{
while ((line = reader.ReadLine()) != null)
{
results.Add(line.Split('=')[0], line.Split('=')[1]);
}
var userId = Convert.ToInt64(Session["UserID"]);
var item = Convert.ToInt64(Request.QueryString["cm"]);
context = new entities();
var existUser = context.Payments.Where(u => u.UserID == userId).ToList();
var existItem = existUser.Where(i => i.RequestID == item).ToList();
var paypalInvoice = results["invoice"];
var txn_id = results["txn_id"];
var sameInvoice =
existItem.Where(i => i.invoice== paypalInvoice).FirstOrDefault();
if (sameInvoice != null)
{
var currentAmount = Request.QueryString["amt"];
var dbAmount = Convert.ToDecimal(sameInvoice.Amount).ToString();
var currentIp = HttpContext.Current.Request.UserHostAddress;
if (dbAmount != null)
{
if (currentAmount == dbAmount)
{
if (currentIp == sameInvoice.IP)
{
sameInvoice.Status = true;
sameInvoice.PaypalTX = txn_id;
pnlSearch.Visible = false;
pnlShowDetail.Visible = true;
ShowDetail(Request.QueryString["cm"], true);
btnBack.Visible = false;
PrivateDetail.Visible = true;
interested.Visible = false;
context.SaveChanges();
}
}
}
}
}
else if (line == "FAIL")
{
// Log for manual investigation
Response.Write("Unable to retrive transaction detail");
}
}
else
{
//unknown error
Response.Write("ERROR");
}
}