Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
can I have any Paypal Sandbox Integration step by step for ASP.net c# (for Website, web application) with an example?

What I have tried:

string redirectUrl = "";

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

redirectUrl += "&first_name=name";

redirectUrl += "&item_name=" + Name;

redirectUrl += "&amount=" + Price;

redirectUrl += "&business=Paypalmail";

redirectUrl += "&quantity=1";

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

redirectUrl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();

Response.Redirect(redirectUrl);


Success URL, and Failed URL are defined in Web.config.

this code redirecting to sandbox. but i didnt get return response.

can anyone help on this?

thanks in advance.
Posted
Updated 25-May-16 10:21am
Comments
ZurdoDev 25-May-16 8:56am    
I'd suggest asking PayPal first and going to their dev site.
Patrice T 25-May-16 15:29pm    
Ask paypal !

1 solution

I don't know anything about PayPal integration, but is it possible that having the business= specified twice is confusing things?
Also, are the values you are including in the redirectUrl are appropriately Url encoded? (See HttpUtility.UrlEncode Method (String) (System.Web)[^] and/or HttpUtility.UrlPathEncode Method (String) (System.Web)[^].)

The code you have is a bit sloppy ;-)
Here's how I'd structure it (I'm not addressing the encoding potential issue.)
Option 1:
C#
const string redirectUrlFormat = 
"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business={0}" + 
"&first_name=name" +
"&item_name={1}" +
"&amount={2}" +
// "&business=Paypalmail"    // This was the duplication!!!
"&quantity=1" +
"&return={3}"
"&cancel_return={4}";
string redirectUrl = string.Format(redirectUrlFormat,
                                   ConfigurationManager.AppSettings["paypalemail"],
                                   Name, Price,
                                   ConfigurationManager.AppSettings["SuccessURL"],
                                   ConfigurationManager.AppSettings["FailedURL"]);
Response.Redirect(redirectUrl);

Option 2:
C#
StringBuilder redirectUrl = new StringBuilder();

redirectUrl.Add("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=");
redirectUrl.Add(ConfigurationManager.AppSettings["paypalemail"]);
redirectUrl.Add("&first_name=name&item_name=");
redirectUrl.Add(Name);
redirectUrl.Add("&amount=");
redirectUrl.Add(Price);
redirectUrl.Add("&quantity=1&return=");
redirectUrl.Add(ConfigurationManager.AppSettings["SuccessURL"]);
redirectUrl.Add("&cancel_return=");
redirectUrl.Add(ConfigurationManager.AppSettings["FailedURL"]);

Response.Redirect(redirectUrl.ToString());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900