Written by Sean Behan on Sun Jun 17th 2012

If you use the Paypal sandbox you'll notice that there is an IPN Simulator test tool. You must be logged to use it. This tool lets you test an IPN handler script for your application. If your script is not correct and you try to send a test IPN transaction the simulator will spit out a misleading error message. It will report

IPN delivery failed. Unable to connect to the specified URL. Please verify the URL and try again.

What this actually means is that your server was contacted and your script failed! If you're using the wrong URL then this error message will apply, however. If you are using the right URL but you have a handler script that fails or is not right in some fashion, it seems logical to report the details of the failure! At the very least, it would be nice to hear

Indeed this URL address is correct, we said hello, but you refused our 'handshake'. How rude! Link to more info...

When I first tried out the simulator I assumed that the problem was with my DNS. I was testing against a subdomain that didn't have a cname set up. I wasn't too sure though if this was the problem. I could visit the URL I specified in my web browser and ping my domain, etc. I eventually got it working after checking some log files. I had to parse my apache logs to fnd that the IPN parameters were indeed posted to my server. This led me to the error in my code.

I'm not blaming Paypal 100%. The error was ultimately on my end. Nonetheless, Paypal did not aid in my troubleshooting endeavor. Instead they exacerbated the problem with an error message that made some assumptions about how I was using their tool. The first being that I understood the IPN protocol. The second, that I understood the way the IPN simulator is meant to work and the protocol under which it operates. Not my error because there is no documentation for the test tool.

Having to parse log files was a needless step in this otherwise simple remote request. Another issue that confounded the problem were the Paypal forums. Some people seemed to think that the IPN simulator was not even operational. Could this be because of misleading error messages?

In my opinion the Paypal documentation is thorough, however, very poorly organized. It seems also that a lot of the Paypal core docs are available in multiple/too many places. I've seen the IPN documentation in at least 3 or 4 different areas on the site. Each page adds more information or has a slightly different verbiage to explain the same problem.  Not to mention, there are way too many PDFs available for download! PDFs are great, but the content, organization and display is different from same documentation online.

At any rate, here is a quick Rails controller that will at least get your IPN simulated transactions to return success!

require 'uri'
require 'net/http'
require 'net/https'
class PaymentsController < ApplicationController
  #skip this check b/c post comes in from paypal
  protect_from_forgery :except => [:ipn]
  def ipn
    begin
      if request.post?
  #you need to post back to paypal the name/value string
  #in the same order received w/added cmd=_notify-validate
  from_pp = request.raw_post
  data = from_pp + "&amp;cmd=_notify-validate"
  url = URI.parse 'https://sandbox.paypal.com/cgi-bin/webscr'
  http = Net:HTTP.new url.host, url.port
  http.use_ssl = true

 response, data = http.post url.path, data, {
    'Content-Type' =&gt; 'application/x-www-for-urlencoded' }
  end
 rescue Exception =&gt; e
 logger.info("Error: paypal transaction #{e.message}")
end

end end


Tagged with..
#ipn #paypal #testing #Business

Just finishing up brewing up some fresh ground comments...