-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
nil class error for test and live events #1
Comments
@barancw, thanks for posting. I think making the authentication step optional would be useful. I'll try add that to the next release. This forum post was the reason I decided to retrieve the event by default. Accommodating HTTP basic auth is also a feature I'd like to add. It's unfortunate that retrieving the request breaks the "test webhooks" button. For manual testing, creating payments/customers/etc. in test mode through the dashboard will trigger webhooks. Those will have valid event information included. I can't determine the cause of your issue from the details supplied. Can you post the subscriber block? |
@invisiblefunnel, thanks for the reply - Here's my subscribe block: StripeEvent.registration do
subscribe do |event|
Rails.logger.info event
end
end At first I tried just an empty block, like this: StripeEvent.registration do
subscribe do |event|
end
end I should be able to use a blank block and see in my logs that I send stripe a 200 status code when it sends the hook. Instead I'm sending a 500 because of the "nil" class error that I'm getting from the @event instance variable. I thought maybe my keys could be set wrong but I can make the call correctly from the console so my keys have to be set correctly. Also - it's strange that I don't get the stripe error (Status 404) in my log output. Just the reference to the nil class. Hopefully, I'm just making a dumb n00b error in the subscriber block :) Thanks for your help, |
@barancw Your setup looks correct. I'll try to recreate the error and post back with my findings. |
Here's a dump of my Gemfile.lock so you can see what versions I'm running:
|
Here's a strange turn of events ... after running a database migration, the hooks are coming in now with a 200 status code. I'm going to keep digging into this. Very strange, these events should be unrelated. I didn't modify any of the stripe_event code. before migration:Started POST "/stripe-comm-hook" for 50.18.189.115 at 2012-08-13 14:29:11 -0400 after migration:Started POST "/stripe-comm-hook" for 50.18.189.113 at 2012-08-13 14:46:17 -0400 After writing this, I realized I'm also missing this warning: WARNING: Can't verify CSRF token authenticity. |
Fix in pull request: #2 |
Still an issue: #2 (comment). |
I will say that sometimes I do get a 200 and everything works just fine (I'm not sure why it sometimes works) but right now I'm getting the 500 error most of the time. The patch from pull request #2 seems to have solved the issue, but will test further today. |
Fix issue #1 and consolidate controllers
I noticed from your implementation that test webhooks sent from the "test webhooks" button in the account settings panel on stripe will fail. They send an id of "evt_00000000000000" which will throw a 404 error when tried to retrieve as you are doing in your application_controller.rb on line 7: @event = Stripe::Event.retrieve(params[:id])
Now, I figured that I'd be fine for live transactions. I still end up in the same boat here:
Started POST "/stripe-comm-hook" for 50.18.189.119 at 2012-08-13 00:22:05 -0400
Processing by StripeEvent::WebhookController#event as XML
Parameters: {"object"=>"event", "type"=>"customer.updated", "created"=>1344828074, "pending_webhooks"=>1, "data"=>"object"=>{"id"=>"cus_08bwsfKEsvPJBm", "discount"=>nil, "description"=>"Baran, Christopherr", account_balance"=>0, "livemode"=>false, "active_card"=>nil, "object"=>"customer", "email"=>"cb@chrisbaran.net", created"=>1344375666, "subscription"=>{"customer"=>"cus_08bwsfKEsvPJBm", "start"=>1344789456, "ended_at"=>nil, trial_end"=>1347381456, "current_period_start"=>1344789456, "object"=>"subscription", "canceled_at"=>nil, current_period_end"=>1347381456, "status"=>"trialing", "trial_start"=>1344789456, "cancel_at_period_end"=>false, "plan"=>"id"=>"10", "currency"=>"usd", "trial_period_days"=>30, "livemode"=>false, "object"=>"plan", "amount"=>2000, name"=>"Pipe Fitters - Full Phone List", "interval"=>"month"}}, "delinquent"=>false}, "previous_attributes"=>"description"=>"Baran, Christopher"}}, "livemode"=>false, "id"=>"evt_0AZYkJQPKaMmhR", webhook"=>{"object"=>"event", "type"=>"customer.updated", "created"=>1344828074, "pending_webhooks"=>1, "data"=>"object"=>{"id"=>"cus_08bwsfKEsvPJBm", "discount"=>nil, "description"=>"Baran, Christopherr", account_balance"=>0, "livemode"=>false, "active_card"=>nil, "object"=>"customer", "email"=>"cb@chrisbaran.net", created"=>1344375666, "subscription"=>{"customer"=>"cus_08bwsfKEsvPJBm", "start"=>1344789456, "ended_at"=>nil, trial_end"=>1347381456, "current_period_start"=>1344789456, "object"=>"subscription", "canceled_at"=>nil, current_period_end"=>1347381456, "status"=>"trialing", "trial_start"=>1344789456, "cancel_at_period_end"=>false, "plan"=>"id"=>"10", "currency"=>"usd", "trial_period_days"=>30, "livemode"=>false, "object"=>"plan", "amount"=>2000, name"=>"Pipe Fitters - Full Phone List", "interval"=>"month"}}, "delinquent"=>false}, "previous_attributes"=>"description"=>"Baran, Christopher"}}, "livemode"=>false, "id"=>"evt_0AZYkJQPKaMmhR", controller"=>"stripe_event/webhook", "action"=>"event"}}
WARNING: Can't verify CSRF token authenticity
Completed 500 Internal Server Error in 31ms
NoMethodError (undefined method
type' for nil:NilClass): stripe_event (0.3.0) lib/stripe_event.rb:12:in
publish'stripe_event (0.3.0) app/controllers/stripe_event/webhook_controller.rb:4:in
event' actionpack (3.2.5) lib/action_controller/metal/implicit_render.rb:4:in
send_action'actionpack (3.2.5) lib/abstract_controller/base.rb:167:in
process_action' actionpack (3.2.5) lib/action_controller/metal/rendering.rb:10:in
process_action'actionpack (3.2.5) lib/abstract_controller/callbacks.rb:18:in
block in process_action' activesupport (3.2.5) lib/active_support/callbacks.rb:414:in
_run__377245576__process_action__943494040__callbacks'activesupport (3.2.5) lib/active_support/callbacks.rb:405:in
__run_callback' activesupport (3.2.5) lib/active_support/callbacks.rb:385:in
_run_process_action_callbacks'activesupport (3.2.5) lib/active_support/callbacks.rb:81:in
run_callbacks' actionpack (3.2.5) lib/abstract_controller/callbacks.rb:17:in
process_action'actionpack (3.2.5) lib/action_controller/metal/rescue.rb:29:in
process_action' actionpack (3.2.5) lib/action_controller/metal/instrumentation.rb:30:in
block in process_action'activesupport (3.2.5) lib/active_support/notifications.rb:123:in
block in instrument' activesupport (3.2.5) lib/active_support/notifications/instrumenter.rb:20:in
instrument'activesupport (3.2.5) lib/active_support/notifications.rb:123:in
instrument' actionpack (3.2.5) lib/action_controller/metal/instrumentation.rb:29:in
process_action'actionpack (3.2.5) lib/action_controller/metal/params_wrapper.rb:206:in
process_action' activerecord (3.2.5) lib/active_record/railties/controller_runtime.rb:18:in
process_action'actionpack (3.2.5) lib/abstract_controller/base.rb:121:in
process' actionpack (3.2.5) lib/abstract_controller/rendering.rb:45:in
process'rack-mini-profiler (0.1.7) lib/mini_profiler/profiling_methods.rb:62:in
block in profile_method' actionpack (3.2.5) lib/action_controller/metal.rb:203:in
dispatch'actionpack (3.2.5) lib/action_controller/metal/rack_delegation.rb:14:in
dispatch' actionpack (3.2.5) lib/action_controller/metal.rb:246:in
block in action'actionpack (3.2.5) lib/action_dispatch/routing/route_set.rb:73:in
call' actionpack (3.2.5) lib/action_dispatch/routing/route_set.rb:73:in
dispatch'actionpack (3.2.5) lib/action_dispatch/routing/route_set.rb:36:in
call' journey (1.0.4) lib/journey/router.rb:68:in
block in call'journey (1.0.4) lib/journey/router.rb:56:in
each' journey (1.0.4) lib/journey/router.rb:56:in
call'actionpack (3.2.5) lib/action_dispatch/routing/route_set.rb:600:in
call' railties (3.2.5) lib/rails/engine.rb:479:in
call'railties (3.2.5) lib/rails/railtie/configurable.rb:30:in
method_missing' journey (1.0.4) lib/journey/router.rb:68:in
block in call'journey (1.0.4) lib/journey/router.rb:56:in
each' journey (1.0.4) lib/journey/router.rb:56:in
call'actionpack (3.2.5) lib/action_dispatch/routing/route_set.rb:600:in
call' omniauth (1.1.0) lib/omniauth/strategy.rb:177:in
call!'omniauth (1.1.0) lib/omniauth/strategy.rb:157:in
call' omniauth (1.1.0) lib/omniauth/strategy.rb:177:in
call!'omniauth (1.1.0) lib/omniauth/strategy.rb:157:in
call' omniauth (1.1.0) lib/omniauth/strategy.rb:177:in
call!'omniauth (1.1.0) lib/omniauth/strategy.rb:157:in
call' omniauth (1.1.0) lib/omniauth/strategy.rb:177:in
call!'omniauth (1.1.0) lib/omniauth/strategy.rb:157:in
call' omniauth (1.1.0) lib/omniauth/strategy.rb:177:in
call!'omniauth (1.1.0) lib/omniauth/strategy.rb:157:in
call' omniauth (1.1.0) lib/omniauth/strategy.rb:177:in
call!'omniauth (1.1.0) lib/omniauth/strategy.rb:157:in
call' sass (3.1.19) lib/sass/plugin/rack.rb:54:in
call'warden (1.1.1) lib/warden/manager.rb:35:in
block in call' warden (1.1.1) lib/warden/manager.rb:34:in
catch'warden (1.1.1) lib/warden/manager.rb:34:in
call' actionpack (3.2.5) lib/action_dispatch/middleware/best_standards_support.rb:17:in
call'rack (1.4.1) lib/rack/etag.rb:23:in
call' rack (1.4.1) lib/rack/conditionalget.rb:35:in
call'actionpack (3.2.5) lib/action_dispatch/middleware/head.rb:14:in
call' actionpack (3.2.5) lib/action_dispatch/middleware/params_parser.rb:21:in
call'actionpack (3.2.5) lib/action_dispatch/middleware/flash.rb:238:in
call' rack (1.4.1) lib/rack/session/abstract/id.rb:205:in
context'rack (1.4.1) lib/rack/session/abstract/id.rb:200:in
call' actionpack (3.2.5) lib/action_dispatch/middleware/cookies.rb:338:in
call'activerecord (3.2.5) lib/active_record/query_cache.rb:64:in
call' activerecord (3.2.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in
call'actionpack (3.2.5) lib/action_dispatch/middleware/callbacks.rb:28:in
block in call' activesupport (3.2.5) lib/active_support/callbacks.rb:405:in
_run__599555566__call__907623258__callbacks'activesupport (3.2.5) lib/active_support/callbacks.rb:405:in
__run_callback' activesupport (3.2.5) lib/active_support/callbacks.rb:385:in
_run_call_callbacks'activesupport (3.2.5) lib/active_support/callbacks.rb:81:in
run_callbacks' actionpack (3.2.5) lib/action_dispatch/middleware/callbacks.rb:27:in
call'actionpack (3.2.5) lib/action_dispatch/middleware/reloader.rb:65:in
call' actionpack (3.2.5) lib/action_dispatch/middleware/remote_ip.rb:31:in
call'actionpack (3.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:16:in
call' actionpack (3.2.5) lib/action_dispatch/middleware/show_exceptions.rb:56:in
call'railties (3.2.5) lib/rails/rack/logger.rb:26:in
call_app' railties (3.2.5) lib/rails/rack/logger.rb:16:in
call'actionpack (3.2.5) lib/action_dispatch/middleware/request_id.rb:22:in
call' rack (1.4.1) lib/rack/methodoverride.rb:21:in
call'rack (1.4.1) lib/rack/runtime.rb:17:in
call' activesupport (3.2.5) lib/active_support/cache/strategy/local_cache.rb:72:in
call'rack (1.4.1) lib/rack/lock.rb:15:in
call' actionpack (3.2.5) lib/action_dispatch/middleware/static.rb:62:in
call'rack-mini-profiler (0.1.7) lib/mini_profiler/profiler.rb:233:in
call' railties (3.2.5) lib/rails/engine.rb:479:in
call'railties (3.2.5) lib/rails/application.rb:220:in
call' rack (1.4.1) lib/rack/content_length.rb:14:in
call'railties (3.2.5) lib/rails/rack/log_tailer.rb:17:in
call' rack (1.4.1) lib/rack/handler/webrick.rb:59:in
service'c:/codeshopruby/lib/ruby/1.9.1/webrick/httpserver.rb:138:in
service' c:/codeshopruby/lib/ruby/1.9.1/webrick/httpserver.rb:94:in
run'c:/codeshopruby/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Rendered c:/codeshopruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.erb (3.0ms)
Rendered c:/codeshopruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.0ms)
Rendered c:/codeshopruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (26.0ms)
I can retrieve the event from my console just fine:
irb(main):007:0> Stripe::Event.retrieve("evt_0AZYkJQPKaMmhR").type
=> "customer.updated"
Do you have any ideas what I'm doing wrong?
Also, I understand that manually retrieving the event from the webhook increases security, but it the process this breaks the test webhooks and it also requires another request. Why didn't you just use the data payload in the hook itself?
The text was updated successfully, but these errors were encountered: