diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index aedfdd70f8..036b22c5ae 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -29,7 +29,17 @@ module Spree hide_ofn_navigation(@order.distributor) end - def show; end + def show + credit_payment_method = @order.distributor.payment_methods.customer_credit + credit_payment = @order.payments.find_by(payment_method: credit_payment_method) + @paid_with_credit = credit_payment&.amount + + @payment_total = if credit_payment.nil? + @order.payment_total + else + @order.payment_total - @paid_with_credit + end + end def empty if @order = current_order diff --git a/app/views/spree/orders/_form.html.haml b/app/views/spree/orders/_form.html.haml index 943a677c3c..07cd626659 100644 --- a/app/views/spree/orders/_form.html.haml +++ b/app/views/spree/orders/_form.html.haml @@ -48,9 +48,17 @@ %h5 = t :orders_form_total %td.text-right - %h5.order-total.grand-total= @order.display_total + %h5.order-total.grand-total= @order.display_total.to_html %td + - if @paid_with_credit.present? + %tr + %td.text-right{colspan: "3"} + %strong + = t :customer_credit + %td.text-right#customer-credit + %span.order-total= Spree::Money.new(-1 * @paid_with_credit).to_html + - if @order.total_tax > 0 %tr %td.text-right{colspan:"3"} diff --git a/app/views/spree/orders/_totals_footer.html.haml b/app/views/spree/orders/_totals_footer.html.haml index ecd29ccf31..7c5a4bf17f 100644 --- a/app/views/spree/orders/_totals_footer.html.haml +++ b/app/views/spree/orders/_totals_footer.html.haml @@ -25,13 +25,21 @@ = t :order_total_price %td.text-right.total %h5#order_total= order.display_total.to_html + - if @paid_with_credit.present? + %tr.total + %td.text-right{colspan: "3"} + %strong + = t :customer_credit + %td.text-right.total#customer-credit + %strong + = Spree::Money.new(-1 * @paid_with_credit).to_html %tr.total %td.text-right{colspan: "3"} %strong = t :order_amount_paid - %td.text-right.total{id: "amount-paid"} + %td.text-right.total#amount-paid %strong - = order.display_payment_total.to_html + = Spree::Money.new(@payment_total).to_html - if order.outstanding_balance.positive? %tr.total %td.text-right{colspan: "3"} diff --git a/spec/system/consumer/checkout/summary_spec.rb b/spec/system/consumer/checkout/summary_spec.rb index 84c9445d4c..594e3a5439 100644 --- a/spec/system/consumer/checkout/summary_spec.rb +++ b/spec/system/consumer/checkout/summary_spec.rb @@ -426,7 +426,8 @@ RSpec.describe "As a consumer, I want to checkout my order" do # TODO it should be displaying some kind indication it was paid with credit expect(page).to have_content "PAID" expect(page).to have_content "Paying via: Customer credit" - expect(page).to have_selector("#amount-paid", text: with_currency(10.00)) + expect(page).to have_selector("#customer-credit", text: with_currency(-10.00)) + expect(page).to have_selector("#amount-paid", text: with_currency(0.00)) end end @@ -469,9 +470,10 @@ RSpec.describe "As a consumer, I want to checkout my order" do expect(page).to have_content "NOT PAID" expect(page).to have_content "Paying via: #{payment_method.display_name}" within "#line-items" do - expect(page).to have_selector("#amount-paid", text: with_currency(2.00)) - # actual order total is 10.00 + expect(page).to have_selector("#customer-credit", text: with_currency(-2.00)) + expect(page).to have_selector("#amount-paid", text: with_currency(0.00)) expect(page).to have_content("Balance Due") + # actual order total is 10.00 expect(page).to have_selector("#balance-due", text: with_currency(8.00)) end end diff --git a/spec/system/consumer/shopping/orders_spec.rb b/spec/system/consumer/shopping/orders_spec.rb index e2e0c1ddc3..d14b510258 100644 --- a/spec/system/consumer/shopping/orders_spec.rb +++ b/spec/system/consumer/shopping/orders_spec.rb @@ -196,6 +196,26 @@ RSpec.describe "Order Management" do expect(page).to have_content 'Cancelled' expect(order.reload).to be_canceled end + + context "with customer credit" do + let(:credit_payment_method) { Spree::PaymentMethod.customer_credit } + + it "displays the credit used" do + create( + :customer_account_transaction, + amount: 100, customer: order.customer, + payment_method: credit_payment_method + ) + # Add credit payment + payment = order.payments.create!(payment_method: credit_payment_method, + amount: 2.00) + payment.internal_purchase! + + visit order_path(order) + + expect(page).to have_selector("#customer-credit", text: with_currency(-2.00)) + end + end end end