本文介绍了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 [email protected]>

< 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="[email protected]">
<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">

推荐答案


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

08-24 13:49