mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Show last payment method in order confirmation
If we had multiple failed payments and then a successful payment, the order confirmation was displaying the payment method of the first failed payment. That was confusing and is now changed to the last payment method.
This commit is contained in:
10
app/helpers/orders_helper.rb
Normal file
10
app/helpers/orders_helper.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
module OrdersHelper
|
||||
def order_paid_via(order)
|
||||
# `sort_by` avoids additional database queries when payments are loaded
|
||||
# already. There is usually only one payment and this shouldn't cause
|
||||
# any overhead compared to `order(:updated_at)`.
|
||||
#
|
||||
# Using `last` without sort is not deterministic.
|
||||
order.payments.sort_by(&:updated_at).last.andand.payment_method
|
||||
end
|
||||
end
|
||||
@@ -13,9 +13,9 @@
|
||||
.pad
|
||||
.text-big
|
||||
= t :order_payment
|
||||
%strong= order.payments.first.andand.payment_method.andand.name
|
||||
%strong= order_paid_via(order).andand.name
|
||||
%p.text-small.text-skinny.pre-line
|
||||
%em= order.payments.first.andand.payment_method.andand.description
|
||||
%em= order_paid_via(order).andand.description
|
||||
|
||||
.order-summary.text-small
|
||||
%strong
|
||||
|
||||
@@ -29,4 +29,26 @@ describe "spree/shared/_order_details.html.haml" do
|
||||
|
||||
expect(rendered).to have_content("Paying via: Bar<script>evil</script>ter→ing")
|
||||
end
|
||||
|
||||
it "shows the last used payment method" do
|
||||
first_payment = order.payments.first
|
||||
second_payment = create(
|
||||
:payment,
|
||||
order: order,
|
||||
payment_method: create(:payment_method, name: "Cash")
|
||||
)
|
||||
third_payment = create(
|
||||
:payment,
|
||||
order: order,
|
||||
payment_method: create(:payment_method, name: "Credit")
|
||||
)
|
||||
first_payment.update_column(:updated_at, 3.days.ago)
|
||||
second_payment.update_column(:updated_at, 2.days.ago)
|
||||
third_payment.update_column(:updated_at, 1.day.ago)
|
||||
order.payments.reload
|
||||
|
||||
render
|
||||
|
||||
expect(rendered).to have_content("Paying via: Credit")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user