FIX: ordering
* Fix broken user id * ascending/descending
This commit is contained in:
parent
ca62cad04e
commit
18cf0e7f26
|
@ -12,9 +12,17 @@ module DiscoursePatrons
|
||||||
|
|
||||||
def payments_order
|
def payments_order
|
||||||
if %w(created_at amount).include?(params[:order])
|
if %w(created_at amount).include?(params[:order])
|
||||||
params[:order].to_sym
|
{ params[:order] => ascending }
|
||||||
else
|
else
|
||||||
:created_at
|
{ created_at: :asc }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def ascending
|
||||||
|
if params[:ascending] == 'false'
|
||||||
|
:desc
|
||||||
|
else
|
||||||
|
:asc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ module DiscoursePatrons
|
||||||
description: SiteSetting.discourse_patrons_payment_description,
|
description: SiteSetting.discourse_patrons_payment_description,
|
||||||
receipt_email: params[:receipt_email],
|
receipt_email: params[:receipt_email],
|
||||||
confirm: true,
|
confirm: true,
|
||||||
customer: user_id
|
metadata: { user_id: user_id }
|
||||||
)
|
)
|
||||||
|
|
||||||
Payment.create(
|
Payment.create(
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
queryParams: ["order"],
|
queryParams: ["order", "ascending"],
|
||||||
order: null,
|
order: null,
|
||||||
|
ascending: true,
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
loadMore() {},
|
loadMore() {},
|
||||||
|
|
||||||
orderPayments(order) {
|
orderPayments(order) {
|
||||||
|
if (order === this.get("order")) {
|
||||||
|
this.toggleProperty("ascending");
|
||||||
|
}
|
||||||
|
|
||||||
this.set("order", order);
|
this.set("order", order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,19 @@ export default Discourse.Route.extend({
|
||||||
queryParams: {
|
queryParams: {
|
||||||
order: {
|
order: {
|
||||||
refreshModel: true
|
refreshModel: true
|
||||||
|
},
|
||||||
|
ascending: {
|
||||||
|
refreshModel: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
model(params) {
|
model(params) {
|
||||||
return ajax("/patrons/admin", {
|
return ajax("/patrons/admin", {
|
||||||
method: "get",
|
method: "get",
|
||||||
data: { order: params.order }
|
data: {
|
||||||
|
order: params.order,
|
||||||
|
ascending: params.ascending
|
||||||
|
}
|
||||||
}).then(results => results);
|
}).then(results => results);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
|
|
||||||
|
{{#unless model.error}}
|
||||||
|
<h3>{{i18n 'discourse_patrons.heading.success' site_name=siteSettings.title}}</h3>
|
||||||
|
|
||||||
<h3>{{i18n 'discourse_patrons.heading.success' site_name=siteSettings.title}}</h3>
|
<p>
|
||||||
|
{{cook-text siteSettings.discourse_patrons_success_page}}
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>
|
|
||||||
{{cook-text siteSettings.discourse_patrons_success_page}}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
{{#if model}}
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{i18n 'discourse_patrons.payment_intent_id'}}</td>
|
<td>{{i18n 'discourse_patrons.payment_intent_id'}}</td>
|
||||||
|
@ -17,4 +16,4 @@
|
||||||
<td>{{model.amount}}</td>
|
<td>{{model.amount}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
{{/if}}
|
{{/unless}}
|
||||||
|
|
|
@ -9,5 +9,9 @@ module DiscoursePatrons
|
||||||
it 'is a subclass of AdminController' do
|
it 'is a subclass of AdminController' do
|
||||||
expect(DiscoursePatrons::AdminController < Admin::AdminController).to eq(true)
|
expect(DiscoursePatrons::AdminController < Admin::AdminController).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: authenticate to test these
|
||||||
|
it "is ascending"
|
||||||
|
it "is has ordered by"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,13 +49,13 @@ module DiscoursePatrons
|
||||||
|
|
||||||
it 'allows admin to see receipts' do
|
it 'allows admin to see receipts' do
|
||||||
controller.expects(:current_user).returns(admin)
|
controller.expects(:current_user).returns(admin)
|
||||||
::Stripe::PaymentIntent.expects(:retrieve).returns(customer: user.id)
|
::Stripe::PaymentIntent.expects(:retrieve).returns(metadata: { user_id: user.id })
|
||||||
get :show, params: { pid: '123' }, format: :json
|
get :show, params: { pid: '123' }, format: :json
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not allow another the user to see receipts' do
|
it 'does not allow another the user to see receipts' do
|
||||||
::Stripe::PaymentIntent.expects(:retrieve).returns(customer: 9999)
|
::Stripe::PaymentIntent.expects(:retrieve).returns(metadata: { user_id: 9999 })
|
||||||
get :show, params: { pid: '123' }, format: :json
|
get :show, params: { pid: '123' }, format: :json
|
||||||
|
|
||||||
aggregate_failures do
|
aggregate_failures do
|
||||||
|
@ -85,7 +85,7 @@ module DiscoursePatrons
|
||||||
amount: 9000,
|
amount: 9000,
|
||||||
receipt_email: 'hello@example.com',
|
receipt_email: 'hello@example.com',
|
||||||
currency: 'aud',
|
currency: 'aud',
|
||||||
customer: current_user.id
|
metadata: { user_id: current_user.id }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -134,8 +134,8 @@ module DiscoursePatrons
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has the customer id' do
|
it 'has the user id' do
|
||||||
::Stripe::PaymentIntent.expects(:create).with(has_entry(:customer, current_user.id)).returns(payment)
|
::Stripe::PaymentIntent.expects(:create).with(has_entry(:metadata, { user_id: current_user.id })).returns(payment)
|
||||||
post :create, params: {}, format: :json
|
post :create, params: {}, format: :json
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue