From 9c46794e800274d75ee6edc7a1f5a5013f6232d8 Mon Sep 17 00:00:00 2001 From: Justin DiRose Date: Thu, 28 May 2020 10:32:57 -0500 Subject: [PATCH] DEV: Remove deprecations & improve error handling (#12) - Replace deprecated methods on client - Fix broken dropdowns due to select kit 2 upgrade - Graceful error handling when Stripe keys are not configured but plugin enabled --- app/controllers/admin/products_controller.rb | 4 +- .../admin/subscriptions_controller.rb | 4 +- app/controllers/concerns/stripe.rb | 4 + app/controllers/products_controller.rb | 2 +- .../components/payment-options.js.es6 | 3 +- .../discourse/components/product-list.js.es6 | 15 +++- .../components/subscribe-card.js.es6 | 4 +- ...s-discourse-subscriptions-dashboard.js.es6 | 4 +- ...discourse-subscriptions-plans-index.js.es6 | 3 +- ...-discourse-subscriptions-plans-show.js.es6 | 3 +- ...ugins-discourse-subscriptions-plans.js.es6 | 4 +- ...course-subscriptions-products-index.js.es6 | 4 +- ...scriptions-products-show-plans-show.js.es6 | 34 ++++++-- ...scourse-subscriptions-products-show.js.es6 | 3 +- ...scourse-subscriptions-subscriptions.js.es6 | 4 +- .../discourse/controllers/s-index.js.es6 | 4 +- .../discourse/controllers/s-show.js.es6 | 9 +- .../discourse/controllers/s.js.es6 | 4 +- .../discourse/helpers/format-curency.js.es6 | 20 ----- .../discourse/helpers/format-currency.js.es6 | 4 +- .../helpers/stripe-payment-link.js.es6 | 4 +- .../helpers/user-viewing-self.js.es6 | 6 +- .../discourse/models/admin-plan.js.es6 | 4 +- .../discourse/models/admin-product.js.es6 | 9 +- .../models/admin-subscription.js.es6 | 17 ++-- .../javascripts/discourse/models/plan.js.es6 | 4 +- .../discourse/models/subscription.js.es6 | 4 +- .../discourse/models/user-payment.js.es6 | 4 +- .../discourse/models/user-subscription.js.es6 | 4 +- ...scriptions-products-show-plans-show.js.es6 | 4 +- ...scourse-subscriptions-products-show.js.es6 | 3 +- .../discourse/routes/s-show.js.es6 | 3 +- ...discourse-subscriptions-products-index.hbs | 80 +++++++++--------- ...subscriptions-products-show-plans-show.hbs | 23 +++++- ...-discourse-subscriptions-subscriptions.hbs | 82 ++++++++++--------- .../templates/components/product-list.hbs | 43 +++++----- .../connectors/user-main-nav/billing.hbs | 2 +- config/locales/client.en.yml | 2 + plugin.rb | 2 +- test/javascripts/helpers/stripe.js.es6 | 4 +- 40 files changed, 261 insertions(+), 179 deletions(-) delete mode 100644 assets/javascripts/discourse/helpers/format-curency.js.es6 diff --git a/app/controllers/admin/products_controller.rb b/app/controllers/admin/products_controller.rb index 2e5f6aa..399931a 100644 --- a/app/controllers/admin/products_controller.rb +++ b/app/controllers/admin/products_controller.rb @@ -12,9 +12,11 @@ module DiscourseSubscriptions product_ids = Product.all.pluck(:external_id) products = [] - if product_ids.present? + if product_ids.present? && is_stripe_configured? products = ::Stripe::Product.list({ ids: product_ids }) products = products[:data] + elsif !is_stripe_configured? + products = nil end render_json_dump products diff --git a/app/controllers/admin/subscriptions_controller.rb b/app/controllers/admin/subscriptions_controller.rb index 78b4153..046a67a 100644 --- a/app/controllers/admin/subscriptions_controller.rb +++ b/app/controllers/admin/subscriptions_controller.rb @@ -12,9 +12,11 @@ module DiscourseSubscriptions subscription_ids = Subscription.all.pluck(:external_id) subscriptions = [] - if subscription_ids.present? + if subscription_ids.present? && is_stripe_configured? subscriptions = ::Stripe::Subscription.list(expand: ['data.plan.product']) subscriptions = subscriptions.select { |sub| subscription_ids.include?(sub[:id]) } + elsif !is_stripe_configured? + subscriptions = nil end render_json_dump subscriptions diff --git a/app/controllers/concerns/stripe.rb b/app/controllers/concerns/stripe.rb index 107309e..04023f7 100644 --- a/app/controllers/concerns/stripe.rb +++ b/app/controllers/concerns/stripe.rb @@ -7,5 +7,9 @@ module DiscourseSubscriptions def set_api_key ::Stripe.api_key = SiteSetting.discourse_subscriptions_secret_key end + + def is_stripe_configured? + SiteSetting.discourse_subscriptions_public_key.present? && SiteSetting.discourse_subscriptions_secret_key.present? + end end end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 2dab40d..930a3cc 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -11,7 +11,7 @@ module DiscourseSubscriptions product_ids = Product.all.pluck(:external_id) products = [] - if product_ids.present? + if product_ids.present? && is_stripe_configured? response = ::Stripe::Product.list({ ids: product_ids, active: true diff --git a/assets/javascripts/discourse/components/payment-options.js.es6 b/assets/javascripts/discourse/components/payment-options.js.es6 index c6c1048..f702f1d 100644 --- a/assets/javascripts/discourse/components/payment-options.js.es6 +++ b/assets/javascripts/discourse/components/payment-options.js.es6 @@ -1,6 +1,7 @@ import { equal } from "@ember/object/computed"; +import Component from "@ember/component"; -export default Ember.Component.extend({ +export default Component.extend({ planButtonSelected: equal("planTypeIsSelected", true), paymentButtonSelected: equal("planTypeIsSelected", false), diff --git a/assets/javascripts/discourse/components/product-list.js.es6 b/assets/javascripts/discourse/components/product-list.js.es6 index 2d01ba9..99d7ab1 100644 --- a/assets/javascripts/discourse/components/product-list.js.es6 +++ b/assets/javascripts/discourse/components/product-list.js.es6 @@ -1,9 +1,16 @@ -import computed from "discourse-common/utils/decorators"; +import discourseComputed from "discourse-common/utils/decorators"; import User from "discourse/models/user"; +import { isEmpty } from "@ember/utils"; +import Component from "@ember/component"; -export default Ember.Component.extend({ - @computed() - currentUser() { +export default Component.extend({ + @discourseComputed("products") + emptyProducts(products) { + return isEmpty(products); + }, + + @discourseComputed() + isLoggedIn() { return User.current(); } }); diff --git a/assets/javascripts/discourse/components/subscribe-card.js.es6 b/assets/javascripts/discourse/components/subscribe-card.js.es6 index d773d59..8e85d63 100644 --- a/assets/javascripts/discourse/components/subscribe-card.js.es6 +++ b/assets/javascripts/discourse/components/subscribe-card.js.es6 @@ -1,4 +1,6 @@ -export default Ember.Component.extend({ +import Component from "@ember/component"; + +export default Component.extend({ didInsertElement() { this._super(...arguments); this.cardElement.mount("#card-element"); diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-dashboard.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-dashboard.js.es6 index eeaf139..4a3781b 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-dashboard.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-dashboard.js.es6 @@ -1,4 +1,6 @@ -export default Ember.Controller.extend({ +import Controller from "@ember/controller"; + +export default Controller.extend({ queryParams: ["order", "descending"], order: null, descending: true, diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-plans-index.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-plans-index.js.es6 index 3f37394..ec7d927 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-plans-index.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-plans-index.js.es6 @@ -1,6 +1,7 @@ +import Controller from "@ember/controller"; import DiscourseURL from "discourse/lib/url"; -export default Ember.Controller.extend({ +export default Controller.extend({ actions: { editPlan(id) { return DiscourseURL.redirectTo( diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-plans-show.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-plans-show.js.es6 index 6fa26ad..e8eebb6 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-plans-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-plans-show.js.es6 @@ -1,6 +1,7 @@ +import Controller from "@ember/controller"; import { popupAjaxError } from "discourse/lib/ajax-error"; -export default Ember.Controller.extend({ +export default Controller.extend({ actions: { createPlan() { if (this.get("model.plan.product_id") === undefined) { diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-plans.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-plans.js.es6 index 2d3f960..fa4ba1e 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-plans.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-plans.js.es6 @@ -1 +1,3 @@ -export default Ember.Controller.extend({}); +import Controller from "@ember/controller"; + +export default Controller.extend({}); diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-index.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-index.js.es6 index 2d3f960..fa4ba1e 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-index.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-index.js.es6 @@ -1 +1,3 @@ -export default Ember.Controller.extend({}); +import Controller from "@ember/controller"; + +export default Controller.extend({}); diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-show-plans-show.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-show-plans-show.js.es6 index 8977220..bee454d 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-show-plans-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-show-plans-show.js.es6 @@ -1,16 +1,40 @@ -import computed from "ember-addons/ember-computed-decorators"; +import discourseComputed from "discourse-common/utils/decorators"; import DiscourseURL from "discourse/lib/url"; +import Controller from "@ember/controller"; -export default Ember.Controller.extend({ +export default Controller.extend({ // Also defined in settings. - currencies: ["AUD", "CAD", "EUR", "GBP", "USD", "INR"], + selectedCurrency: Ember.computed.alias("model.plan.currency"), + selectedInterval: Ember.computed.alias("model.plan.interval"), - @computed("model.plan.isNew") + @discourseComputed + currencies() { + return [ + { id: "AUD", name: "AUD" }, + { id: "CAD", name: "CAD" }, + { id: "EUR", name: "EUR" }, + { id: "GBP", name: "GBP" }, + { id: "USD", name: "USD" }, + { id: "INR", name: "INR" } + ]; + }, + + @discourseComputed + availableIntervals() { + return [ + { id: "day", name: "day" }, + { id: "week", name: "week" }, + { id: "month", name: "month" }, + { id: "year", name: "year" } + ]; + }, + + @discourseComputed("model.plan.isNew") planFieldDisabled(isNew) { return !isNew; }, - @computed("model.product.id") + @discourseComputed("model.product.id") productId(id) { return id; }, diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-show.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-show.js.es6 index f708c86..4dd3397 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-show.js.es6 @@ -1,6 +1,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error"; +import Controller from "@ember/controller"; -export default Ember.Controller.extend({ +export default Controller.extend({ actions: { cancelProduct() { this.transitionToRoute("adminPlugins.discourse-subscriptions.products"); diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-subscriptions.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-subscriptions.js.es6 index 2d3f960..fa4ba1e 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-subscriptions.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-subscriptions.js.es6 @@ -1 +1,3 @@ -export default Ember.Controller.extend({}); +import Controller from "@ember/controller"; + +export default Controller.extend({}); diff --git a/assets/javascripts/discourse/controllers/s-index.js.es6 b/assets/javascripts/discourse/controllers/s-index.js.es6 index 2d3f960..fa4ba1e 100644 --- a/assets/javascripts/discourse/controllers/s-index.js.es6 +++ b/assets/javascripts/discourse/controllers/s-index.js.es6 @@ -1 +1,3 @@ -export default Ember.Controller.extend({}); +import Controller from "@ember/controller"; + +export default Controller.extend({}); diff --git a/assets/javascripts/discourse/controllers/s-show.js.es6 b/assets/javascripts/discourse/controllers/s-show.js.es6 index 6328ef3..6b01d85 100644 --- a/assets/javascripts/discourse/controllers/s-show.js.es6 +++ b/assets/javascripts/discourse/controllers/s-show.js.es6 @@ -1,18 +1,19 @@ +import Controller from "@ember/controller"; import Customer from "discourse/plugins/discourse-subscriptions/discourse/models/customer"; import Payment from "discourse/plugins/discourse-subscriptions/discourse/models/payment"; import Subscription from "discourse/plugins/discourse-subscriptions/discourse/models/subscription"; -import computed from "discourse-common/utils/decorators"; +import discourseComputed from "discourse-common/utils/decorators"; import I18n from "I18n"; -export default Ember.Controller.extend({ +export default Controller.extend({ planTypeIsSelected: true, - @computed("planTypeIsSelected") + @discourseComputed("planTypeIsSelected") type(planTypeIsSelected) { return planTypeIsSelected ? "plans" : "payment"; }, - @computed("type") + @discourseComputed("type") buttonText(type) { return I18n.t(`discourse_subscriptions.${type}.payment_button`); }, diff --git a/assets/javascripts/discourse/controllers/s.js.es6 b/assets/javascripts/discourse/controllers/s.js.es6 index 2d3f960..fa4ba1e 100644 --- a/assets/javascripts/discourse/controllers/s.js.es6 +++ b/assets/javascripts/discourse/controllers/s.js.es6 @@ -1 +1,3 @@ -export default Ember.Controller.extend({}); +import Controller from "@ember/controller"; + +export default Controller.extend({}); diff --git a/assets/javascripts/discourse/helpers/format-curency.js.es6 b/assets/javascripts/discourse/helpers/format-curency.js.es6 deleted file mode 100644 index 011dd46..0000000 --- a/assets/javascripts/discourse/helpers/format-curency.js.es6 +++ /dev/null @@ -1,20 +0,0 @@ -// TODO: typo in this helper name: currency not curency. -export default Ember.Helper.helper(function(params) { - let currencySign; - - switch (Discourse.SiteSettings.discourse_subscriptions_currency) { - case "EUR": - currencySign = "€"; - break; - case "GBP": - currencySign = "£"; - break; - case "INR": - currencySign = "₹"; - break; - default: - currencySign = "$"; - } - - return [currencySign, params[0]].join(""); -}); diff --git a/assets/javascripts/discourse/helpers/format-currency.js.es6 b/assets/javascripts/discourse/helpers/format-currency.js.es6 index 67834ff..7bf3de6 100644 --- a/assets/javascripts/discourse/helpers/format-currency.js.es6 +++ b/assets/javascripts/discourse/helpers/format-currency.js.es6 @@ -1,4 +1,6 @@ -export default Ember.Helper.helper(function(params) { +import Helper from "@ember/component/helper"; + +export default Helper.helper(function(params) { let currencySign; switch (params[0]) { diff --git a/assets/javascripts/discourse/helpers/stripe-payment-link.js.es6 b/assets/javascripts/discourse/helpers/stripe-payment-link.js.es6 index e038903..f44c2ab 100644 --- a/assets/javascripts/discourse/helpers/stripe-payment-link.js.es6 +++ b/assets/javascripts/discourse/helpers/stripe-payment-link.js.es6 @@ -1,4 +1,6 @@ -export default Ember.Helper.helper(function(params) { +import Helper from "@ember/component/helper"; + +export default Helper.helper(function(params) { const payment = params[0]; return `${payment.payment_intent_id}`; diff --git a/assets/javascripts/discourse/helpers/user-viewing-self.js.es6 b/assets/javascripts/discourse/helpers/user-viewing-self.js.es6 index 047ed8a..9058394 100644 --- a/assets/javascripts/discourse/helpers/user-viewing-self.js.es6 +++ b/assets/javascripts/discourse/helpers/user-viewing-self.js.es6 @@ -1,10 +1,10 @@ import { registerUnbound } from "discourse-common/lib/helpers"; +import User from "discourse/models/user"; export default registerUnbound("user-viewing-self", function(model) { - if (Discourse.User.current()) { + if (User.current()) { return ( - Discourse.User.current().username.toLowerCase() === - model.username.toLowerCase() + User.current().username.toLowerCase() === model.username.toLowerCase() ); } diff --git a/assets/javascripts/discourse/models/admin-plan.js.es6 b/assets/javascripts/discourse/models/admin-plan.js.es6 index 72fd1e2..5cfc94b 100644 --- a/assets/javascripts/discourse/models/admin-plan.js.es6 +++ b/assets/javascripts/discourse/models/admin-plan.js.es6 @@ -1,5 +1,5 @@ import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan"; -import computed from "ember-addons/ember-computed-decorators"; +import discourseComputed from "discourse-common/utils/decorators"; import { ajax } from "discourse/lib/ajax"; const AdminPlan = Plan.extend({ @@ -10,7 +10,7 @@ const AdminPlan = Plan.extend({ intervals: ["day", "week", "month", "year"], metadata: {}, - @computed("trial_period_days") + @discourseComputed("trial_period_days") parseTrialPeriodDays(trial_period_days) { if (trial_period_days) { return parseInt(0 + trial_period_days, 10); diff --git a/assets/javascripts/discourse/models/admin-product.js.es6 b/assets/javascripts/discourse/models/admin-product.js.es6 index 2ffe3c1..8912827 100644 --- a/assets/javascripts/discourse/models/admin-product.js.es6 +++ b/assets/javascripts/discourse/models/admin-product.js.es6 @@ -40,9 +40,12 @@ const AdminProduct = EmberObject.extend({ AdminProduct.reopenClass({ findAll() { - return ajax("/s/admin/products", { method: "get" }).then(result => - result.map(product => AdminProduct.create(product)) - ); + return ajax("/s/admin/products", { method: "get" }).then(result => { + if (result === null) { + return { unconfigured: true }; + } + result.map(product => AdminProduct.create(product)); + }); }, find(id) { diff --git a/assets/javascripts/discourse/models/admin-subscription.js.es6 b/assets/javascripts/discourse/models/admin-subscription.js.es6 index 114b884..09fba36 100644 --- a/assets/javascripts/discourse/models/admin-subscription.js.es6 +++ b/assets/javascripts/discourse/models/admin-subscription.js.es6 @@ -1,19 +1,19 @@ -import computed from "ember-addons/ember-computed-decorators"; +import discourseComputed from "discourse-common/utils/decorators"; import { ajax } from "discourse/lib/ajax"; import EmberObject from "@ember/object"; const AdminSubscription = EmberObject.extend({ - @computed("status") + @discourseComputed("status") canceled(status) { return status === "canceled"; }, - @computed("metadata") + @discourseComputed("metadata") metadataUserExists(metadata) { return metadata.user_id && metadata.username; }, - @computed("metadata") + @discourseComputed("metadata") subscriptionUserPath(metadata) { return Discourse.getURL( `/admin/users/${metadata.user_id}/${metadata.username}` @@ -31,9 +31,12 @@ AdminSubscription.reopenClass({ find() { return ajax("/s/admin/subscriptions", { method: "get" - }).then(result => - result.map(subscription => AdminSubscription.create(subscription)) - ); + }).then(result => { + if (result === null) { + return { unconfigured: true }; + } + result.map(subscription => AdminSubscription.create(subscription)); + }); } }); diff --git a/assets/javascripts/discourse/models/plan.js.es6 b/assets/javascripts/discourse/models/plan.js.es6 index a724c2f..b2658be 100644 --- a/assets/javascripts/discourse/models/plan.js.es6 +++ b/assets/javascripts/discourse/models/plan.js.es6 @@ -1,5 +1,5 @@ import EmberObject from "@ember/object"; -import computed from "discourse-common/utils/decorators"; +import discourseComputed from "discourse-common/utils/decorators"; import { ajax } from "discourse/lib/ajax"; const Plan = EmberObject.extend({ @@ -14,7 +14,7 @@ const Plan = EmberObject.extend({ } }), - @computed("amountDollars", "currency", "interval") + @discourseComputed("amountDollars", "currency", "interval") subscriptionRate(amountDollars, currency, interval) { return `${amountDollars} ${currency.toUpperCase()} / ${interval}`; } diff --git a/assets/javascripts/discourse/models/subscription.js.es6 b/assets/javascripts/discourse/models/subscription.js.es6 index c279be1..c3a0bd8 100644 --- a/assets/javascripts/discourse/models/subscription.js.es6 +++ b/assets/javascripts/discourse/models/subscription.js.es6 @@ -1,9 +1,9 @@ -import computed from "ember-addons/ember-computed-decorators"; +import discourseComputed from "discourse-common/utils/decorators"; import { ajax } from "discourse/lib/ajax"; import EmberObject from "@ember/object"; const Subscription = EmberObject.extend({ - @computed("status") + @discourseComputed("status") canceled(status) { return status === "canceled"; }, diff --git a/assets/javascripts/discourse/models/user-payment.js.es6 b/assets/javascripts/discourse/models/user-payment.js.es6 index 049c9d8..2a1f00a 100644 --- a/assets/javascripts/discourse/models/user-payment.js.es6 +++ b/assets/javascripts/discourse/models/user-payment.js.es6 @@ -1,9 +1,9 @@ import EmberObject from "@ember/object"; -import computed from "discourse-common/utils/decorators"; +import discourseComputed from "discourse-common/utils/decorators"; import { ajax } from "discourse/lib/ajax"; const UserPayment = EmberObject.extend({ - @computed("amount") + @discourseComputed("amount") amountDollars(amount) { return parseFloat(amount / 100).toFixed(2); } diff --git a/assets/javascripts/discourse/models/user-subscription.js.es6 b/assets/javascripts/discourse/models/user-subscription.js.es6 index 857a244..ae66904 100644 --- a/assets/javascripts/discourse/models/user-subscription.js.es6 +++ b/assets/javascripts/discourse/models/user-subscription.js.es6 @@ -1,10 +1,10 @@ import EmberObject from "@ember/object"; -import computed from "ember-addons/ember-computed-decorators"; +import discourseComputed from "discourse-common/utils/decorators"; import { ajax } from "discourse/lib/ajax"; import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan"; const UserSubscription = EmberObject.extend({ - @computed("status") + @discourseComputed("status") canceled(status) { return status === "canceled"; }, diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show-plans-show.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show-plans-show.js.es6 index 5186fce..a89cafc 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show-plans-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show-plans-show.js.es6 @@ -1,6 +1,7 @@ import Route from "@ember/routing/route"; import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/models/admin-plan"; import Group from "discourse/models/group"; +import { hash } from "rsvp"; export default Route.extend({ model(params) { @@ -14,6 +15,7 @@ export default Route.extend({ plan = AdminPlan.create({ active: true, isNew: true, + interval: "month", currency: Discourse.SiteSettings.discourse_subscriptions_currency, product: product.get("id") }); @@ -23,7 +25,7 @@ export default Route.extend({ const groups = Group.findAll({ ignore_automatic: true }); - return Ember.RSVP.hash({ plan, product, groups }); + return hash({ plan, product, groups }); }, renderTemplate() { diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show.js.es6 index 8da744b..c1ab765 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show.js.es6 @@ -2,6 +2,7 @@ import Route from "@ember/routing/route"; import AdminProduct from "discourse/plugins/discourse-subscriptions/discourse/models/admin-product"; import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/models/admin-plan"; import I18n from "I18n"; +import { hash } from "rsvp"; export default Route.extend({ model(params) { @@ -16,7 +17,7 @@ export default Route.extend({ plans = AdminPlan.findAll({ product_id }); } - return Ember.RSVP.hash({ plans, product }); + return hash({ plans, product }); }, actions: { diff --git a/assets/javascripts/discourse/routes/s-show.js.es6 b/assets/javascripts/discourse/routes/s-show.js.es6 index 55f9cd6..a02d9f7 100644 --- a/assets/javascripts/discourse/routes/s-show.js.es6 +++ b/assets/javascripts/discourse/routes/s-show.js.es6 @@ -1,6 +1,7 @@ import Route from "@ember/routing/route"; import Product from "discourse/plugins/discourse-subscriptions/discourse/models/product"; import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan"; +import { hash } from "rsvp"; export default Route.extend({ model(params) { @@ -9,6 +10,6 @@ export default Route.extend({ const product = Product.find(product_id); const plans = Plan.findAll({ product_id }); - return Ember.RSVP.hash({ plans, product }); + return hash({ plans, product }); } }); diff --git a/assets/javascripts/discourse/templates/admin/plugins-discourse-subscriptions-products-index.hbs b/assets/javascripts/discourse/templates/admin/plugins-discourse-subscriptions-products-index.hbs index b703734..44d6565 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-discourse-subscriptions-products-index.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-discourse-subscriptions-products-index.hbs @@ -1,41 +1,45 @@ - -

- {{#link-to 'adminPlugins.discourse-subscriptions.products.show' 'new' class="btn btn-primary"}} - {{d-icon "plus"}} - {{i18n 'discourse_subscriptions.admin.products.operations.new'}} - {{/link-to}} -

- -{{#if model}} - - - - - - - - - {{#each model as |product|}} - - - - - - - - {{/each}} -
{{i18n 'discourse_subscriptions.admin.products.product.name'}}{{i18n 'discourse_subscriptions.admin.products.product.created_at'}}{{i18n 'discourse_subscriptions.admin.products.product.updated_at'}}{{i18n 'discourse_subscriptions.admin.products.product.active'}}
{{product.name}}{{format-unix-date product.created}}{{format-unix-date product.updated}}{{product.active}} - {{#link-to "adminPlugins.discourse-subscriptions.products.show" product.id class="btn no-text btn-icon"}} - {{d-icon "far-edit"}} - {{/link-to}} - {{d-button - action=(route-action "destroyProduct") - actionParam=product - icon="trash-alt" - class="btn-danger btn no-text btn-icon"}} -
+{{#if model.unconfigured }} +

{{i18n 'discourse_subscriptions.admin.unconfigured'}}

+

Discourse Subscriptions on Meta

{{else}} -

- {{i18n 'discourse_subscriptions.admin.products.product_help'}} +

+ {{#link-to 'adminPlugins.discourse-subscriptions.products.show' 'new' class="btn btn-primary"}} + {{d-icon "plus"}} + {{i18n 'discourse_subscriptions.admin.products.operations.new'}} + {{/link-to}}

+ + {{#if model}} + + + + + + + + + {{#each model as |product|}} + + + + + + + + {{/each}} +
{{i18n 'discourse_subscriptions.admin.products.product.name'}}{{i18n 'discourse_subscriptions.admin.products.product.created_at'}}{{i18n 'discourse_subscriptions.admin.products.product.updated_at'}}{{i18n 'discourse_subscriptions.admin.products.product.active'}}
{{product.name}}{{format-unix-date product.created}}{{format-unix-date product.updated}}{{product.active}} + {{#link-to "adminPlugins.discourse-subscriptions.products.show" product.id class="btn no-text btn-icon"}} + {{d-icon "far-edit"}} + {{/link-to}} + {{d-button + action=(route-action "destroyProduct") + actionParam=product + icon="trash-alt" + class="btn-danger btn no-text btn-icon"}} +
+ {{else}} +

+ {{i18n 'discourse_subscriptions.admin.products.product_help'}} +

+ {{/if}} {{/if}} diff --git a/assets/javascripts/discourse/templates/admin/plugins-discourse-subscriptions-products-show-plans-show.hbs b/assets/javascripts/discourse/templates/admin/plugins-discourse-subscriptions-products-show-plans-show.hbs index ed59c62..2e97a25 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-discourse-subscriptions-products-show-plans-show.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-discourse-subscriptions-products-show-plans-show.hbs @@ -15,7 +15,12 @@

- {{combo-box valueAttribute="name" content=model.groups value=model.plan.metadata.group_name}} + {{combo-box + valueProperty="name" + content=model.groups + value=model.plan.metadata.group_name + onChange=(action (mut model.plan.metadata.group_name)) + }}

{{i18n 'discourse_subscriptions.admin.plans.plan.group_help'}}
@@ -25,7 +30,12 @@ {{#if planFieldDisabled}} {{input class="plan-amount plan-currency" disabled=true value=model.plan.currency}} {{else}} - {{combo-box disabled=planFieldDisabled content=currencies value=model.plan.currency}} + {{combo-box + disabled=planFieldDisabled + content=currencies + value=model.plan.currency + onChange=(action (mut model.plan.currency)) + }} {{/if}} {{input class="plan-amount" type="text" name="name" value=model.plan.amountDollars disabled=planFieldDisabled}}

@@ -44,9 +54,14 @@ {{i18n 'discourse_subscriptions.admin.plans.plan.interval'}} {{#if planFieldDisabled}} - {{input disabled=true value=model.plan.interval}} + {{input disabled=true value=selectedInterval}} {{else}} - {{combo-box valueAttribute="value" content=model.plan.intervals value=model.plan.interval}} + {{combo-box + valueProperty="name" + content=availableIntervals + value=selectedInterval + onChange=(action (mut selectedInterval)) + }} {{/if}}

diff --git a/assets/javascripts/discourse/templates/admin/plugins-discourse-subscriptions-subscriptions.hbs b/assets/javascripts/discourse/templates/admin/plugins-discourse-subscriptions-subscriptions.hbs index b349abe..ee6d91a 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-discourse-subscriptions-subscriptions.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-discourse-subscriptions-subscriptions.hbs @@ -1,39 +1,43 @@ - - - - - - - - - - - - - - - {{#each model as |subscription|}} - - - - - - - - - - - {{/each}} -
{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.user'}}{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.subscription_id'}}{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.customer'}}{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.product'}}{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.plan'}}{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.status'}}{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.created_at'}}
- {{#if subscription.metadataUserExists}} - - {{subscription.metadata.username}} - - {{/if}} - {{subscription.id}}{{subscription.customer}}{{subscription.plan.product.name}}{{subscription.plan.nickname}}{{subscription.status}}{{format-unix-date subscription.created}} - {{#if subscription.loading}} - {{loading-spinner size="small"}} - {{else}} - {{d-button disabled=subscription.canceled label="cancel" action=(route-action "cancelSubscription" subscription) icon="times"}} - {{/if}} -
+{{#if model.unconfigured}} +

{{i18n 'discourse_subscriptions.admin.unconfigured'}}

+

Discourse Subscriptions on Meta

+{{else}} + + + + + + + + + + + + + + {{#each model as |subscription|}} + + + + + + + + + + + {{/each}} +
{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.user'}}{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.subscription_id'}}{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.customer'}}{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.product'}}{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.plan'}}{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.status'}}{{i18n 'discourse_subscriptions.admin.subscriptions.subscription.created_at'}}
+ {{#if subscription.metadataUserExists}} + + {{subscription.metadata.username}} + + {{/if}} + {{subscription.id}}{{subscription.customer}}{{subscription.plan.product.name}}{{subscription.plan.nickname}}{{subscription.status}}{{format-unix-date subscription.created}} + {{#if subscription.loading}} + {{loading-spinner size="small"}} + {{else}} + {{d-button disabled=subscription.canceled label="cancel" action=(route-action "cancelSubscription" subscription) icon="times"}} + {{/if}} +
+{{/if}} diff --git a/assets/javascripts/discourse/templates/components/product-list.hbs b/assets/javascripts/discourse/templates/components/product-list.hbs index 87b09ed..d29c018 100644 --- a/assets/javascripts/discourse/templates/components/product-list.hbs +++ b/assets/javascripts/discourse/templates/components/product-list.hbs @@ -1,24 +1,27 @@ +{{#if emptyProducts}} +

{{i18n 'discourse_subscriptions.subscribe.no_products'}}

+{{else}} + {{#each products as |product|}} +
+

{{product.name}}

-{{#each products as |product|}} -
-

{{product.name}}

+

+ {{product.description}} +

+ {{#if isLoggedIn}} +
+ {{#link-to "s.show" product.id disabled=product.subscribed class="btn btn-primary"}} + {{i18n 'discourse_subscriptions.subscribe.title'}} + {{/link-to}} +
+ {{/if}} +
+ {{/each}} + + {{#unless isLoggedIn}}

- {{product.description}} + {{i18n 'discourse_subscriptions.subscribe.unauthenticated'}}

- - {{#if currentUser}} -
- {{#link-to "s.show" product.id disabled=product.subscribed class="btn btn-primary"}} - {{i18n 'discourse_subscriptions.subscribe.title'}} - {{/link-to}} -
- {{/if}} -
-{{/each}} - -{{#unless currentUser}} -

- {{i18n 'discourse_subscriptions.subscribe.unauthenticated'}} -

-{{/unless}} + {{/unless}} +{{/if}} diff --git a/assets/javascripts/discourse/templates/connectors/user-main-nav/billing.hbs b/assets/javascripts/discourse/templates/connectors/user-main-nav/billing.hbs index 977d685..2665898 100644 --- a/assets/javascripts/discourse/templates/connectors/user-main-nav/billing.hbs +++ b/assets/javascripts/discourse/templates/connectors/user-main-nav/billing.hbs @@ -1,3 +1,3 @@ {{#if (user-viewing-self model)}} - {{#link-to 'user.billing'}}{{d-icon "credit-card"}}{{I18n 'discourse_subscriptions.navigation.billing'}}{{/link-to}} + {{#link-to 'user.billing'}}{{d-icon "far-credit-card"}}{{I18n 'discourse_subscriptions.navigation.billing'}}{{/link-to}} {{/if}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 020b917..ad1ebd7 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -67,6 +67,7 @@ en: confirm: Are you sure you want to cancel this subscription? subscribe: title: Subscribe + no_products: There are currently no products available. unauthenticated: You need to create an account to subscribe. card: title: Payment @@ -86,6 +87,7 @@ en: confirm_payment: Confirm payment success: Go back admin: + unconfigured: 'Stripe is not configured correctly. Please see Discourse Meta for information.' dashboard: title: Dashboard table: diff --git a/plugin.rb b/plugin.rb index 9761d42..4d5963d 100644 --- a/plugin.rb +++ b/plugin.rb @@ -14,7 +14,7 @@ register_asset "stylesheets/common/main.scss" register_asset "stylesheets/common/layout.scss" register_asset "stylesheets/common/subscribe.scss" register_asset "stylesheets/mobile/main.scss" -register_svg_icon "credit-card" if respond_to?(:register_svg_icon) +register_svg_icon "far-credit-card" if respond_to?(:register_svg_icon) register_html_builder('server:before-head-close') do "" diff --git a/test/javascripts/helpers/stripe.js.es6 b/test/javascripts/helpers/stripe.js.es6 index bb85450..5390d94 100644 --- a/test/javascripts/helpers/stripe.js.es6 +++ b/test/javascripts/helpers/stripe.js.es6 @@ -1,8 +1,10 @@ +import { Promise } from "rsvp"; + export function stubStripe() { window.Stripe = () => { return { createPaymentMethod() { - return new Ember.RSVP.Promise(resolve => { + return new Promise(resolve => { resolve({}); }); },