mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-07-05 22:12:11 +00:00
meta data
This commit is contained in:
parent
496f2b9706
commit
d02ba3ef6a
@ -8,8 +8,13 @@ module DiscoursePatrons
|
|||||||
before_action :set_api_key
|
before_action :set_api_key
|
||||||
|
|
||||||
def index
|
def index
|
||||||
products = ::Stripe::Product.list
|
begin
|
||||||
render_json_dump products.data
|
products = ::Stripe::Product.list
|
||||||
|
|
||||||
|
render_json_dump products.data
|
||||||
|
rescue ::Stripe::InvalidRequestError => e
|
||||||
|
return render_json_error e.message
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@ -18,9 +23,7 @@ module DiscoursePatrons
|
|||||||
type: 'service',
|
type: 'service',
|
||||||
name: params[:name],
|
name: params[:name],
|
||||||
active: params[:active],
|
active: params[:active],
|
||||||
metadata: {
|
metadata: metadata
|
||||||
group_name: params[:group_name]
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
render_json_dump product
|
render_json_dump product
|
||||||
@ -47,9 +50,7 @@ module DiscoursePatrons
|
|||||||
params[:id], {
|
params[:id], {
|
||||||
name: params[:name],
|
name: params[:name],
|
||||||
active: params[:active],
|
active: params[:active],
|
||||||
metadata: {
|
metadata: metadata
|
||||||
group_name: params[:group_name]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -70,6 +71,12 @@ module DiscoursePatrons
|
|||||||
return render_json_error e.message
|
return render_json_error e.message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def metadata
|
||||||
|
{ group_name: params[:metadata][:group_name] }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,8 +8,13 @@ module DiscoursePatrons
|
|||||||
before_action :set_api_key
|
before_action :set_api_key
|
||||||
|
|
||||||
def index
|
def index
|
||||||
subscriptions = ::Stripe::Subscription.list
|
begin
|
||||||
render_json_dump subscriptions
|
subscriptions = ::Stripe::Subscription.list
|
||||||
|
|
||||||
|
render_json_dump subscriptions
|
||||||
|
rescue ::Stripe::InvalidRequestError => e
|
||||||
|
return render_json_error e.message
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,10 +4,10 @@ export default Ember.Controller.extend({
|
|||||||
actions: {
|
actions: {
|
||||||
createProduct() {
|
createProduct() {
|
||||||
// TODO: set default group name beforehand
|
// TODO: set default group name beforehand
|
||||||
if (this.get("model.product.groupName") === undefined) {
|
if (this.get("model.product.metadata.group_name") === undefined) {
|
||||||
this.set(
|
this.set(
|
||||||
"model.product.groupName",
|
"model.product.metadata",
|
||||||
this.get("model.group.firstObject")
|
{ group_name: this.get("model.groups.firstObject.name") }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ const AdminProduct = Discourse.Model.extend({
|
|||||||
save() {
|
save() {
|
||||||
const data = {
|
const data = {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
groupName: this.groupName,
|
metadata: this.metadata,
|
||||||
active: this.active
|
active: this.active
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ const AdminProduct = Discourse.Model.extend({
|
|||||||
update() {
|
update() {
|
||||||
const data = {
|
const data = {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
groupName: this.groupName,
|
metadata: this.metadata,
|
||||||
active: this.active
|
active: this.active
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<table class="table discourse-patrons-admin">
|
<table class="table discourse-patrons-admin">
|
||||||
<thead>
|
<thead>
|
||||||
<th>{{i18n 'discourse_patrons.admin.products.product.product_id'}}</th>
|
<th>{{i18n 'discourse_patrons.admin.products.product.product_id'}}</th>
|
||||||
|
<th>{{i18n 'discourse_patrons.admin.products.product.name'}}</th>
|
||||||
<th>{{i18n 'discourse_patrons.admin.products.product.group'}}</th>
|
<th>{{i18n 'discourse_patrons.admin.products.product.group'}}</th>
|
||||||
<th>{{i18n 'discourse_patrons.admin.products.product.active'}}</th>
|
<th>{{i18n 'discourse_patrons.admin.products.product.active'}}</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
@ -9,6 +10,7 @@
|
|||||||
{{#each model as |product|}}
|
{{#each model as |product|}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{product.id}}</td>
|
<td>{{product.id}}</td>
|
||||||
|
<td>{{product.name}}</td>
|
||||||
<td>{{product.metadata.group_name}}</td>
|
<td>{{product.metadata.group_name}}</td>
|
||||||
<td>{{product.active}}</td>
|
<td>{{product.active}}</td>
|
||||||
<td class="td-right">
|
<td class="td-right">
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="interval">{{i18n 'discourse_patrons.admin.products.product.group'}}</label>
|
<label for="interval">{{i18n 'discourse_patrons.admin.products.product.group'}}</label>
|
||||||
{{combo-box valueAttribute="value" content=model.groups value=model.product.groupName}}
|
{{combo-box valueAttribute="name" content=model.groups value=model.product.metadata.group_name}}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="interval">{{i18n 'discourse_patrons.admin.products.product.active'}}</label>
|
<label for="interval">{{i18n 'discourse_patrons.admin.products.product.active'}}</label>
|
||||||
|
@ -56,22 +56,22 @@ module DiscoursePatrons
|
|||||||
describe 'create' do
|
describe 'create' do
|
||||||
it 'is of product type service' do
|
it 'is of product type service' do
|
||||||
::Stripe::Product.expects(:create).with(has_entry(:type, 'service'))
|
::Stripe::Product.expects(:create).with(has_entry(:type, 'service'))
|
||||||
post "/patrons/admin/products.json", params: {}
|
post "/patrons/admin/products.json", params: { metadata: { group_name: '' } }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has a name' do
|
it 'has a name' do
|
||||||
::Stripe::Product.expects(:create).with(has_entry(:name, 'Jesse Pinkman'))
|
::Stripe::Product.expects(:create).with(has_entry(:name, 'Jesse Pinkman'))
|
||||||
post "/patrons/admin/products.json", params: { name: 'Jesse Pinkman' }
|
post "/patrons/admin/products.json", params: { name: 'Jesse Pinkman', metadata: { group_name: '' } }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has an active attribute' do
|
it 'has an active attribute' do
|
||||||
::Stripe::Product.expects(:create).with(has_entry(active: 'false'))
|
::Stripe::Product.expects(:create).with(has_entry(active: 'false'))
|
||||||
post "/patrons/admin/products.json", params: { active: 'false' }
|
post "/patrons/admin/products.json", params: { active: 'false', metadata: { group_name: '' } }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has a metadata' do
|
it 'has a metadata' do
|
||||||
::Stripe::Product.expects(:create).with(has_entry(metadata: { group_name: 'discourse-user-group-name' }))
|
::Stripe::Product.expects(:create).with(has_entry(metadata: { group_name: 'discourse-user-group-name' }))
|
||||||
post "/patrons/admin/products.json", params: { group_name: 'discourse-user-group-name' }
|
post "/patrons/admin/products.json", params: { metadata: { group_name: 'discourse-user-group-name' }}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ module DiscoursePatrons
|
|||||||
describe 'update' do
|
describe 'update' do
|
||||||
it 'updates the product' do
|
it 'updates the product' do
|
||||||
::Stripe::Product.expects(:update)
|
::Stripe::Product.expects(:update)
|
||||||
patch "/patrons/admin/products/prod_walterwhite.json", params: {}
|
patch "/patrons/admin/products/prod_walterwhite.json", params: { metadata: { group_name: '' }}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user