Fix updating pending payment

Check if payment actually have an adjustment before trying to update it
This commit is contained in:
Gaetan Craig-Riou
2024-10-01 10:22:47 +10:00
parent a74cf97083
commit d01d312b4f

View File

@@ -240,19 +240,25 @@ module OrderManagement
return unless order.state.in? ["payment", "confirmation", "complete"]
return unless order.pending_payments.any?
@payment = order.pending_payments.first
return update_payment if @payment.adjustment.nil?
# Update payment tax fees if needed
payment = order.pending_payments.first
new_amount = payment.payment_method.compute_amount(payment)
if new_amount != payment.adjustment.amount
update_payment_adjustment(payment.adjustment, new_amount)
new_amount = @payment.payment_method.compute_amount(@payment)
if new_amount != @payment.adjustment.amount
update_payment_adjustment(new_amount)
end
# Update payment with correct amount
payment.update_attribute :amount, order.total
update_payment
end
def update_payment_adjustment(adjustment, amount)
adjustment.update_attribute(:amount, amount)
def update_payment
# Update payment with correct amount
@payment.update_attribute :amount, order.total
end
def update_payment_adjustment(amount)
@payment.adjustment.update_attribute(:amount, amount)
# Update order total to take into account updated payment fees
update_adjustment_total