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