mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user