This is a little gem that helps you parsing the return of the Pagseguro’s transaction notification.
You can find more info about the notification API here.
The first thing you’ll need to do is to enable the Pagseguro’s transaction notification. When you do that, you’ll receive a post in the URL that you just set up.
When you’re done, it’s time to set up the PagseguroCatcher params. If you’re using Rails, the best way to do that is creating an initializer and set the following parameters:
PagseguroCatcher.configure do |config| config.token = "YOUR CONFIG TOKEN" config.email = "firstname.lastname@example.org" end
Every time that some transaction occurs, you’ll receive a post in the URL that you set up on Pagseguro. When that post hits your app, you’ll do this (again, assuming you’re in a Rails application):
if request.post? if params[:notificationCode] && params[:notificationType] transaction = PagseguroCatcher::Checker.new(params[:notificationCode], params[:notificationType]).check # your implementation logic goes here end render :nothing => true end
transaction object contains the all the magic:
transaction.date # => Thu, 10 Feb 2011 16:13:41 -0300 transaction.payment_method_type # => Cartão de crédito
You can also access others sections as well:
transaction.sender.name # => "John Doe" transaction.amount.gross # => 199.99 transaction.shipping.zip # => "01452002"
Looping each item is easy too:
transaction.each_item do |item| puts item.description end Notebook Prata Notebook Rosa
- write the documentation
- implement a nice way to rescue the
::Checker#checkmethod, when the request isn’t successfull or the return is invalid
- maybe some nice logs?
- Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet
- Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it
- Fork the project
- Start a feature/bugfix branch
- Commit and push until you are happy with your contribution
- Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
- Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright © 2011 Matias H. Leidemer. See LICENSE.txt for