Display credit used on the order confirmation page

This commit is contained in:
Gaetan Craig-Riou
2026-02-17 16:40:30 +11:00
parent b42b10fcd1
commit a60afd10e4
5 changed files with 55 additions and 7 deletions

View File

@@ -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

View File

@@ -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"}

View File

@@ -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"}

View File

@@ -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

View File

@@ -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