Asp.net Paypal返回Url要求
本文关键字:Url 要求 返回 Paypal net Asp | 更新日期: 2023-09-27 18:28:47
我的测试程序使用asp.net。
//string Server_URL = "https://www.paypal.com/ph/cgi-bin/webscr?";
string Server_URL = ConfigurationManager.AppSettings["URL"].ToString();
//Assigning Cmd Path as Statically to Parameter
string cmd = "_xclick";
//Assigning business Id as Statically to Parameter
string business = ConfigurationManager.AppSettings["BusinessName"].ToString();
//Assigning item name as Statically to Parameter
string item_name = lblProductCode.Text;
//Passing Amount as Statically to parameter
double amount = Convert.ToDouble(_lblPrice.Text);
Session["Amount"] = amount;
//Passing Currency as Statically to parameter
string currency_code = "PHP";
string redirect = "";
//Pass your Server_Url,cmd,business,item_name,amount,currency_code variable.
redirect += Server_URL;
redirect += "cmd=" + cmd;
redirect += "&business=" + business;
redirect += "&first_name=" + Session["id"].ToString();
redirect += "&item_name=" + item_name;
redirect += "&amount=" + amount;
redirect += "&quantity=1";
redirect += "¤cy_code=" + currency_code;
redirect += "&return=http://localhost:49457/Fun/Success.aspx";
redirect += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();
Session["Redirect"] = redirect;
Response.Redirect(redirect);
现在在网站支付偏好我在代码中的返回中设置了相同的返回URL。上面写着"我们无法验证您输入的URL。请检查您的输入并重试。"
是否可以在返回url中插入localhost url???
我以前是这样做的,它在本地服务器测试中对我有效:
protected void imgBtnBuyNow_Clicked(object sender, EventArgs e)
{
string redirecturl = "";
//Mention URL to redirect content to paypal site
redirecturl += "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" + ConfigurationManager.AppSettings["paypalemail"].ToString();
//First name i assign static based on login details assign this value
redirecturl += "&first_name=ehsan";
//City i assign static based on login user detail you change this value
redirecturl += "&city=rawalpindi";
//State i assign static based on login user detail you change this value
redirecturl += "&state=punjab";
//Product Name
redirecturl += "&item_name=" + packageName.Value.ToString();
//Product Amount
redirecturl += "&amount=" + tdPrice.InnerHtml;
//Business contact id
//redirecturl += "&business=nravindranmca@gmail.com";
//Shipping charges if any
redirecturl += "&shipping=5";
//Handling charges if any
redirecturl += "&handling=5";
//Tax amount if any
redirecturl += "&tax=5";
//Add quatity i added one only statically
redirecturl += "&quantity=1";
//Currency code
redirecturl += "¤cy=USD";
redirecturl += "&invoice=" + packageID.Value.ToString();
redirecturl += "&custom=" + Session["userid"].ToString() + "," + packageID.Value.ToString() + "," + Session["purchaseType"].ToString();
//Success return page url
redirecturl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString();
//Failed return page url
redirecturl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();
Response.Redirect(redirecturl);
}
这是web.config中的设置:
<add key="token" value="Jlt89XcvKKNRyLICXJCaWBlYoXxPify22EQlz3ZaColy51HdwJz05rILtd4" />
<add key="paypalemail" value="biznes_1357901741_biz@yahoo.com" />
<add key="PayPalSubmitUrl" value="https://www.sandbox.paypal.com/cgi-bin/webscr" />
<add key="FailedURL" value="http://localhost:4076/OpenLearningSolutions/Failed.aspx" />
<add key="SuccessURL" value="http://localhost:4076/OpenLearningSolutions/Success.aspx" />
在贝宝沙盒Web支付参考中,有一个返回url的网站,如果你在那里输入你的本地开发服务器url,那将永远不会工作。你不能这样做,这是一件你应该熟悉的基本事情,从逻辑上讲,这是不可能的,它将如何识别你的本地url。你可以在发送给贝宝的网络请求中设置返回url作为参数,如下所示:
redirecturl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString();
//Failed return page url
redirecturl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();
没有必要在那里设置返回url,因为我们在web请求
据我所知,localhost URL是不可能的。试试这个:在hosts文件中添加一个规则,并将localhost映射到另一个名称,比如"mysite.com"。然后提供带有该新名称的URL和您的路径作为PayPal的返回URL。Paypal应该正确地调用它。
用记事本打开windows/system32/drivers/etc/hosts(以管理员身份运行)添加行:localhost contoso.example.org
现在,您的返回url将如下所示:http://contoso.example.org:49457/Fun/Success.aspx并且您应该能够在浏览器中打开(它将指向localhost)。
然后,将此返回url包含在您对PayPal API的调用中,并将其放在"付款首选项"页面的字段中。