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
end
def destroy
plan = ::Stripe::Plan.delete(params[:id])
render json: plan
end
end
end

View File

@ -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" });
}
}
});

View File

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

View File

@ -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

View File

@ -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