mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Fix updating pending payment
Check if payment actually have an adjustment before trying to update it
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user