Move tax charge logic out of checkout controller and update payment transition

This commit is contained in:
Matt-Yorkley
2023-06-02 23:19:26 +01:00
parent bf912ae4d3
commit 074eb4b592
4 changed files with 10 additions and 13 deletions

View File

@@ -24,7 +24,7 @@ class SplitCheckoutController < ::BaseController
def edit
redirect_to_step_based_on_order unless params[:step]
check_step if params[:step]
recalculate_tax if params[:step] == "summary"
apply_voucher if @order.voucher_adjustments.present?
flash_error_when_no_shipping_method_available if available_shipping_methods.none?
end
@@ -309,12 +309,6 @@ class SplitCheckoutController < ::BaseController
end
end
def recalculate_tax
@order.create_tax_charge!
@order.update_order!
apply_voucher if @order.voucher_adjustments.present?
end
def apply_voucher
VoucherAdjustmentsService.calculate(@order)

View File

@@ -77,7 +77,10 @@ module Spree
before_transition to: :delivery, do: :ensure_available_shipping_rates
before_transition to: :confirmation, do: :validate_payment_method!
after_transition to: :payment, do: :create_tax_charge!
after_transition to: :payment do |order|
order.create_tax_charge!
order.update_totals_and_states
end
after_transition to: :complete, do: :finalize!
after_transition to: :resumed, do: :after_resume
after_transition to: :canceled, do: :after_cancel

View File

@@ -57,7 +57,7 @@ describe Spree::Admin::OrdersController, type: :controller do
it "updates fees and taxes and redirects to order details page" do
expect(order).to receive(:recreate_all_fees!)
expect(order).to receive(:create_tax_charge!)
expect(order).to receive(:create_tax_charge!).at_least :once
spree_put :update, params

View File

@@ -99,12 +99,12 @@ describe "As a consumer, I want to see adjustment breakdown" do
choose "Delivery"
click_button "Next - Payment method"
click_on "Next - Order summary"
click_on "Complete order"
# DB checks
order_within_zone.reload
expect(order_within_zone.additional_tax_total).to eq(1.3)
expect(order_within_zone.reload.additional_tax_total).to eq(1.3)
click_on "Next - Order summary"
click_on "Complete order"
# UI checks
expect(page).to have_content("Confirmed")