Update pending payment for completed order

Update pending payment for cash order, so we can take into account any
changes affecting order toral (shipments, line item quantity etc...).
This is to allow payment capture to cover the order total, not just
the amount due at checkout.
This commit is contained in:
Gaetan Craig-Riou
2024-02-06 16:56:29 +11:00
parent e6fba74a87
commit 7da516b637
2 changed files with 18 additions and 1 deletions

View File

@@ -234,7 +234,10 @@ module OrderManagement
end
def update_pending_payment
return unless order.state.in? ["payment", "confirmation"]
# We only want to update complete order pending payment when it's a cash payment. We assume
# that if the payment was a credit card it would alread have been processed, so we don't
# bother checking the payment type
return unless order.state.in? ["payment", "confirmation", "complete"]
return unless order.pending_payments.any?
order.pending_payments.first.update_attribute :amount, order.total

View File

@@ -105,6 +105,20 @@ module OrderManagement
expect(shipment).to receive(:update!).with(order)
updater.update_shipments
end
context "whith pending payments" do
let(:order) { create(:completed_order_with_totals) }
it "updates pending payments" do
payment = create(:payment, order: , amount: order.total)
# update order so the order total will change
update_order_quantity(order)
order.payments.reload
expect { updater.update }.to change { payment.reload.amount }.from(50).to(60)
end
end
end
context "incompleted order" do