简体   繁体   中英

Asp.net Paypal Return Url Requirement

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???

i used to do this way and it works for me on local server testing:

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);
}

and here is the settings in 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" />

In the paypal sandbox Web payment reference there is a return url site, if you are entering there your local development server url, that will never work.You can't do that its a basic thing that you should be fimiliar and its logically not possible, how it will recogninze your local url.You can set return url as parameter in the web request that you are sending to paypal like this:

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

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

There is no need to set return url there, as we are sending it in the web request

As far as I know localhost urls are not possible. Try this: add a rule to hosts file, and map localhost to another name, say - "mysite.com". Then provide URL with that new name and your path as Return Url for PayPal. Paypal should correctly call it.

Open windows/system32/drivers/etc/hosts with notepad ( running it as administrator ) Add line: localhost contoso.example.org

Now, your return url will look like : http://contoso.example.org:49457/Fun/Success.aspx and you should be able to open in your browser ( it will point to localhost ).

Then, include this return url in your calls to PayPal API and put it the field on Payment Preferences page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM