list plans

This commit is contained in:
Rimian Perkins 2019-09-25 11:18:11 +10:00
parent bfdc8a5691
commit 1b232a1bd4
12 changed files with 73 additions and 28 deletions

View File

@ -6,6 +6,11 @@ module DiscoursePatrons
before_action :set_api_key
def index
plans = ::Stripe::Plan.list
render json: plans.data
end
def create
plan = ::Stripe::Plan.create(
amount: params[:amount],
@ -17,7 +22,7 @@ module DiscoursePatrons
id: 'gold-special',
)
plan.to_json
render json: plan
end
end
end

View File

@ -5,7 +5,7 @@ module DiscoursePatrons
extend ActiveSupport::Concern
def set_api_key
::Stripe.api_key = 'SiteSetting.discourse_patrons_secret_key'
::Stripe.api_key = SiteSetting.discourse_patrons_secret_key
end
end
end

View File

@ -0,0 +1,5 @@
export default Ember.Controller.extend({
actions: {
deletePlan(plan) {}
}
});

View File

@ -0,0 +1,7 @@
import { ajax } from "discourse/lib/ajax";
export default Discourse.Route.extend({
model() {
return ajax("/patrons/admin/plans", { method: "get" });
}
});

View File

@ -1 +1,2 @@
export default Discourse.Route.extend({});

View File

@ -1,13 +1,7 @@
import { ajax } from "discourse/lib/ajax";
export default Discourse.Route.extend({
// model(params) {
// return ajax("/patrons/admin/subscriptions", {
// method: "get",
// data: {
// order: params.order,
// descending: params.descending
// }
// }).then(results => results);
// }
model(params) {
return ajax("/patrons/admin/subscriptions", { method: "get" });
}
});

View File

@ -0,0 +1,22 @@
<h3>{{i18n 'discourse_patrons.admin.plans.title'}}</h3>
<table class="table discourse-patrons-admin">
<thead>
<th>{{i18n 'discourse_patrons.admin.plans.plan.plan_id'}}</th>
<th>{{i18n 'discourse_patrons.admin.plans.plan.nickname'}}</th>
<th>{{i18n 'discourse_patrons.admin.plans.plan.interval'}}</th>
<th>{{i18n 'discourse_patrons.admin.plans.plan.amount'}}</th>
</thead>
{{#each model.plans as |plan|}}
<tr>
<td>{{plan.id}}</td>
<td>{{plan.nickname}}</td>
<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"}}
</td>
</tr>
{{/each}}
</table>

View File

@ -1,5 +1,4 @@
<h3>{{i18n 'discourse_patrons.admin.plans.title'}}</h3>
{{#link-to 'adminPlugins.discourse-patrons.plans.show' 'new' class="btn btn-primary"}}

View File

@ -1,5 +1,5 @@
<h3>Subscription Plans</h3>
<h3>{{i18n 'discourse_patrons.admin.plans'}}</h3>
<table class="table discourse-patrons-admin">
<thead>
@ -10,7 +10,7 @@
<th>Amount</th>
</tr>
</thead>
{{#each model as |plan|}}
{{#each model as |subscription|}}
<tr>
</tr>

View File

@ -54,8 +54,10 @@ en:
name: Name
amount: Amount
interval: Interval
table:
head:
plan: Plan
plan:
plan_id: Plan ID
nickname: Nickname
interval: Interval
amount: Amount
subscriptions:
title: Subscriptions

View File

@ -3,6 +3,7 @@
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'
get '/' => 'patrons#index'

View File

@ -12,20 +12,29 @@ module DiscoursePatrons
expect(DiscoursePatrons::PlansController < Admin::AdminController).to eq(true)
end
it "creates a plan with a currency" do
SiteSetting.stubs(:discourse_patrons_currency).returns('aud')
::Stripe::Plan.expects(:create).with(has_entry(:currency, 'aud'))
post "/patrons/admin/plans.json", params: {}
describe "index" do
it "is ok" do
::Stripe::Plan.expects(:list)
get "/patrons/admin/plans.json"
end
end
it "creates a plan with an interval" do
::Stripe::Plan.expects(:create).with(has_entry(:interval, 'week'))
post "/patrons/admin/plans.json", params: { interval: 'week' }
end
describe "create" do
it "creates a plan with a currency" do
SiteSetting.stubs(:discourse_patrons_currency).returns('aud')
::Stripe::Plan.expects(:create).with(has_entry(:currency, 'aud'))
post "/patrons/admin/plans.json", params: {}
end
it "creates a plan with an amount" do
::Stripe::Plan.expects(:create).with(has_entry(:amount, '102'))
post "/patrons/admin/plans.json", params: { amount: '102' }
it "creates a plan with an interval" do
::Stripe::Plan.expects(:create).with(has_entry(:interval, 'week'))
post "/patrons/admin/plans.json", params: { interval: 'week' }
end
it "creates a plan with an amount" do
::Stripe::Plan.expects(:create).with(has_entry(:amount, '102'))
post "/patrons/admin/plans.json", params: { amount: '102' }
end
end
end
end