Created
March 29, 2016 23:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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