diff --git a/.env_sample b/.env_sample index 2cac95618..615574c08 100644 --- a/.env_sample +++ b/.env_sample @@ -133,11 +133,6 @@ export SLACK_CHANNEL="" export SLACK_DEPLOY_CHANNEL="" export SLACK_WEBHOOK_URL="" -# Stripe for payment system -# (https://stripe.com/docs/api) -export STRIPE_PUBLISHABLE_KEY="Optional" -export STRIPE_SECRET_KEY="Optional" - # For video calling in DEV Connect # (https://www.twilio.com/docs/video) export TWILIO_ACCOUNT_SID="Optional" diff --git a/app/controllers/admin/configs_controller.rb b/app/controllers/admin/configs_controller.rb index f70a93987..57aea9412 100644 --- a/app/controllers/admin/configs_controller.rb +++ b/app/controllers/admin/configs_controller.rb @@ -32,6 +32,8 @@ module Admin twitter_hashtag shop_url payment_pointer + stripe_api_key + stripe_publishable_key health_check_token feed_style default_font diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9a95ed76d..069d5e64f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -126,4 +126,8 @@ class ApplicationController < ActionController::Base def api_action? self.class.to_s.start_with?("Api::") end + + def initialize_stripe + Stripe.api_key = SiteConfig.stripe_api_key + end end diff --git a/app/controllers/credits_controller.rb b/app/controllers/credits_controller.rb index 9dbcc4d4a..7a6de018a 100644 --- a/app/controllers/credits_controller.rb +++ b/app/controllers/credits_controller.rb @@ -1,5 +1,6 @@ class CreditsController < ApplicationController before_action :authenticate_user! + before_action :initialize_stripe def index @user_unspent_credits_count = current_user.credits.unspent.size diff --git a/app/controllers/stripe_active_cards_controller.rb b/app/controllers/stripe_active_cards_controller.rb index f62776520..337072078 100644 --- a/app/controllers/stripe_active_cards_controller.rb +++ b/app/controllers/stripe_active_cards_controller.rb @@ -1,5 +1,6 @@ class StripeActiveCardsController < ApplicationController before_action :authenticate_user! + before_action :initialize_stripe AUDIT_LOG_CATEGORY = "user.credit_card.edit".freeze private_constant :AUDIT_LOG_CATEGORY diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index df92e1daf..50f8fbbaa 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,6 +7,7 @@ class UsersController < ApplicationController after_action :verify_authorized, except: %i[index signout_confirm add_org_admin remove_org_admin remove_from_org] before_action :authenticate_user!, only: %i[onboarding_update onboarding_checkbox_update] before_action :set_suggested_users, only: %i[index] + before_action :initialize_stripe, only: %i[edit] INDEX_ATTRIBUTES_FOR_SERIALIZATION = %i[id name username summary profile_image].freeze private_constant :INDEX_ATTRIBUTES_FOR_SERIALIZATION diff --git a/app/lib/constants/site_config.rb b/app/lib/constants/site_config.rb index b5905b322..147342293 100644 --- a/app/lib/constants/site_config.rb +++ b/app/lib/constants/site_config.rb @@ -139,6 +139,16 @@ module Constants "See: https://github.com/thepracticaldev/dev.to/pull/6345", placeholder: "$pay.somethinglikethis.co/value" }, + stripe_api_key: { + description: "Secret Stripe key for receiving payments. " \ + "See: https://stripe.com/docs/keys", + placeholder: "sk_live_...." + }, + stripe_publishable_key: { + description: "Public Stripe key for receiving payments. " \ + "See: https://stripe.com/docs/keys", + placeholder: "pk_live_...." + }, mailchimp_newsletter_id: { description: "Main Newsletter ID", placeholder: "" diff --git a/app/models/site_config.rb b/app/models/site_config.rb index d2cbcc2dc..497499e27 100644 --- a/app/models/site_config.rb +++ b/app/models/site_config.rb @@ -80,7 +80,9 @@ class SiteConfig < RailsSettings::Base } # Monetization - field :payment_pointer, type: :string # Experimental + field :payment_pointer, type: :string + field :stripe_api_key, type: :string, default: ApplicationConfig["STRIPE_SECRET_KEY"] + field :stripe_publishable_key, type: :string, default: ApplicationConfig["STRIPE_PUBLISHABLE_KEY"] field :shop_url, type: :string # Newsletter diff --git a/app/views/admin/configs/show.html.erb b/app/views/admin/configs/show.html.erb index 5297e1a62..a5c9425a5 100644 --- a/app/views/admin/configs/show.html.erb +++ b/app/views/admin/configs/show.html.erb @@ -611,6 +611,24 @@
<%= Constants::SiteConfig::DETAILS[:shop_url][:description] %>
+
+ <%= admin_config_label :stripe_api_key %> + <%= f.text_field :stripe_api_key, + class: "form-control", + value: SiteConfig.stripe_api_key, + placeholder: Constants::SiteConfig::DETAILS[:stripe_api_key][:placeholder] %> +
<%= Constants::SiteConfig::DETAILS[:stripe_api_key][:description] %>
+
+ +
+ <%= admin_config_label :stripe_publishable_key %> + <%= f.text_field :stripe_publishable_key, + class: "form-control", + value: SiteConfig.stripe_publishable_key, + placeholder: Constants::SiteConfig::DETAILS[:stripe_publishable_key][:placeholder] %> +
<%= Constants::SiteConfig::DETAILS[:stripe_publishable_key][:description] %>
+
+
<%= admin_config_label :payment_pointer %> <%= f.text_field :payment_pointer, diff --git a/app/views/credits/new.html.erb b/app/views/credits/new.html.erb index f1f4fd16a..d12998973 100644 --- a/app/views/credits/new.html.erb +++ b/app/views/credits/new.html.erb @@ -144,7 +144,7 @@