diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-plans-show.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-plans-show.js.es6 index 0f4b396..39f9ee0 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-plans-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-plans-show.js.es6 @@ -3,7 +3,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error"; export default Ember.Controller.extend({ actions: { createPlan() { - if(this.get("model.plan.product_id") === undefined) { + if (this.get("model.plan.product_id") === undefined) { const productID = this.get("model.products.firstObject.id"); this.set("model.plan.product_id", productID); } diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-products-show-plans-show.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-products-show-plans-show.js.es6 index 80ff5aa..fdfc7d8 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-products-show-plans-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-products-show-plans-show.js.es6 @@ -13,7 +13,9 @@ export default Ember.Controller.extend({ }, redirect(product_id) { - DiscourseURL.redirectTo(`/admin/plugins/discourse-patrons/products/${product_id}`); + DiscourseURL.redirectTo( + `/admin/plugins/discourse-patrons/products/${product_id}` + ); }, actions: { @@ -24,17 +26,20 @@ export default Ember.Controller.extend({ createPlan() { // TODO: set default group name beforehand if (this.get("model.plan.metadata.group_name") === undefined) { - this.set( - "model.plan.metadata", - { group_name: this.get("model.groups.firstObject.name") } - ); + this.set("model.plan.metadata", { + group_name: this.get("model.groups.firstObject.name") + }); } - this.get('model.plan').save().then(() => this.redirect(this.productId)); + this.get("model.plan") + .save() + .then(() => this.redirect(this.productId)); }, updatePlan() { - this.get('model.plan').update().then(() => this.redirect(this.productId)); + this.get("model.plan") + .update() + .then(() => this.redirect(this.productId)); } } }); diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-products-show.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-products-show.js.es6 index 8a61647..d3050bb 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-products-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-products-show.js.es6 @@ -10,7 +10,10 @@ export default Ember.Controller.extend({ this.get("model.product") .save() .then(product => { - this.transitionToRoute("adminPlugins.discourse-patrons.products.show", product.id); + this.transitionToRoute( + "adminPlugins.discourse-patrons.products.show", + product.id + ); }) .catch(popupAjaxError); }, diff --git a/assets/javascripts/discourse/controllers/patrons-index.js.es6 b/assets/javascripts/discourse/controllers/patrons-index.js.es6 index 516acba..0439eb7 100644 --- a/assets/javascripts/discourse/controllers/patrons-index.js.es6 +++ b/assets/javascripts/discourse/controllers/patrons-index.js.es6 @@ -13,7 +13,10 @@ export default Ember.Controller.extend({ paymentSuccessHandler(paymentIntentId) { bootbox.alert("ok payment good... some kind of message"); - this.transitionToRoute("user.billing", Discourse.User.current().username.toLowerCase()); + this.transitionToRoute( + "user.billing", + Discourse.User.current().username.toLowerCase() + ); } } }); diff --git a/assets/javascripts/discourse/controllers/patrons-subscribe.js.es6 b/assets/javascripts/discourse/controllers/patrons-subscribe.js.es6 index cbb98be..74ec8e2 100644 --- a/assets/javascripts/discourse/controllers/patrons-subscribe.js.es6 +++ b/assets/javascripts/discourse/controllers/patrons-subscribe.js.es6 @@ -27,7 +27,7 @@ export default Ember.Controller.extend({ }).then(customer => { const subscription = this.get("model.subscription"); - subscription.set('customer', customer.id); + subscription.set("customer", customer.id); if (subscription.get("plan") === undefined) { subscription.set("plan", this.get("model.plans.firstObject.id")); @@ -35,7 +35,10 @@ export default Ember.Controller.extend({ subscription.save().then(() => { bootbox.alert("ok payment good... some kind of message"); - this.transitionToRoute("user.billing", Discourse.User.current().username.toLowerCase()); + this.transitionToRoute( + "user.billing", + Discourse.User.current().username.toLowerCase() + ); }); }); } diff --git a/assets/javascripts/discourse/discourse-patrons-user-route-map.js.es6 b/assets/javascripts/discourse/discourse-patrons-user-route-map.js.es6 index 6d5402e..3024a30 100644 --- a/assets/javascripts/discourse/discourse-patrons-user-route-map.js.es6 +++ b/assets/javascripts/discourse/discourse-patrons-user-route-map.js.es6 @@ -1,7 +1,7 @@ export default { - resource: 'user', - path: 'users/:username', + resource: "user", + path: "users/:username", map() { - this.route('billing'); + this.route("billing"); } -}; \ No newline at end of file +}; diff --git a/assets/javascripts/discourse/helpers/user-viewing-self.js.es6 b/assets/javascripts/discourse/helpers/user-viewing-self.js.es6 index 1242ca8..047ed8a 100644 --- a/assets/javascripts/discourse/helpers/user-viewing-self.js.es6 +++ b/assets/javascripts/discourse/helpers/user-viewing-self.js.es6 @@ -1,8 +1,11 @@ -import { registerUnbound } from 'discourse-common/lib/helpers'; +import { registerUnbound } from "discourse-common/lib/helpers"; -export default registerUnbound('user-viewing-self', function(model) { - if (Discourse.User.current()){ - return Discourse.User.current().username.toLowerCase() === model.username.toLowerCase(); +export default registerUnbound("user-viewing-self", function(model) { + if (Discourse.User.current()) { + return ( + Discourse.User.current().username.toLowerCase() === + model.username.toLowerCase() + ); } return false; diff --git a/assets/javascripts/discourse/models/admin-plan.js.es6 b/assets/javascripts/discourse/models/admin-plan.js.es6 index 6895bd0..2be4f99 100644 --- a/assets/javascripts/discourse/models/admin-plan.js.es6 +++ b/assets/javascripts/discourse/models/admin-plan.js.es6 @@ -16,10 +16,9 @@ const AdminPlan = Discourse.Model.extend({ @computed("trial_period_days") parseTrialPeriodDays(trial_period_days) { - if(trial_period_days) { + if (trial_period_days) { return parseInt(0 + trial_period_days); - } - else { + } else { return 0; } }, diff --git a/assets/javascripts/discourse/models/admin-product.js.es6 b/assets/javascripts/discourse/models/admin-product.js.es6 index 28202c6..b40846f 100644 --- a/assets/javascripts/discourse/models/admin-product.js.es6 +++ b/assets/javascripts/discourse/models/admin-product.js.es6 @@ -22,8 +22,8 @@ const AdminProduct = Discourse.Model.extend({ active: this.active }; - return ajax("/patrons/admin/products", { method: "post", data }).then(product => - AdminProduct.create(product) + return ajax("/patrons/admin/products", { method: "post", data }).then( + product => AdminProduct.create(product) ); }, @@ -35,7 +35,10 @@ const AdminProduct = Discourse.Model.extend({ active: this.active }; - return ajax(`/patrons/admin/products/${this.id}`, { method: "patch", data }); + return ajax(`/patrons/admin/products/${this.id}`, { + method: "patch", + data + }); } }); @@ -47,10 +50,10 @@ AdminProduct.reopenClass({ }, find(id) { - return ajax(`/patrons/admin/products/${id}`, { method: "get" }).then(product => - AdminProduct.create(product) + return ajax(`/patrons/admin/products/${id}`, { method: "get" }).then( + product => AdminProduct.create(product) ); - }, + } }); export default AdminProduct; diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-index.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-index.js.es6 index b814351..5c80528 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-index.js.es6 +++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-index.js.es6 @@ -13,12 +13,16 @@ export default Discourse.Route.extend({ I18n.t("yes_value"), confirmed => { if (confirmed) { - product.destroy().then(() => { - this.controllerFor("adminPluginsDiscoursePatronsProductsIndex") - .get("model") - .removeObject(product); - }) - .catch(data => bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))); + product + .destroy() + .then(() => { + this.controllerFor("adminPluginsDiscoursePatronsProductsIndex") + .get("model") + .removeObject(product); + }) + .catch(data => + bootbox.alert(data.jqXHR.responseJSON.errors.join("\n")) + ); } } ); diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show-plans-show.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show-plans-show.js.es6 index 3698b51..a4e17c9 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show-plans-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show-plans-show.js.es6 @@ -3,14 +3,19 @@ import Group from "discourse/models/group"; export default Discourse.Route.extend({ model(params) { - const id = params['plan-id']; - const product = this.modelFor('adminPlugins.discourse-patrons.products.show').product; + const id = params["plan-id"]; + const product = this.modelFor( + "adminPlugins.discourse-patrons.products.show" + ).product; let plan; - if(id === 'new') { - plan = AdminPlan.create({ active: true, isNew: true, product: product.get('id') }); - } - else { + if (id === "new") { + plan = AdminPlan.create({ + active: true, + isNew: true, + product: product.get("id") + }); + } else { plan = AdminPlan.find(id); } @@ -20,10 +25,10 @@ export default Discourse.Route.extend({ }, renderTemplate() { - this.render('adminPlugins.discourse-patrons.products.show.plans.show', { - into: 'adminPlugins.discourse-patrons.products', - outlet: 'main', - controller: 'adminPlugins.discourse-patrons.products.show.plans.show', + this.render("adminPlugins.discourse-patrons.products.show.plans.show", { + into: "adminPlugins.discourse-patrons.products", + outlet: "main", + controller: "adminPlugins.discourse-patrons.products.show.plans.show" }); - }, + } }); diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show.js.es6 index 6781cba..0fab55d 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show.js.es6 @@ -3,14 +3,13 @@ import AdminPlan from "discourse/plugins/discourse-patrons/discourse/models/admi export default Discourse.Route.extend({ model(params) { - const product_id = params['product-id']; + const product_id = params["product-id"]; let product; let plans = []; - if(product_id === 'new') { + if (product_id === "new") { product = AdminProduct.create({ active: true, isNew: true }); - } - else { + } else { product = AdminProduct.find(product_id); plans = AdminPlan.findAll({ product_id }); } @@ -26,12 +25,16 @@ export default Discourse.Route.extend({ I18n.t("yes_value"), confirmed => { if (confirmed) { - plan.destroy().then(() => { - this.controllerFor("adminPluginsDiscoursePatronsProductsShow") - .get("model.plans") - .removeObject(plan); - }) - .catch(data => bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))); + plan + .destroy() + .then(() => { + this.controllerFor("adminPluginsDiscoursePatronsProductsShow") + .get("model.plans") + .removeObject(plan); + }) + .catch(data => + bootbox.alert(data.jqXHR.responseJSON.errors.join("\n")) + ); } } ); diff --git a/assets/javascripts/discourse/routes/patrons-subscribe.js.es6 b/assets/javascripts/discourse/routes/patrons-subscribe.js.es6 index e304a2b..08d06eb 100644 --- a/assets/javascripts/discourse/routes/patrons-subscribe.js.es6 +++ b/assets/javascripts/discourse/routes/patrons-subscribe.js.es6 @@ -4,13 +4,17 @@ import Subscription from "discourse/plugins/discourse-patrons/discourse/models/s export default Discourse.Route.extend({ model() { - const toCurrency = (cents) => parseFloat(cents/100).toFixed(2); + const toCurrency = cents => parseFloat(cents / 100).toFixed(2); - const planSelectText = (plan) => { - return `$${toCurrency(plan.amount)} ${plan.currency.toUpperCase()} / ${plan.interval}`; + const planSelectText = plan => { + return `$${toCurrency(plan.amount)} ${plan.currency.toUpperCase()} / ${ + plan.interval + }`; }; - const plans = Plan.findAll().then(results => results.map(p => planSelectText(p))); + const plans = Plan.findAll().then(results => + results.map(p => planSelectText(p)) + ); const subscription = Subscription.create(); return Ember.RSVP.hash({ plans, subscription }); diff --git a/assets/javascripts/discourse/routes/user-billing.js.es6 b/assets/javascripts/discourse/routes/user-billing.js.es6 index f78ad8e..9ce293f 100644 --- a/assets/javascripts/discourse/routes/user-billing.js.es6 +++ b/assets/javascripts/discourse/routes/user-billing.js.es6 @@ -1,4 +1,3 @@ - export default Discourse.Route.extend({ model() { return {}; @@ -7,9 +6,8 @@ export default Discourse.Route.extend({ setupController(controller, model) { if (this.currentUser.id !== this.modelFor("user").id) { this.replaceWith("userActivity"); - } - else { + } else { controller.setProperties({ model }); - }; + } } }); diff --git a/assets/stylesheets/common/discourse-patrons.scss b/assets/stylesheets/common/discourse-patrons.scss index e8f72c7..219ff4d 100644 --- a/assets/stylesheets/common/discourse-patrons.scss +++ b/assets/stylesheets/common/discourse-patrons.scss @@ -1,8 +1,13 @@ // TODO: This gets overridden somewhere. It is defined in common/base/discourse.scss -input[disabled], input[readonly], select[disabled], select[readonly], textarea[disabled], textarea[readonly] { - cursor: not-allowed; - background-color: #e9e9e9; - border-color: #e9e9e9; +input[disabled], +input[readonly], +select[disabled], +select[readonly], +textarea[disabled], +textarea[readonly] { + cursor: not-allowed; + background-color: #e9e9e9; + border-color: #e9e9e9; } .discourse-patrons-section-columns { diff --git a/plugin.rb b/plugin.rb index a0a6b8c..838436d 100644 --- a/plugin.rb +++ b/plugin.rb @@ -34,7 +34,7 @@ Discourse::Application.routes.append do get '/admin/plugins/discourse-patrons/subscriptions' => 'admin/plugins#index' get '/admin/plugins/discourse-patrons/plans' => 'admin/plugins#index' get '/admin/plugins/discourse-patrons/plans/:plan_id' => 'admin/plugins#index' - get 'u/:username/billing' => 'users#show', constraints: {username: USERNAME_ROUTE_FORMAT} + get 'u/:username/billing' => 'users#show', constraints: { username: USERNAME_ROUTE_FORMAT } end after_initialize do diff --git a/spec/controllers/discourse_patrons/patrons_controller_spec.rb b/spec/controllers/discourse_patrons/patrons_controller_spec.rb index 952814c..33ce641 100644 --- a/spec/controllers/discourse_patrons/patrons_controller_spec.rb +++ b/spec/controllers/discourse_patrons/patrons_controller_spec.rb @@ -27,54 +27,6 @@ module DiscoursePatrons end end - describe 'show' do - let!(:admin) { Fabricate(:admin) } - let!(:user) { Fabricate(:user) } - let(:payment_intent) { { customer: user.id } } - - before do - controller.stubs(:current_user).returns(user) - ::Stripe::PaymentIntent.stubs(:retrieve).returns(payment_intent) - end - - it 'responds ok' do - get :show, params: { pid: '123' }, format: :json - expect(response).to have_http_status(200) - end - - it 'requests the payment intent' do - ::Stripe::PaymentIntent.expects(:retrieve).with('abc-1234').returns(payment_intent) - get :show, params: { pid: 'abc-1234' }, format: :json - end - - it 'allows admin to see receipts' do - controller.expects(:current_user).returns(admin) - ::Stripe::PaymentIntent.expects(:retrieve).returns(metadata: { user_id: user.id }) - get :show, params: { pid: '123' }, format: :json - expect(response).to have_http_status(200) - end - - it 'does not allow another the user to see receipts' do - ::Stripe::PaymentIntent.expects(:retrieve).returns(metadata: { user_id: 9999 }) - get :show, params: { pid: '123' }, format: :json - - aggregate_failures do - expect(response).to have_http_status(200) - expect(JSON.parse(response.body)).to eq("error" => "Not found") - end - end - - it 'does not allow anon user to see receipts' do - controller.stubs(:current_user).returns(nil) - get :show, params: { pid: '123' }, format: :json - - aggregate_failures do - expect(response).to have_http_status(200) - expect(JSON.parse(response.body)).to eq("error" => "Not found") - end - end - end - describe 'create' do let!(:current_user) { Fabricate(:user) }