list plans
This commit is contained in:
parent
bfdc8a5691
commit
1b232a1bd4
|
@ -6,6 +6,11 @@ module DiscoursePatrons
|
||||||
|
|
||||||
before_action :set_api_key
|
before_action :set_api_key
|
||||||
|
|
||||||
|
def index
|
||||||
|
plans = ::Stripe::Plan.list
|
||||||
|
render json: plans.data
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
plan = ::Stripe::Plan.create(
|
plan = ::Stripe::Plan.create(
|
||||||
amount: params[:amount],
|
amount: params[:amount],
|
||||||
|
@ -17,7 +22,7 @@ module DiscoursePatrons
|
||||||
id: 'gold-special',
|
id: 'gold-special',
|
||||||
)
|
)
|
||||||
|
|
||||||
plan.to_json
|
render json: plan
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ module DiscoursePatrons
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
def set_api_key
|
def set_api_key
|
||||||
::Stripe.api_key = 'SiteSetting.discourse_patrons_secret_key'
|
::Stripe.api_key = SiteSetting.discourse_patrons_secret_key
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
export default Ember.Controller.extend({
|
||||||
|
actions: {
|
||||||
|
deletePlan(plan) {}
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
|
||||||
|
export default Discourse.Route.extend({
|
||||||
|
model() {
|
||||||
|
return ajax("/patrons/admin/plans", { method: "get" });
|
||||||
|
}
|
||||||
|
});
|
|
@ -1 +1,2 @@
|
||||||
|
|
||||||
export default Discourse.Route.extend({});
|
export default Discourse.Route.extend({});
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
// model(params) {
|
model(params) {
|
||||||
// return ajax("/patrons/admin/subscriptions", {
|
return ajax("/patrons/admin/subscriptions", { method: "get" });
|
||||||
// method: "get",
|
}
|
||||||
// data: {
|
|
||||||
// order: params.order,
|
|
||||||
// descending: params.descending
|
|
||||||
// }
|
|
||||||
// }).then(results => results);
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -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>
|
|
@ -1,5 +1,4 @@
|
||||||
|
|
||||||
|
|
||||||
<h3>{{i18n 'discourse_patrons.admin.plans.title'}}</h3>
|
<h3>{{i18n 'discourse_patrons.admin.plans.title'}}</h3>
|
||||||
|
|
||||||
{{#link-to 'adminPlugins.discourse-patrons.plans.show' 'new' class="btn btn-primary"}}
|
{{#link-to 'adminPlugins.discourse-patrons.plans.show' 'new' class="btn btn-primary"}}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
<h3>Subscription Plans</h3>
|
<h3>{{i18n 'discourse_patrons.admin.plans'}}</h3>
|
||||||
|
|
||||||
<table class="table discourse-patrons-admin">
|
<table class="table discourse-patrons-admin">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
<th>Amount</th>
|
<th>Amount</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{{#each model as |plan|}}
|
{{#each model as |subscription|}}
|
||||||
<tr>
|
<tr>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -54,8 +54,10 @@ en:
|
||||||
name: Name
|
name: Name
|
||||||
amount: Amount
|
amount: Amount
|
||||||
interval: Interval
|
interval: Interval
|
||||||
table:
|
plan:
|
||||||
head:
|
plan_id: Plan ID
|
||||||
plan: Plan
|
nickname: Nickname
|
||||||
|
interval: Interval
|
||||||
|
amount: Amount
|
||||||
subscriptions:
|
subscriptions:
|
||||||
title: Subscriptions
|
title: Subscriptions
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
DiscoursePatrons::Engine.routes.draw do
|
DiscoursePatrons::Engine.routes.draw do
|
||||||
get '/admin' => 'admin#index'
|
get '/admin' => 'admin#index'
|
||||||
get '/admin/subscriptions' => 'subscriptions#index'
|
get '/admin/subscriptions' => 'subscriptions#index'
|
||||||
|
get '/admin/plans' => 'plans#index'
|
||||||
get '/admin/plans/:plan_id' => 'plans#show'
|
get '/admin/plans/:plan_id' => 'plans#show'
|
||||||
post '/admin/plans' => 'plans#create'
|
post '/admin/plans' => 'plans#create'
|
||||||
get '/' => 'patrons#index'
|
get '/' => 'patrons#index'
|
||||||
|
|
|
@ -12,20 +12,29 @@ module DiscoursePatrons
|
||||||
expect(DiscoursePatrons::PlansController < Admin::AdminController).to eq(true)
|
expect(DiscoursePatrons::PlansController < Admin::AdminController).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a plan with a currency" do
|
describe "index" do
|
||||||
SiteSetting.stubs(:discourse_patrons_currency).returns('aud')
|
it "is ok" do
|
||||||
::Stripe::Plan.expects(:create).with(has_entry(:currency, 'aud'))
|
::Stripe::Plan.expects(:list)
|
||||||
post "/patrons/admin/plans.json", params: {}
|
get "/patrons/admin/plans.json"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a plan with an interval" do
|
describe "create" do
|
||||||
::Stripe::Plan.expects(:create).with(has_entry(:interval, 'week'))
|
it "creates a plan with a currency" do
|
||||||
post "/patrons/admin/plans.json", params: { interval: 'week' }
|
SiteSetting.stubs(:discourse_patrons_currency).returns('aud')
|
||||||
end
|
::Stripe::Plan.expects(:create).with(has_entry(:currency, 'aud'))
|
||||||
|
post "/patrons/admin/plans.json", params: {}
|
||||||
|
end
|
||||||
|
|
||||||
it "creates a plan with an amount" do
|
it "creates a plan with an interval" do
|
||||||
::Stripe::Plan.expects(:create).with(has_entry(:amount, '102'))
|
::Stripe::Plan.expects(:create).with(has_entry(:interval, 'week'))
|
||||||
post "/patrons/admin/plans.json", params: { amount: '102' }
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue