From ce988c95121ce7e2ab736ab993398f41af0e52c1 Mon Sep 17 00:00:00 2001 From: spirobel Date: Thu, 13 Jul 2023 20:12:26 +0800 Subject: [PATCH] DEV: continue to use subscribe_controller instead of introducting a new controller --- .../pricingtable_controller.rb | 9 --------- .../subscribe_controller.rb | 15 +-------------- .../discourse/components/campaign-banner.js | 14 ++++++++------ .../javascripts/discourse/models/admin-product.js | 12 +++++++----- plugin.rb | 13 +------------ 5 files changed, 17 insertions(+), 46 deletions(-) delete mode 100644 app/controllers/discourse_subscriptions/pricingtable_controller.rb diff --git a/app/controllers/discourse_subscriptions/pricingtable_controller.rb b/app/controllers/discourse_subscriptions/pricingtable_controller.rb deleted file mode 100644 index 1328c83..0000000 --- a/app/controllers/discourse_subscriptions/pricingtable_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module StripeDiscourseSubscriptions - class PricingtableController < ::ApplicationController - def index - head 200 - end - end -end diff --git a/app/controllers/discourse_subscriptions/subscribe_controller.rb b/app/controllers/discourse_subscriptions/subscribe_controller.rb index 0670fec..de19e9b 100644 --- a/app/controllers/discourse_subscriptions/subscribe_controller.rb +++ b/app/controllers/discourse_subscriptions/subscribe_controller.rb @@ -11,20 +11,7 @@ module DiscourseSubscriptions requires_login except: %i[index contributors show] def index - begin - product_ids = Product.all.pluck(:external_id) - products = [] - - if product_ids.present? && is_stripe_configured? - response = ::Stripe::Product.list({ ids: product_ids, active: true }) - - products = response[:data].map { |p| serialize_product(p) } - end - - render_json_dump products - rescue ::Stripe::InvalidRequestError => e - render_json_error e.message - end + head 200 end def contributors diff --git a/assets/javascripts/discourse/components/campaign-banner.js b/assets/javascripts/discourse/components/campaign-banner.js index 41e34f8..d974240 100644 --- a/assets/javascripts/discourse/components/campaign-banner.js +++ b/assets/javascripts/discourse/components/campaign-banner.js @@ -58,12 +58,14 @@ export default Component.extend({ } if (this.currentUser && this.showContributors) { - return ajax("/s/contributors", { method: "get" }).then((result) => { - this.setProperties({ - contributors: result, - loading: false, - }); - }); + return ajax("/subscriptions/contributors", { method: "get" }).then( + (result) => { + this.setProperties({ + contributors: result, + loading: false, + }); + } + ); } }, diff --git a/assets/javascripts/discourse/models/admin-product.js b/assets/javascripts/discourse/models/admin-product.js index 61d5de6..ae60104 100644 --- a/assets/javascripts/discourse/models/admin-product.js +++ b/assets/javascripts/discourse/models/admin-product.js @@ -40,12 +40,14 @@ const AdminProduct = EmberObject.extend({ AdminProduct.reopenClass({ findAll() { - return ajax("/s/admin/products", { method: "get" }).then((result) => { - if (result === null) { - return { unconfigured: true }; + return ajax("/subscriptions/admin/products", { method: "get" }).then( + (result) => { + if (result === null) { + return { unconfigured: true }; + } + return result.map((product) => AdminProduct.create(product)); } - return result.map((product) => AdminProduct.create(product)); - }); + ); }, find(id) { diff --git a/plugin.rb b/plugin.rb index 11fae25..4b9c43a 100644 --- a/plugin.rb +++ b/plugin.rb @@ -68,17 +68,8 @@ require_relative "app/controllers/concerns/group" after_initialize do ::Stripe.api_version = "2024-04-10" - module ::StripeDiscourseSubscriptions - class Engine < ::Rails::Engine - engine_name "stripe-discourse-subscriptions" - isolate_namespace StripeDiscourseSubscriptions - end - end - StripeDiscourseSubscriptions::Engine.routes.draw { get "/" => "pricingtable#index" } - require_relative "app/controllers/discourse_subscriptions/pricingtable_controller.rb" - Discourse::Application.routes.append do - mount ::StripeDiscourseSubscriptions::Engine, at: "subscriptions" + mount ::DiscourseSubscriptions::Engine, at: "subscriptions" end ::Stripe.set_app_info( @@ -87,8 +78,6 @@ after_initialize do url: "https://github.com/discourse/discourse-subscriptions", ) - Discourse::Application.routes.append { mount ::DiscourseSubscriptions::Engine, at: "s" } - add_to_serializer(:site, :show_campaign_banner) do begin enabled = SiteSetting.discourse_subscriptions_enabled