Java PayPal IPN Servlet

For those following along my adventure to integrate with PayPal, here is the next step. I’ve created a Google AppEngine Java servlet that handles the Instant Payment Notification (IPN) messages PayPal sends your way. I’ve made the servlet freely available on GitHub in the hope of fostering some cooperation.

update: The project has been updated since this post and is now fully “Maven-ized”. Please see this post to check out the changes and read about future plans.

Sorry, no Maven this time. If you put the code in an Eclipse Vaadin/Google AppEngine project you only need to add the Objectify jar in the war/lib directory and you’re ready to get started.

The servlet lives in the /ipn context. So if you use PayPal’s IPN developer tool to create messages, don’t forget to add it.

All IPN messages that PayPal sends your way need to be validated. I’ve implemented the validation by postback. There is one issue, though, the PayPal sandbox servers can be slow from time to time. As Google puts a timeout of 10 seconds on every request you make, you might run into trouble.

The code worked flawlessly until today, right now I’m only getting timeouts. The IPN messages are stored anyway, but they are flagged as not validated. This allows you to continue processing the payment, you just need to investigate the messages later on.

The project also contains a small Vaadin application to easily access the messages. I haven’t done much parsing, except for the transaction type. I leave this as an exercise to the reader 🙂

update: The project has been updated since this post and is now fully “Maven-ized”. Please see this post to check out the changes and read about future plans.