title: How to set up a callback in an initializer?
body: <p>I'm using Koudoku for subscriptions. I want to do different things after receiving a Stripe webhook.</p>
  
  <p><a href="https://github.com/andrewculver/koudoku#webhooks" rel="nofollow noreferrer">In the docs</a>, it shows you can add a callback like so:</p>
  
  <pre><code>Koudoku.setup do |config|
    config.subscriptions_owned_by = :user
    config.stripe_publishable_key = ENV['STRIPE_PUBLISHABLE_KEY']
    config.stripe_secret_key = ENV['STRIPE_SECRET_KEY']
  
    # add webhooks
    config.subscribe 'charge.failed', YourChargeFailed
  end
  </code></pre>
  
  <p>What I can't figure out how to write the <code>YourChargeFailed</code> part. I've tried something like:</p>
  
  <pre><code> config.subscribe 'order.payment_succeeded', ActiveRecord::Subscription.after_successful_payment
  </code></pre>
  
  <p>but I get <code>undefined method after_successful_payment for #&lt;Class:0x007fb845849b30&gt;</code></p>
  
  <p>How can I successfully subscribe to Stripe events, capture the return data, and initiate a callback function?</p>
  
  <p>Thanks!</p>
  
  <p>UPDATE</p>
  
  <p>Here is what I've tried, and the corresponding errors I'm receiving:</p>
  
  <p>purchases_helper.rb</p>
  
  <pre><code>module PurchasesHelper
    require 'stripe'
  
    def stripe_webhook(event)
      puts 'Purchases Helper'
      puts 'invoice.payment_succeeded'
      @customer = Stripe::Customer.retrieve(event[:data][:object][:customer])
  
      @user = User.find_by(email: @customer[:email])
  
      @badge = Badge.find_by(condition: '2019Purchase')
      @badges_user = BadgesUser.find_by(user_id: @user.id, badge_id: @badge.id)
      # if @badges_user === nil
      #   BadgesUser.create(user_id: user.id, badge_id: badge.id)
      # end
      puts 'badge created'
    end
  end
  </code></pre>
  
  <p>initializers/koudoku.rb</p>
  
  <pre><code>Koudoku.setup do |config|
    include ::PurchasesHelper
  
    config.subscribe 'charge.succeeded' do |event|
      puts 'charge created'
      ::PurchasesHelper.stripe_webhook(event)
    end
  
  end
  </code></pre>
  
  <p>ERROR:</p>
  
  <pre><code>undefined method `stripe_webhook' for PurchasesHelper:Module excluded from capture: Not configured to send/capture in environment 'development'
  
  NoMethodError (undefined method `stripe_webhook' for PurchasesHelper:Module):
  </code></pre>
  
  <p>Another attempt:</p>
  
  <pre><code>Koudoku.setup do |config|
    config.subscribe 'charge.succeeded' do |event|
      puts 'charge created'
      PurchasesHelper.stripe_webhook(event)
    end
  end
  </code></pre>
  
  <p>ERROR:</p>
  
  <pre><code>undefined method `stripe_webhook' for PurchasesHelper:Module excluded from capture: Not configured to send/capture in environment 'development'
  
  NoMethodError (undefined method `stripe_webhook' for PurchasesHelper:Module):
  </code></pre>
  
  <p>3rd Attempt:</p>
  
  <pre><code>Koudoku.setup do |config|
    include PurchasesHelper
  
    config.subscribe 'charge.succeeded' do |event|
      puts 'charge created'
      stripe_webhook(event)
    end
  
  end
  </code></pre>
  
  <p>ERROR:</p>
  
  <pre><code>A copy of PurchasesHelper has been removed from the module tree but is still active! excluded from capture: Not configured to send/capture in environment 'development'
  
  ArgumentError (A copy of PurchasesHelper has been removed from the module tree but is still active!):
  </code></pre>