diff --git a/app/controllers/admin/plans_controller.rb b/app/controllers/admin/plans_controller.rb index 0f56505..c85f557 100644 --- a/app/controllers/admin/plans_controller.rb +++ b/app/controllers/admin/plans_controller.rb @@ -24,5 +24,10 @@ module DiscoursePatrons render json: plan end + + def destroy + plan = ::Stripe::Plan.delete(params[:id]) + render json: plan + end end end diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-plans-index.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-plans-index.js.es6 index 9fcc419..bb6314a 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-plans-index.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons-plans-index.js.es6 @@ -1,5 +1,9 @@ +import { ajax } from "discourse/lib/ajax"; + export default Ember.Controller.extend({ actions: { - deletePlan(plan) {} + deletePlan(id) { + return ajax(`/patrons/admin/plans/${id}`, { method: "delete" }); + } } }); diff --git a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-plans-index.hbs b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-plans-index.hbs index 0381917..f0fae54 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-plans-index.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-plans-index.hbs @@ -15,7 +15,7 @@ {{plan.interval}} {{plan.amount}} - {{d-button action=(action "deletePlan" plan) icon="trash" class="btn-danger btn no-text btn-icon"}} + {{d-button action=(action "deletePlan" plan.id) icon="trash-alt" class="btn-danger btn no-text btn-icon"}} {{/each}} diff --git a/config/routes.rb b/config/routes.rb index 94508b6..7574d3b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,15 @@ # frozen_string_literal: true DiscoursePatrons::Engine.routes.draw do - get '/admin' => 'admin#index' - get '/admin/subscriptions' => 'subscriptions#index' - get '/admin/plans' => 'plans#index' - get '/admin/plans/:plan_id' => 'plans#show' - post '/admin/plans' => 'plans#create' + scope 'admin' do + get '/' => 'admin#index' + + resources :subscriptions, only: [:index] + resources :plans + end + get '/' => 'patrons#index' get '/:pid' => 'patrons#show' + resources :patrons, only: [:index, :create] end diff --git a/spec/requests/plans_controller_spec.rb b/spec/requests/plans_controller_spec.rb index 480db3e..dc3b85b 100644 --- a/spec/requests/plans_controller_spec.rb +++ b/spec/requests/plans_controller_spec.rb @@ -36,5 +36,12 @@ module DiscoursePatrons post "/patrons/admin/plans.json", params: { amount: '102' } end end + + describe "delete" do + it "deletes a plan" do + ::Stripe::Plan.expects(:delete).with('plan_12345') + delete "/patrons/admin/plans/plan_12345.json" + end + end end end