Paypal集成问题 - 将响应视为失败 [英] Paypal integration issue- Getting response as failure

查看:94
本文介绍了Paypal集成问题 - 将响应视为失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试将paypal集成到我的asp.net应用程序。我是这种支付网关的新手。但是,我创建了Sandbox帐户,沙箱中的所有东西都运行良好。



我将所需的值发送到sandbox.paypal.com并且有牵引力没关系。

但是,当我回到我的应用程序并且使用PDT响应方式时,我得到失败响应。

我没有得到transaaction id(tx)来自paypal。



任何人都可以知道过来这个问题。



提前致谢........



我使用以下代码



发送给paypal的值链接



hi i am trying to integrate paypal to my asp.net application .I am new to this type of payment gateways. But, i had created the Sandbox accounts and every thing in sandbox is working fine.

I am sending the required values to the sandbox.paypal.com and there the traction is ok.
But , i am getting failure response when it come backs to my application and i am using PDT way of response .
and i am not getting the transaaction id (tx) from paypal.

Can anyone have an idea of over coming this issue.

Thanks in advance.........

I am using the following code

Values sent to paypal link

string redirectUrl = "";


                redirectUrl += "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" + ConfigurationManager.AppSettings["PayPalEmail"].ToString();


                redirectUrl += "&first_name" + CommonHelper.FirstName;
                redirectUrl += "&item_name= Credits";
                redirectUrl += "&amount=" + lblPrice.Text;
                redirectUrl += "&currency_code=GBP";
                //redirectUrl += "&tax=" + lblVatPRice.Text;
                redirectUrl += "&quantity=1";

                redirectUrl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString();
                redirectUrl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();
                //redirectUrl += "&notify_url=" + ConfigurationManager.AppSettings["NotifyURL"].ToString();
                Response.Redirect(redirectUrl);



}





回复此页面

paypalresponse.aspx





公共部分class HandlePayPalResponse:System.Web.UI.Page

{

protected void Page_Load(object sender,EventArgs e)

{





if(!Page.IsPostBack)

{

string authToken = ConfigurationManager.AppSettings [token];



//从查询字符串读取txn令牌

string txToken = Request.QueryString.Get(tx );





string query = string.Format(cmd = _notify-synch& tx = {0}& at = {1},

txToken,authToken);



//创建请求返回

string url = ConfigurationManager.AppSettings [PayPalSubmitUrl];

HttpWebRequest req =(HttpWebRequest)WebRequest.Create(url);



//为请求设置值

req.Method =POST;

req.ContentType =application / x-www-form- urlencoded;

req.ContentLength = query.Length;



//将请求写回IPN字符串

StreamWriter stOut = new StreamWriter(req.GetRequestStream(),

System.Text.Encoding.ASCII);

stOut.Write(query);

stOut.Close();



//向PayP请求并获得响应

StreamReader stIn = new StreamReader(req.GetResponse()。GetResponseStream());

string strResponse = stIn.ReadToEnd();

stIn.Close();



//完整性检查

Label2.Text = strResponse;



//如果响应是SUCCESS,则解析响应字符串和输出详细信息

if(strResponse.StartsWith(SUCCESS))

{

Paypal pdt = Paypal.Parse(strResponse);

Label1.Text =

string.Format(谢谢你{0} {1} [{2}]用于支付{3} {4}!,

pdt.PayerFirstName,pdt.PayerLastName,

pdt.PayerEmail,pdt .GrossTotal,pdt.Currency);

}

else

{

Label1.Text =Oooops,出了点问题......;

}

}



web.config设置

< add key =tokenvalue =ELtdsUBCPOulCijrkzz1cKXuXU9a23C1WJH4U3iNoiIhsGoPbUwVYfJeCaFl> ;;

< add key = PayPalEmailvalue =test.merchant@gmail.com>

< add key =paypalsubmiturlvalue =http://localhost/mysite.webapp/paypal.aspx>

< add key =successurlvalue =http://localhost/mysite.webapp/paypal1.aspx>

< add key =failureurl value =http://localhost/mysite.webapp/paypal2.aspx>


}


response comes to this page
paypalresponse.aspx


public partial class HandlePayPalResponse : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


if (!Page.IsPostBack)
{
string authToken = ConfigurationManager.AppSettings["token"];

//read in txn token from querystring
string txToken = Request.QueryString.Get("tx");


string query = string.Format("cmd=_notify-synch&tx={0}&at={1}",
txToken, authToken);

// Create the request back
string url = ConfigurationManager.AppSettings["PayPalSubmitUrl"];
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = query.Length;

// Write the request back IPN strings
StreamWriter stOut = new StreamWriter(req.GetRequestStream(),
System.Text.Encoding.ASCII);
stOut.Write(query);
stOut.Close();

// Do the request to PayPal and get the response
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = stIn.ReadToEnd();
stIn.Close();

// sanity check
Label2.Text = strResponse;

// If response was SUCCESS, parse response string and output details
if (strResponse.StartsWith("SUCCESS"))
{
Paypal pdt = Paypal.Parse(strResponse);
Label1.Text =
string.Format("Thank you {0} {1} [{2}] for your payment of {3} {4}!",
pdt.PayerFirstName, pdt.PayerLastName,
pdt.PayerEmail, pdt.GrossTotal, pdt.Currency);
}
else
{
Label1.Text = "Oooops, something went wrong...";
}
}

web.config settings
<add key="token" value="ELtdsUBCPOulCijrkzz1cKXuXU9a23C1WJH4U3iNoiIhsGoPbUwVYfJeCaFl">;
<add key="PayPalEmail" value="test.merchant@gmail.com">
<add key="paypalsubmiturl" value="http://localhost/mysite.webapp/paypal.aspx">
<add key="successurl" value="http://localhost/mysite.webapp/paypal1.aspx">
<add key="failureurl" value="http://localhost/mysite.webapp/paypal2.aspx">

推荐答案

永远不要接受来自不安全网站的代码来处理任何事情用真钱做的。

你不知道是谁给你代码,你不知道它做了什么,你不知道它把钱正确地放到了适当的账户里,没有通过细节到任何第三个p arties。



只能从Paypal自己获取此类代码 - 否则欺诈的范围太大。请记住,如果您的行为被视为疏忽,您本人可能要对任何损失承担责任 - 从公共论坛获取您的代码肯定会是!
Never, ever, accept code from a insecure website to handle anything to do with real money.
You do not know who is giving you the code, you do not know what it does, you do not know that it places the monies correctly into the appropriate account, without passing the details to any third parties.

Only get such code from Paypal themselves - the scope for fraud otherwise is far too large. And remember, you personally could be liable for any monies lost if your action is seen to be negligent - which getting your code from a public forum would most certainly be!


这篇关于Paypal集成问题 - 将响应视为失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆