Gem installation

gem 'stripe'
gem 'stripe_event'

Endpoint

# routes.rb

mount StripeEvent::Engine, at: '/webhooks/stripe'

Configuration

# /config/initializers/stripe.rb

Stripe.api_key = Rails.application.credentials.dig(:stripe, Rails.env.to_sym, :private_key)

StripeEvent.signing_secret = Rails.application.credentials.dig(:stripe, Rails.env.to_sym, :endpoint_secret)

StripeEvent.configure do |events|
  events.subscribe 'customer.subscription.created' do |event|
		...
  end

  events.all do |event|
    logger.info "Stripe Event: #{event.type}"
  end

  def logger
    @logger ||= Logger.new('log/stripe_webhooks.log')
  end
end

Stripe CLI

# README.md
## Test stripe
- Install Stripe CLI <https://stripe.com/docs/stripe-cli>
- Login to stripe CLI `stripe login`
- Run stripe CLI `stripe listen --forward-to localhost:3000/webhooks/stripe`