Can I test paypal api's from localhost

oshirowanen picture oshirowanen · Apr 1, 2011 · Viewed 37.5k times · Source

UPDATE 1:

According to this tutorial on Using PayPal's Instant Payment Notification with PHP, PayPal cannot access locally hosted websites unless certain router ports are opened. Is this because the website is about IPN or is this true for all PayPal APIs?

ORIGINAL QUESTION:

On my laptop, I have a LAMP environment setup, when I use the http://localhost to create website before going live.

For a new project, I need to use the PayPal APIs. Will I be able to use the localhost to test the PayPal APIs if I connect my laptop to the internet? Or will I have to upload my website to a LAMP host elsewhere?

You're probably thinking, what a stupid question, just try it to see if it works. I have tried it and it's not working and I wanted to rule out this question before going onto the next step.

Answer

Brad Parks picture Brad Parks · Jul 17, 2012

If you want to debug your IPN code, you'll need to make your server publicly available in some way. This is so PayPal can asynchronously post back to your server at a later time after you've submitted your request. Usually this is pretty quick I think (within 15 seconds) but it could be longer.

One easy way I've found to make a development server available publicly is to use ngrok, or forwardhq.com. This allows you to continue to develop in your IDE like normal, running your code in debug mode. When PayPal posts back to your endpoint, you can debug it right there in your IDE. These services wrap this up for you, so it's very easy to do without any technical know how.

From my understanding, this is done using a "reverse SSH tunnel" which allows your site to be made public by proxying it through a server that's already publicly available. Note that before you do this, you have to consider that not just PayPal can hit your site once it's made public, but anyone can, so please take that into consideration first.

Also, if you've got your own public facing domain and don't mind playing around in a terminal with SSH, you can supposedly do something like this shell script (copied from this gist)

# Usage: show <local-port> <subdomain>
function show() {
    DOMAIN=".yourdomain.com"
    REMOTE="$2$DOMAIN"
    ssh -tR 1080:127.0.0.1:$1 vps "sudo ssh -Nl \$USER -L $REMOTE:80:127.0.0.1:1080 localhost"
}

To get this to work as above, you'd need to put the following in your ~/.ssh/config file:

Host vps
    HostName <server address>
    User <server username>

If you don't want to (or can't) do this, then the following will work:

SERVERUSER="<server username>"
ssh -l $SERVERUSER -tR 1080:127.0.0.1:$1 <server address> "sudo ssh -Nl \$SERVERUSER -L $REMOTE:80:127.0.0.1:1080 localhost"