2019-09-11 05:55:35 -04:00
|
|
|
# frozen_string_literal: true
|
2019-09-11 05:27:24 -04:00
|
|
|
|
2019-12-02 02:58:14 -05:00
|
|
|
# name: discourse-subscriptions
|
2023-11-07 20:29:37 -05:00
|
|
|
# about: Allows admins to sell subscriptions to site content.
|
|
|
|
# meta_topic_id: 140818
|
2020-03-21 05:35:05 -04:00
|
|
|
# version: 2.8.1
|
2020-04-29 06:57:17 -04:00
|
|
|
# url: https://github.com/discourse/discourse-subscriptions
|
2020-05-22 12:20:05 -04:00
|
|
|
# authors: Rimian Perkins, Justin DiRose
|
2017-01-30 21:28:41 -05:00
|
|
|
|
2019-12-03 19:53:05 -05:00
|
|
|
enabled_site_setting :discourse_subscriptions_enabled
|
2017-01-31 19:35:21 -05:00
|
|
|
|
2024-04-16 13:28:07 -04:00
|
|
|
gem "stripe", "11.1.0"
|
2019-09-11 05:18:30 -04:00
|
|
|
|
2019-12-02 19:51:18 -05:00
|
|
|
register_asset "stylesheets/common/main.scss"
|
|
|
|
register_asset "stylesheets/common/layout.scss"
|
2019-12-05 21:52:03 -05:00
|
|
|
register_asset "stylesheets/common/subscribe.scss"
|
2021-06-02 14:15:03 -04:00
|
|
|
register_asset "stylesheets/common/campaign.scss"
|
2019-12-02 19:51:18 -05:00
|
|
|
register_asset "stylesheets/mobile/main.scss"
|
2020-05-28 11:32:57 -04:00
|
|
|
register_svg_icon "far-credit-card" if respond_to?(:register_svg_icon)
|
2019-09-11 07:14:48 -04:00
|
|
|
|
2024-03-06 11:45:55 -05:00
|
|
|
register_html_builder("server:before-head-close") do |controller|
|
|
|
|
"<script src='https://js.stripe.com/v3/' nonce='#{controller.helpers.csp_nonce_placeholder}'></script>"
|
2019-09-11 05:18:30 -04:00
|
|
|
end
|
|
|
|
|
2024-04-29 14:47:58 -04:00
|
|
|
register_html_builder("server:before-head-close") do |controller|
|
|
|
|
"<script async src='https://js.stripe.com/v3/pricing-table.js' nonce='#{controller.helpers.csp_nonce_placeholder}'></script>"
|
|
|
|
end
|
|
|
|
|
2022-12-29 07:35:06 -05:00
|
|
|
extend_content_security_policy(script_src: %w[https://js.stripe.com/v3/ https://hooks.stripe.com])
|
2019-09-11 05:18:30 -04:00
|
|
|
|
2022-12-29 07:35:06 -05:00
|
|
|
add_admin_route "discourse_subscriptions.admin_navigation", "discourse-subscriptions.products"
|
2019-09-13 22:56:28 -04:00
|
|
|
|
|
|
|
Discourse::Application.routes.append do
|
2022-12-29 07:35:06 -05:00
|
|
|
get "/admin/plugins/discourse-subscriptions" => "admin/plugins#index",
|
|
|
|
:constraints => AdminConstraint.new
|
|
|
|
get "/admin/plugins/discourse-subscriptions/products" => "admin/plugins#index",
|
|
|
|
:constraints => AdminConstraint.new
|
|
|
|
get "/admin/plugins/discourse-subscriptions/products/:product_id" => "admin/plugins#index",
|
|
|
|
:constraints => AdminConstraint.new
|
|
|
|
get "/admin/plugins/discourse-subscriptions/products/:product_id/plans" => "admin/plugins#index",
|
|
|
|
:constraints => AdminConstraint.new
|
|
|
|
get "/admin/plugins/discourse-subscriptions/products/:product_id/plans/:plan_id" =>
|
|
|
|
"admin/plugins#index",
|
|
|
|
:constraints => AdminConstraint.new
|
|
|
|
get "/admin/plugins/discourse-subscriptions/subscriptions" => "admin/plugins#index",
|
|
|
|
:constraints => AdminConstraint.new
|
|
|
|
get "/admin/plugins/discourse-subscriptions/plans" => "admin/plugins#index",
|
|
|
|
:constraints => AdminConstraint.new
|
|
|
|
get "/admin/plugins/discourse-subscriptions/plans/:plan_id" => "admin/plugins#index",
|
|
|
|
:constraints => AdminConstraint.new
|
|
|
|
get "/admin/plugins/discourse-subscriptions/coupons" => "admin/plugins#index",
|
|
|
|
:constraints => AdminConstraint.new
|
|
|
|
get "u/:username/billing" => "users#show", :constraints => { username: USERNAME_ROUTE_FORMAT }
|
|
|
|
get "u/:username/billing/:id" => "users#show", :constraints => { username: USERNAME_ROUTE_FORMAT }
|
|
|
|
get "u/:username/billing/subscriptions/card/:subscription_id" => "users#show",
|
|
|
|
:constraints => {
|
|
|
|
username: USERNAME_ROUTE_FORMAT,
|
|
|
|
}
|
2019-09-13 22:56:28 -04:00
|
|
|
end
|
|
|
|
|
2024-03-06 08:51:25 -05:00
|
|
|
module ::DiscourseSubscriptions
|
|
|
|
PLUGIN_NAME = "discourse-subscriptions"
|
|
|
|
end
|
|
|
|
|
|
|
|
require_relative "lib/discourse_subscriptions/engine"
|
|
|
|
require_relative "app/controllers/concerns/stripe"
|
|
|
|
require_relative "app/controllers/concerns/group"
|
2020-07-06 12:11:04 -04:00
|
|
|
|
2019-09-11 03:13:12 -04:00
|
|
|
after_initialize do
|
2024-04-16 13:28:07 -04:00
|
|
|
::Stripe.api_version = "2024-04-10"
|
2019-12-02 02:58:14 -05:00
|
|
|
|
|
|
|
::Stripe.set_app_info(
|
2022-12-29 07:35:06 -05:00
|
|
|
"Discourse Subscriptions",
|
2024-04-16 13:28:07 -04:00
|
|
|
version: "2.8.2",
|
2022-12-29 07:35:06 -05:00
|
|
|
url: "https://github.com/discourse/discourse-subscriptions",
|
2019-12-02 02:58:14 -05:00
|
|
|
)
|
2019-09-11 07:14:48 -04:00
|
|
|
|
2022-12-29 07:35:06 -05:00
|
|
|
Discourse::Application.routes.append { mount ::DiscourseSubscriptions::Engine, at: "s" }
|
2021-07-15 16:05:27 -04:00
|
|
|
|
|
|
|
add_to_serializer(:site, :show_campaign_banner) do
|
|
|
|
begin
|
|
|
|
enabled = SiteSetting.discourse_subscriptions_enabled
|
|
|
|
campaign_enabled = SiteSetting.discourse_subscriptions_campaign_enabled
|
|
|
|
goal_met = Discourse.redis.get("subscriptions_goal_met_date")
|
|
|
|
|
|
|
|
enabled && campaign_enabled && (!goal_met || 7.days.ago <= Date.parse(goal_met))
|
2022-12-29 07:35:06 -05:00
|
|
|
rescue StandardError
|
2021-07-15 16:05:27 -04:00
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2017-02-16 21:15:32 -05:00
|
|
|
end
|