Rails adventures and PayPal IPN

I’m happy I’ve managed to prevent the application from dying on me – looks like it was because I was missing declarations such as the following:

FastCgiServer /var/www/sureboss_html/shop/dispatch.fcgi -initial-env RAILS_ENV=production -processes 2 -idle-timeout 600

This ensures that Apache handles the FCGI processes, rather than more just being created on request – this just ended up with processes kicking around doing nothing but unstability on my VPS.

So far I’m impressed with Rails:http://www.rubyonrails.org/ – I’ve got a prototype site up and running quicker than I would’ve previously expected (thanks to the Pragmatic Bookshelf’s Agile Web Development boo) and I absolutely love the way that it forces you to build stuff correctly. Things that have previously been considered ‘bad form’ or code smells.

For instance, take ASP.NET – the environment I do most of my professional work in – where a lot of the code for your average server control involves a very, very tricky lifecycle (incidentally i’ve still got a post in draft about writing a composite databound server control – the thing that has caused me most pain in the past). Well, the intended way is to build a control with private fields for each contained control, instantiate the types inside CreateChildControls, initialise the control (excluding any databound info) inside OnInit etc. The problem being, you must be aware of the implications for the rest of the lifecycle – when data has been posted back and the control tree re-initialised, when you’re allowed to access child and/or parent controls etc.

Rails is different and, to an extent, closer to a more traditional approach – that of the old-school classic ASP, PHP and other scripted languages – and also that of many Java web frameworks such as Struts, Spring MVC and Webflows etc. where the developer is more aware of the issues surrounding web development’s request/response model. Although I like ASP.NET, sometimes I get the feeling its made things more complicated than it needs to be – and I’m hoping the changed ASP.NET 2 model will have improved things.

I’ve got a basic shopping cart, and the final confirmation/checkout page sorted. For PayPal integration this generates some form data that is posted to PayPal, allowing the user to proceed through and pay etc.

However, IPN (Instant Payment Notification) should allow me to receive notification of when this succeeds/fails so I can update the database of orders, email people etc. I’m using PayPal’s developer sandbox to get this working but it just seems to ignore that I want IPN support – checking Apache’s access logs there’s no mention of any request for my IPN controller from PayPal.

This just seems to be solid proof for testing only things you can control – ideally I’d like to stub out PayPal and just test that my controller (with it’s use of the PayPal ruby gem) works as it should. I previously gave up with this as it seemed to involve mocking too much – something that’s been causing some furor on the TDD mailing list I’m a subscriber of. Maybe it’s worth another look. I’m told it’s the kind of thing Ruby is designed for?

In any case, if anyone’s actually had PayPal IPN working on the Sandbox could they leave me a comment and point me in the right direction please?

UPDATE: I’ve sorted most of the problems. I’ve also posted a more detailed guide of how I got it all working together.