diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 62b8608409..5432ef8b2a 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -170,14 +170,6 @@ class CheckoutController < Spree::CheckoutController @order.ship_address ||= customer_preferred_ship_address || preferred_ship_address || last_used_ship_address || Spree::Address.default end - def after_payment - # object_params sets the payment amount to the order total, but it does this before - # the shipping method is set. This results in the customer not being charged for their - # order's shipping. To fix this, we refresh the payment amount here. - @order.update_totals - @order.payments.first.update_attribute :amount, @order.total - end - # Overriding Spree's methods def raise_insufficient_quantity respond_to do |format| diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 2eff1faa54..9ed6c30733 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -349,4 +349,15 @@ Spree::Order.class_eval do adjustment.update!(self) adjustment.locked = locked end + + # object_params sets the payment amount to the order total, but it does this before + # the shipping method is set. This results in the customer not being charged for their + # order's shipping. To fix this, we refresh the payment amount here. + def charge_shipping! + update_totals + return unless payments.any? + payments.first.update_attribute :amount, total + end end + +Spree::Order.state_machine.after_transition to: :payment, do: :charge_shipping!