Friday, November 26, 2010

Setting Up a Dev/Test Environment for PayPal Instant Payment Notification (IPN)

So you have a web site where you want to integrate PayPal IPN in a Windows environment?

Requirements/Steps:

1. Obtain Public IP address and (optional) get a free DNS name
2. Create web site on your local computer with an IPN Handler
3. Configure Router and Windows Firewall
4. Setup a PayPal Test Account and test IPN from PayPal

Obtain Public IP address and (optional) get a free DNS name

PayPal needs to access your web site from the internet and thus needs a public IP address or a DNS name.
Two Options:
1.  Public IP Address you can find at What is My IP Address?
2.  Free DNS name - go to DynDNS and sign up for an account.  You'll need to install a service on your test computer so when your dynamic IP updates, it will notify DynDNS so they will be in sync.  You'll end up with a name such as yourhost.dyndns.org.

Create Web Site on your Test Machine

Create a web site on your local computer in IIS that has an IPN handler aspx page.  There are a number of already written IPN handlers that you can use or tweak:
C# IPN Handler - http://forums.asp.net/p/92314/92314.aspx
C# PayPal IPN Class - http://paypalipnclass.codeplex.com/releases/view/31282
Upload these files to your website as well as a dummy default html page, this will be used for test purposes only.

 

Configure Router

Now that you have a public url (yourhost.dyndns.org), you need to configure your router to drive traffic to your site.  In your router setup you need to use port forwarding or virtual server to re-route port 80 traffic to the internal IP address of your test box.  If your web site is on another port than port 80, configure your router to point to the port that your website is on. 

PayPal IPN does not work with urls with port numbers in them.

Once you have the router configured, you need to open up port 80 in your Windows Firewall.  Check this article out:  Here's a good article that explains how to do that: How to configure the new Windows Server 2008 advanced firewall MMC snap-in

If you have access to an outside network, once the router is configured, try navigating to your web site page to verify you can access it.

 

Setup a PayPal Test Account


PayPal has a sandbox that you can utilize for free to simulate payments.  Sign up for a free account, all you need is a valid e-mail address.  Once you log in, you'll see the following screen:

image


Click on the "Instant Payment Notification" link.  You'll have to enter your IPN Handler URL from the site you've created.  Running this simulation will post back to your public URL and verify that you IPN code is (hopefully) working correctly.  PayPal will throw an error if it can't hit your URL. 

*Note that you can NOT have a port number in your IPN Handler URL.  If you include a port number, PayPal will thrown an error stating that it can not hit the URL. 

Happy Programming!


Additional Resources:

-How to Setup PayPal IPN Test Environment