Handle setting of payment amount during checkout in OrderUpdater

This commit is contained in:
Matt-Yorkley
2022-01-31 23:38:23 +00:00
parent 4e4d9bb5a5
commit 31e6405125
3 changed files with 11 additions and 0 deletions

View File

@@ -35,6 +35,14 @@ module OrderManagement
end
persist_totals
update_pending_payment
end
def update_pending_payment
return unless order.state.in? ["payment", "confirmation"]
return unless order.pending_payments.any?
order.pending_payments.first.update_attribute :amount, order.total
end
# Updates the following Order total values:

View File

@@ -165,6 +165,7 @@ describe SplitCheckoutController, type: :controller do
expect(order.state).to eq "confirmation"
expect(order.payments.first.adjustment.amount).to eq 1.23
expect(order.payments.first.amount).to eq order.item_total + order.adjustment_total
expect(order.adjustment_total).to eq 1.23
expect(order.total).to eq order.item_total + order.adjustment_total
end

View File

@@ -129,6 +129,8 @@ describe ProcessPaymentIntent do
it "completes the order, but with failed payment state recorded" do
service.call!
order.reload
expect(order.state).to eq("complete")
expect(order.payment_state).to eq("failed")
expect(order).to have_received(:deliver_order_confirmation_email)