1

I'm using asp.net for my test program.

//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 += "&currency_code=" + currency_code;

            redirect += "&return=http://localhost:49457/Fun/Success.aspx";
            redirect += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();

            Session["Redirect"] = redirect;

            Response.Redirect(redirect);

Now in Website Payment Preferences I set the return URL same in my return in my code. it said "We were unable to validate the URL you have entered. Please check your entry and try again."

Is it possible to insert a localhost url in the return url???

4

3 回答 3

2

我曾经这样做,它适用于本地服务器测试:

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 += "&currency=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" />
于 2013-08-23T05:11:03.837 回答
1

在 paypal 沙箱 Web 支付参考中有一个返回 url 站点,如果你在那里输入你的本地开发服务器 url,那将永远无法工作。你不能这样做,这是你应该熟悉的基本事情,在逻辑上是不可能的,它将如何识别您的本地 url。您可以在发送到 paypal 的 Web 请求中将返回 url 设置为参数,如下所示:

redirecturl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString();

//Failed return page url
redirecturl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();

无需在此处设置返回 url,因为我们在 Web 请求中发送它

于 2013-08-23T07:42:34.320 回答
0

据我所知,本地主机网址是不可能的。试试这个:在主机文件中添加一条规则,并将 localhost 映射到另一个名称,比如 - “mysite.com”。然后提供具有该新名称的 URL 和您的路径作为 PayPal 的 Return Url。Paypal 应该正确调用它。

用记事本打开 windows/system32/drivers/etc/hosts(以管理员身份运行)添加行: localhost contoso.example.org

现在,您的返回 url 将如下所示:http ://contoso.example.org:49457/Fun/Success.aspx ,您应该能够在浏览器中打开(它将指向 localhost)。

然后,在您对 PayPal API 的调用中包含此返回 url,并将其放在 Payment Preferences 页面上的字段中。

于 2013-08-23T02:47:36.283 回答