?
Solved

Paypal API not accepting Localhost

Posted on 2014-04-02
3
Medium Priority
?
1,278 Views
Last Modified: 2016-03-24
Hi all,

I'm having issues testing the Paypal API as I am getting an error from Paypal saying my returnURL is invalid.

If I alter this to be the finalised url i.e. www.mysite.com/returnURL this fires correctly.

Obviously for debug purposes I want to return to http://localhost:1939/returnURL

I think it is the : in thestring its rejecting.

Are there any ways around this?
0
Comment
Question by:flynny
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Andrew Angell
ID: 39971552
The value you pass to PayPal for Return and Cancel URL's is the value their servers will use when the time comes to redirect.  If that value is http://localhost they would just be redirecting to themselves.  This isn't going to work, of course, and that's why they reject it.

In order to test on your local server you'll need to use your full IP address instead of localhost or setup some DNS of some sort.  You could use a dynamic DNS service, or just manually create A records to point to your IP address there.  

For example, if I'm setting up a new website for a client I'll login to their hosting account, go into the DNS settings, and create a new A record that points sandbox.domain.com to my IP address here.  

Then, I setup a vhost in my Apache config for sandbox.domain.com.  This way the site can be accessed publicly via http://sandbox.domain.com and I can use that with my PayPal tests or anything else I need.  

Another trick you can do when you setup your test server like this is you can have your config settings work dynamically based off the subdomain of the site.  When it's running sandbox.domain.com you can have all your config settings use PayPal sandbox credentials and database test credentials, etc.  When it's not running on sandbox, use all live credentials.  This way  you don't have to keep switching everything back and forth.
0
 

Author Comment

by:flynny
ID: 39971611
Thanks for that Andrew, that helpful.

referring to your last comment do you mean I can filter in the web.config? would you be able to provide a little test code for this? as this could be really helpful.
0
 
LVL 11

Accepted Solution

by:
Andrew Angell earned 2000 total points
ID: 39971618
No, I just mean in a basic config file.  For example, I use this a lot...

$host_split = explode('.',$_SERVER['HTTP_HOST']);
$sandbox = $host_split[0] == 'sandbox' && $host_split[1] == 'domain' ? TRUE : FALSE;
$domain = $sandbox ? 'http://sandbox.domain.com/' : 'http://www.domain.com/';

Open in new window


That would check the current subdomain and domain (whatever.domain) and it would set $sandbox to true if it was sandbox.domain.com.  In any other case $sandbox would be false.  

Then I do everything else in my config files based on $sandbox, so it automatically handles different credentials for test vs. live databases, API's, etc.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question