mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-03-06 09:39:51 +00:00
plans have group names
This commit is contained in:
parent
bb1e330f68
commit
a94287434d
@ -27,6 +27,7 @@ module DiscoursePatrons
|
||||
product: params[:product],
|
||||
trial_period_days: params[:trial_period_days],
|
||||
currency: SiteSetting.discourse_patrons_currency,
|
||||
metadata: { group_name: params[:metadata][:group_name] }
|
||||
)
|
||||
|
||||
render_json_dump plan
|
||||
|
@ -73,7 +73,6 @@ module DiscoursePatrons
|
||||
name: params[:name],
|
||||
statement_descriptor: params[:statement_descriptor],
|
||||
active: params[:active],
|
||||
metadata: { group_name: params[:metadata][:group_name] }
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -6,6 +6,7 @@ const AdminPlan = Discourse.Model.extend({
|
||||
interval: "month",
|
||||
amount: 0,
|
||||
intervals: ["day", "week", "month", "year"],
|
||||
metadata: {},
|
||||
|
||||
@computed("created")
|
||||
createdFormatted(created) {
|
||||
@ -22,7 +23,8 @@ const AdminPlan = Discourse.Model.extend({
|
||||
interval: this.interval,
|
||||
amount: this.amount,
|
||||
trial_period_days: this.trial_period_days,
|
||||
product: this.product
|
||||
product: this.product,
|
||||
metadata: this.metadata,
|
||||
};
|
||||
|
||||
return ajax("/patrons/admin/plans", { method: "post", data });
|
||||
|
@ -1,4 +1,5 @@
|
||||
import AdminPlan from "discourse/plugins/discourse-patrons/discourse/models/admin-plan";
|
||||
import Group from "discourse/models/group";
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
model(params) {
|
||||
@ -13,7 +14,9 @@ export default Discourse.Route.extend({
|
||||
plan = AdminPlan.find(id);
|
||||
}
|
||||
|
||||
return Ember.RSVP.hash({ plan, product });
|
||||
const groups = Group.findAll({ ignore_automatic: true });
|
||||
|
||||
return Ember.RSVP.hash({ plan, product, groups });
|
||||
},
|
||||
|
||||
renderTemplate() {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import AdminProduct from "discourse/plugins/discourse-patrons/discourse/models/admin-product";
|
||||
import AdminPlan from "discourse/plugins/discourse-patrons/discourse/models/admin-plan";
|
||||
import Group from "discourse/models/group";
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
model(params) {
|
||||
@ -16,9 +15,7 @@ export default Discourse.Route.extend({
|
||||
plans = AdminPlan.findAll({ product_id });
|
||||
}
|
||||
|
||||
const groups = Group.findAll({ ignore_automatic: true });
|
||||
|
||||
return Ember.RSVP.hash({ plans, product, groups });
|
||||
return Ember.RSVP.hash({ plans, product });
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
@ -13,6 +13,13 @@
|
||||
{{i18n 'discourse_patrons.admin.plans.plan.nickname_help'}}
|
||||
</div>
|
||||
</p>
|
||||
<p>
|
||||
<label for="interval">{{i18n 'discourse_patrons.admin.plans.plan.group'}}</label>
|
||||
{{combo-box valueAttribute="name" content=model.groups value=model.plan.metadata.group_name}}
|
||||
<div class="control-instructions">
|
||||
{{i18n 'discourse_patrons.admin.plans.plan.group_help'}}
|
||||
</div>
|
||||
</p>
|
||||
<p>
|
||||
<label for="amount">{{i18n 'discourse_patrons.admin.plans.plan.amount'}}</label>
|
||||
{{input type="text" name="name" value=model.plan.amount}}
|
||||
|
@ -15,15 +15,8 @@
|
||||
</div>
|
||||
</p>
|
||||
<p>
|
||||
<label for="interval">{{i18n 'discourse_patrons.admin.products.product.group'}}</label>
|
||||
{{combo-box valueAttribute="name" content=model.groups value=model.product.metadata.group_name}}
|
||||
<div class="control-instructions">
|
||||
{{i18n 'discourse_patrons.admin.products.product.group_help'}}
|
||||
</div>
|
||||
</p>
|
||||
<p>
|
||||
<label for="interval">{{i18n 'discourse_patrons.admin.products.product.active'}}</label>
|
||||
{{input type="checkbox" checked=model.product.active}}
|
||||
<label for="active">{{i18n 'discourse_patrons.admin.products.product.active'}}</label>
|
||||
{{input type="checkbox" name="active" checked=model.product.active}}
|
||||
</p>
|
||||
</form>
|
||||
|
||||
@ -35,6 +28,7 @@
|
||||
<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.created_at'}}</th>
|
||||
<th>{{i18n 'discourse_patrons.admin.plans.plan.group'}}</th>
|
||||
<th class="td-right">{{i18n 'discourse_patrons.admin.plans.plan.amount'}}</th>
|
||||
<th class="td-right">
|
||||
{{#link-to "adminPlugins.discourse-patrons.products.show.plans.show" model.product.id "new" class="btn"}}
|
||||
@ -47,6 +41,7 @@
|
||||
<td>{{plan.nickname}}</td>
|
||||
<td>{{plan.interval}}</td>
|
||||
<td>{{format-date plan.createdFormatted}}</td>
|
||||
<td>{{plan.metadata.group_name}}</td>
|
||||
<td class="td-right">{{plan.amount}}</td>
|
||||
<td class="td-right">
|
||||
{{#link-to "adminPlugins.discourse-patrons.products.show.plans.show" model.product.id plan.id class="btn no-text btn-icon"}}
|
||||
@ -65,7 +60,7 @@
|
||||
<td colspan="5">
|
||||
{{#unless model.plans}}
|
||||
<hr>
|
||||
Create a pricing plan to subscribe customers to this product
|
||||
{{i18n 'discourse_patrons.admin.products.product.plan_help'}}
|
||||
{{/unless}}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -75,6 +75,7 @@ en:
|
||||
statement_descriptor_help: Extra information about a product which will appear on your customer’s credit card statement.
|
||||
group: User Group
|
||||
group_help: This is the discourse user group the customer gets added to when the subscription is created.
|
||||
plan_help: Create a pricing plan to subscribe customers to this product
|
||||
active: Active
|
||||
created_at: Created
|
||||
plans:
|
||||
@ -95,6 +96,8 @@ en:
|
||||
amount: Amount
|
||||
trial: Trial Period Days
|
||||
trial_help: Subscriptions to this plan will automatically start with a free trial of this length
|
||||
group: User Group
|
||||
group_help: This is the discourse user group the customer gets added to when the subscription is created.
|
||||
created_at: Created
|
||||
subscriptions:
|
||||
title: Subscriptions
|
||||
|
@ -79,33 +79,38 @@ module DiscoursePatrons
|
||||
describe "create" do
|
||||
it "creates a plan with a nickname" do
|
||||
::Stripe::Plan.expects(:create).with(has_entry(:nickname, 'Veg'))
|
||||
post "/patrons/admin/plans.json", params: { nickname: 'Veg' }
|
||||
post "/patrons/admin/plans.json", params: { nickname: 'Veg', metadata: { group_name: '' } }
|
||||
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: {}
|
||||
post "/patrons/admin/plans.json", params: { metadata: { group_name: '' } }
|
||||
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' }
|
||||
post "/patrons/admin/plans.json", params: { interval: 'week', metadata: { group_name: '' } }
|
||||
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' }
|
||||
post "/patrons/admin/plans.json", params: { amount: '102', metadata: { group_name: '' } }
|
||||
end
|
||||
|
||||
it "creates a plan with a trial period" do
|
||||
::Stripe::Plan.expects(:create).with(has_entry(:trial_period_days, '14'))
|
||||
post "/patrons/admin/plans.json", params: { trial_period_days: '14' }
|
||||
post "/patrons/admin/plans.json", params: { trial_period_days: '14', metadata: { group_name: '' } }
|
||||
end
|
||||
|
||||
it "creates a plan with a product" do
|
||||
::Stripe::Plan.expects(:create).with(has_entry(product: 'prod_walterwhite'))
|
||||
post "/patrons/admin/plans.json", params: { product: 'prod_walterwhite' }
|
||||
post "/patrons/admin/plans.json", params: { product: 'prod_walterwhite', metadata: { group_name: '' } }
|
||||
end
|
||||
|
||||
it 'has a metadata' do
|
||||
::Stripe::Plan.expects(:create).with(has_entry(metadata: { group_name: 'discourse-user-group-name' }))
|
||||
post "/patrons/admin/plans.json", params: { metadata: { group_name: 'discourse-user-group-name' } }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -56,27 +56,22 @@ module DiscoursePatrons
|
||||
describe 'create' do
|
||||
it 'is of product type service' do
|
||||
::Stripe::Product.expects(:create).with(has_entry(:type, 'service'))
|
||||
post "/patrons/admin/products.json", params: { metadata: { group_name: '' } }
|
||||
post "/patrons/admin/products.json", params: { }
|
||||
end
|
||||
|
||||
it 'has a name' do
|
||||
::Stripe::Product.expects(:create).with(has_entry(:name, 'Jesse Pinkman'))
|
||||
post "/patrons/admin/products.json", params: { name: 'Jesse Pinkman', metadata: { group_name: '' } }
|
||||
post "/patrons/admin/products.json", params: { name: 'Jesse Pinkman' }
|
||||
end
|
||||
|
||||
it 'has an active attribute' do
|
||||
::Stripe::Product.expects(:create).with(has_entry(active: 'false'))
|
||||
post "/patrons/admin/products.json", params: { active: 'false', metadata: { group_name: '' } }
|
||||
post "/patrons/admin/products.json", params: { active: 'false' }
|
||||
end
|
||||
|
||||
it 'has a statement descriptor' do
|
||||
::Stripe::Product.expects(:create).with(has_entry(statement_descriptor: 'Blessed are the cheesemakers'))
|
||||
post "/patrons/admin/products.json", params: { statement_descriptor: 'Blessed are the cheesemakers', metadata: { group_name: '' } }
|
||||
end
|
||||
|
||||
it 'has a metadata' do
|
||||
::Stripe::Product.expects(:create).with(has_entry(metadata: { group_name: 'discourse-user-group-name' }))
|
||||
post "/patrons/admin/products.json", params: { metadata: { group_name: 'discourse-user-group-name' } }
|
||||
post "/patrons/admin/products.json", params: { statement_descriptor: 'Blessed are the cheesemakers' }
|
||||
end
|
||||
end
|
||||
|
||||
@ -90,7 +85,7 @@ module DiscoursePatrons
|
||||
describe 'update' do
|
||||
it 'updates the product' do
|
||||
::Stripe::Product.expects(:update)
|
||||
patch "/patrons/admin/products/prod_walterwhite.json", params: { metadata: { group_name: '' } }
|
||||
patch "/patrons/admin/products/prod_walterwhite.json", params: {}
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user