integrallis / stripe_event

Stripe webhook integration for Rails applications.
https://rubygems.org/gems/stripe_event
MIT License
842 stars 105 forks source link

Rails 4 Compatibility #13

Closed benubois closed 11 years ago

benubois commented 11 years ago

I'm running into some issues when testing stripe_event with Rails 4 Beta 1.

I'm happy to look into this, but I thought I'd ask to see if I could get an idea of where to start looking.

After removing the Rails 3.1 requirement in the gemspec, all posts to the mount point get a 404 not found error:

Started POST "/stripe" for 127.0.0.1 at 2013-03-04 03:38:55 -0800

ActionController::RoutingError (No route matches [POST] "/stripe"):
  vendor/bundle/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  vendor/bundle/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  vendor/bundle/gems/railties-4.0.0.beta1/lib/rails/rack/logger.rb:38:in `call_app'
  vendor/bundle/gems/railties-4.0.0.beta1/lib/rails/rack/logger.rb:21:in `block in call'
  vendor/bundle/gems/activesupport-4.0.0.beta1/lib/active_support/tagged_logging.rb:67:in `block in tagged'
  vendor/bundle/gems/activesupport-4.0.0.beta1/lib/active_support/tagged_logging.rb:25:in `tagged'
  vendor/bundle/gems/activesupport-4.0.0.beta1/lib/active_support/tagged_logging.rb:67:in `tagged'
  vendor/bundle/gems/railties-4.0.0.beta1/lib/rails/rack/logger.rb:21:in `call'
  vendor/bundle/gems/quiet_assets-1.0.2/lib/quiet_assets.rb:18:in `call_with_quiet_assets'
  vendor/bundle/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/request_id.rb:21:in `call'
  vendor/bundle/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
  vendor/bundle/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
  vendor/bundle/gems/activesupport-4.0.0.beta1/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  vendor/bundle/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
  vendor/bundle/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/static.rb:64:in `call'
  vendor/bundle/gems/railties-4.0.0.beta1/lib/rails/engine.rb:510:in `call'
  vendor/bundle/gems/railties-4.0.0.beta1/lib/rails/application.rb:96:in `call'
  vendor/bundle/gems/railties-4.0.0.beta1/lib/rails/railtie/configurable.rb:30:in `method_missing'
  /Users/ben/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:147:in `handle'
  /Users/ben/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:99:in `rescue in block (2 levels) in start'
  /Users/ben/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:96:in `block (2 levels) in start'
  /Users/ben/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:86:in `each'
  /Users/ben/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:86:in `block in start'
  /Users/ben/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:66:in `loop'
  /Users/ben/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:66:in `start'
  /Users/ben/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/lib/nack/server.rb:13:in `run'
  /Users/ben/Library/Application Support/Pow/Versions/0.4.0/node_modules/nack/bin/nack_worker:4:in `<main>'

  Rendered vendor/bundle/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.9ms)
  Rendered vendor/bundle/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/templates/routes/_route.html.erb (8.7ms)
  Rendered vendor/bundle/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/templates/routes/_route.html.erb (0.2ms)
  Rendered vendor/bundle/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/templates/routes/_table.html.erb (4.5ms)
  Rendered vendor/bundle/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (85.9ms)
benubois commented 11 years ago

Just wanted to add, stripe_event was working in this same app on Rails 3.2.12, and stripe_event is mounted like:

mount StripeEvent::Engine => '/stripe'
benubois commented 11 years ago

I think I got it. It's because match needs to specify :via options. So the fix is to change this:

StripeEvent::Engine.routes.draw do
  root :to => 'webhook#event'
end

to this

StripeEvent::Engine.routes.draw do
  root :to => 'webhook#event', :via => :post
end

I'll work on putting together a pull request.

invisiblefunnel commented 11 years ago

@benubois a pull request would be great. Thank you!

invisiblefunnel commented 11 years ago

@benubois @mattgoldman Thank you again for your help :heart: . I've pushed v0.6.0 with Rails 4 compatibility.