delete plans

This commit is contained in:
Rimian Perkins 2019-09-25 13:20:28 +10:00
parent 1b232a1bd4
commit d4afe93a5d
5 changed files with 26 additions and 7 deletions

View File

@ -24,5 +24,10 @@ module DiscoursePatrons
render json: plan render json: plan
end end
def destroy
plan = ::Stripe::Plan.delete(params[:id])
render json: plan
end
end end
end end

View File

@ -1,5 +1,9 @@
import { ajax } from "discourse/lib/ajax";
export default Ember.Controller.extend({ export default Ember.Controller.extend({
actions: { actions: {
deletePlan(plan) {} deletePlan(id) {
return ajax(`/patrons/admin/plans/${id}`, { method: "delete" });
}
} }
}); });

View File

@ -15,7 +15,7 @@
<td>{{plan.interval}}</td> <td>{{plan.interval}}</td>
<td>{{plan.amount}}</td> <td>{{plan.amount}}</td>
<td> <td>
{{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"}}
</td> </td>
</tr> </tr>
{{/each}} {{/each}}

View File

@ -1,12 +1,15 @@
# frozen_string_literal: true # frozen_string_literal: true
DiscoursePatrons::Engine.routes.draw do DiscoursePatrons::Engine.routes.draw do
get '/admin' => 'admin#index' scope 'admin' do
get '/admin/subscriptions' => 'subscriptions#index' get '/' => 'admin#index'
get '/admin/plans' => 'plans#index'
get '/admin/plans/:plan_id' => 'plans#show' resources :subscriptions, only: [:index]
post '/admin/plans' => 'plans#create' resources :plans
end
get '/' => 'patrons#index' get '/' => 'patrons#index'
get '/:pid' => 'patrons#show' get '/:pid' => 'patrons#show'
resources :patrons, only: [:index, :create] resources :patrons, only: [:index, :create]
end end

View File

@ -36,5 +36,12 @@ module DiscoursePatrons
post "/patrons/admin/plans.json", params: { amount: '102' } post "/patrons/admin/plans.json", params: { amount: '102' }
end end
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
end end