Skip to content

Instantly share code, notes, and snippets.

@digerata
Created March 29, 2016 23:39
Show Gist options
  • Save digerata/aa9c299ef3ea9a7940fd8e9f9e1bc1cf to your computer and use it in GitHub Desktop.
Save digerata/aa9c299ef3ea9a7940fd8e9f9e1bc1cf to your computer and use it in GitHub Desktop.
Stripe initializer that makes it easy to work with development and production keys.
# override in production...
if ENV['STRIPE_KEY']
Rails.logger.warn "Using production environment keys for Stripe."
STRIPE_KEY = ENV['STRIPE_KEY']
STRIPE_PUBLISH = ENV['STRIPE_PUBLISH']
else
Rails.logger.warn "Using test keys for Stripe."
# dev values...
STRIPE_KEY = "sk_test_KEY"
STRIPE_PUBLISH = "pk_test_PUBLISH"
end
Stripe.api_key = STRIPE_KEY
# If we use stripe webhooks, gem 'stripe_event' is needed for the following code
if ENV['STRIPE_WEBHOOK_SECRET']
StripeEvent.authentication_secret = ENV['STRIPE_WEBHOOK_SECRET']
else
StripeEvent.authentication_secret = Rails.application.secrets.stripe_webhook_secret
end
StripeEvent.configure do |events|
events.all do |event|
StripeService.process_event(event)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment