integrallis / stripe_event

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

Uninitialized constant NameError on server startup #138

Closed christianrolle closed 3 years ago

christianrolle commented 3 years ago

Current Rails 6.0 implementation:

# config/initializers/stripe.rb
StripeEvent.configure do |events|
  events.subscribe 'charge.failed', Stripe::ChargeFailedInteractor
end

and

# app/interactors/stripe/failed_charge_interactor.rb
module Stripe
  class FailedChargeInteractor
    include Interactor

    def call(event)
      Rails.logger.error("Stripe charge failed: #{params}")
    end
  end
end

and then running the server with rails s:

/.rvm/gems/ruby-2.7.2@fps/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/active_support.rb:61:in `block in load_missing_constant': uninitialized constant Stripe::ChargeFailedInteractor (NameError)
    78: from bin/rails:3:in `<main>'
    77: from bin/rails:3:in `load'
    76: from /home/christian/work/evopark/fps_rails/bin/spring:15:in `<top (required)>'
    75: from /home/christian/work/evopark/fps_rails/bin/spring:15:in `require'
    74: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<top (required)>'
    73: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `load'
    72: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/spring-2.1.1/bin/spring:49:in `<top (required)>'
    71: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/spring-2.1.1/lib/spring/client.rb:30:in `run'
    70: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/spring-2.1.1/lib/spring/client/command.rb:7:in `call'
    69: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `call'
    68: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `load'
    67: from /home/christian/work/evopark/fps_rails/bin/rails:9:in `<top (required)>'
    66: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    65: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    64: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    63: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    62: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    61: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/railties-6.0.3.4/lib/rails/commands.rb:18:in `<main>'
    60: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/railties-6.0.3.4/lib/rails/command.rb:46:in `invoke'
    59: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/railties-6.0.3.4/lib/rails/command/base.rb:69:in `perform'
    58: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
    57: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
    56: from /home/christian/.rvm/gems/ruby-2.7.2@fps/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'

Do I miss out on something?

daapower commented 1 year ago

How did you solve this? I'm having the same issue once moving to Rails 7.0

daapower commented 1 year ago

solved my issues, due to Rails 7.0+ loading I had to make require statements of each Stripe module as they weren't automatically loaded like in Rails 5

DmzTheo commented 1 year ago

@daapower I having the same issue on moving to Rails 7, how did you make require statement of each Stripe module ?

KevinBerthier commented 1 year ago

@DmzTheo assuming that your handler are in app/services/stripe_webhook

Dir[Rails.root.join('app/services/stripe_webhook/*.rb')].each do |file|
  require file
end