diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 998f0ceeea..049280b7b0 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -15,7 +15,7 @@ class CheckoutController < Spree::CheckoutController end def update - if @order.update_attributes(params[:order]) + if @order.update_attributes(object_params) fire_event('spree.checkout.update') while @order.state != "complete" if @order.state == "payment" @@ -52,8 +52,23 @@ class CheckoutController < Spree::CheckoutController end end + private + # Copied and modified from spree. Remove check for order state, since the state machine is + # progressed all the way in one go with the one page checkout. + def object_params + # For payment step, filter order parameters to produce the expected nested attributes for a single payment and its source, discarding attributes for payment methods other than the one selected + if params[:payment_source].present? && source_params = params.delete(:payment_source)[params[:order][:payments_attributes].first[:payment_method_id].underscore] + params[:order][:payments_attributes].first[:source_attributes] = source_params + end + if (params[:order][:payments_attributes]) + params[:order][:payments_attributes].first[:amount] = @order.total + end + params[:order] + end + + def update_failed clear_ship_address respond_to do |format| diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index 8b0efea314..54cfd6fa61 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -145,6 +145,10 @@ feature "As a consumer I want to check out my cart", js: true do place_order page.should have_content "Your order has been processed successfully" + + # Order should have a payment with the correct amount + o = Spree::Order.complete.first + o.payments.first.amount.should == 10 end it "shows the payment processing failed message when submitted with an invalid credit card" do diff --git a/spec/support/request/shop_workflow.rb b/spec/support/request/shop_workflow.rb index c87d33149a..e8fd6e3b17 100644 --- a/spec/support/request/shop_workflow.rb +++ b/spec/support/request/shop_workflow.rb @@ -13,6 +13,7 @@ module ShopWorkflow def add_product_to_cart create(:line_item, variant: product.master, order: order) + order.reload.save! # Recalculate totals end def toggle_accordion(name)