fix statement descriptor param

This commit is contained in:
Rimian Perkins 2019-10-22 09:24:54 +11:00
parent c6dd47d328
commit 2179e3d280
3 changed files with 26 additions and 17 deletions

View File

@ -20,10 +20,7 @@ module DiscoursePatrons
def create def create
begin begin
product = ::Stripe::Product.create( product = ::Stripe::Product.create(
type: 'service', product_params.merge(type: 'service')
name: params[:name],
active: params[:active],
metadata: metadata
) )
render_json_dump product render_json_dump product
@ -48,9 +45,7 @@ module DiscoursePatrons
begin begin
product = ::Stripe::Product.update( product = ::Stripe::Product.update(
params[:id], params[:id],
name: params[:name], product_params
active: params[:active],
metadata: metadata
) )
render_json_dump product render_json_dump product
@ -73,8 +68,13 @@ module DiscoursePatrons
private private
def metadata def product_params
{ group_name: params[:metadata][:group_name] } {
name: params[:name],
statement_descriptor: params[:statement_descriptor],
active: params[:active],
metadata: { group_name: params[:metadata][:group_name] }
}
end end
end end
end end

View File

@ -53,12 +53,16 @@
</table> </table>
</p> </p>
<hr>
<div class="buttons"> <section>
{{#if model.product.isNew}} <hr>
{{d-button label="discourse_patrons.admin.products.operations.create" action="createProduct" icon="plus"}}
{{else}} <div class="pull-right">
{{d-button label="discourse_patrons.admin.products.operations.update" action="updateProduct" icon="fa-save"}} {{#if model.product.isNew}}
{{/if}} {{d-button label="discourse_patrons.admin.products.operations.create" action="createProduct" icon="plus"}}
</div> {{else}}
{{d-button label="discourse_patrons.admin.products.operations.update" action="updateProduct" icon="check"}}
{{/if}}
</div>
</section>

View File

@ -69,6 +69,11 @@ module DiscoursePatrons
post "/patrons/admin/products.json", params: { active: 'false', metadata: { group_name: '' } } post "/patrons/admin/products.json", params: { active: 'false', metadata: { group_name: '' } }
end 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 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: { metadata: { group_name: 'discourse-user-group-name' } } post "/patrons/admin/products.json", params: { metadata: { group_name: 'discourse-user-group-name' } }