Pippin
Pippin is a Rails Engine for processing PayPal IPN requests. It automatically adds a route to your Rails application that validates and processes IPNs.
If you want to do something with those IPN objects (and I recommend you do), then all you need to do is attach a subscriber to the notification, and that’ll fire as each valid IPN is received.
Using Rails 3.0? Then you better jump back to the 0.1.1 release of this library, which does not use ActiveSupport::Notifications.
Installation and Usage
Just add it to your Gemfile:
gem 'pippin', '~> 1.0.0'
Then somewhere (perhaps in an initializer), subscribe to the notifications:
ActiveSupport::Notifications.subscribe('received.ipn') do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
ipn = event.payload[:ipn]
# use IPN data
ipn.params # => {'business' => '[email protected]', 'txn_type' => ...}
end
There are also notifications fired using the txn_type parameter as the prefix, if you wish to subscribe to certain types:
ActiveSupport::Notifications.subscribe('subscr_signup.ipn') do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
ipn = event.payload[:ipn]
# A subscription sign up has happened. Do something!
end
Any parameters with the suffix ‘_date’ in their name will automatically be translated from PayPal’s ugly date string to an appropriate Time object.
When constructing your form that redirects people to PayPal, you’ll want to set the notify_url
parameter to use Pippin’s URL that has automatically been added to your routes: 'pippin/ipns'
.
Contributing
Contributions are very much welcome – but keep in mind the following:
- Keep patches in a separate branch.
- Write tests for your patches.
- Don’t mess with the version or history file. I’ll take care of that when the patch is merged in.
Credits
Copyright © 2012, Pippin is developed and maintained by Pat Allan, and is released under the open MIT Licence.