diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 65d308bc0d..987f8d50d7 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -165,7 +165,7 @@ class CheckoutController < Spree::StoreController checkout_succeeded redirect_to(order_path(@order)) && return else - flash[:error] = order_workflow_error + flash[:error] = order_error checkout_failed end end @@ -179,8 +179,6 @@ class CheckoutController < Spree::StoreController @order.select_shipping_method(shipping_method_id) if @order.state == "delivery" next if advance_order_state(@order) - - flash[:error] = order_workflow_error return update_failed end @@ -205,7 +203,7 @@ class CheckoutController < Spree::StoreController false end - def order_workflow_error + def order_error if @order.errors.present? @order.errors.full_messages.to_sentence else @@ -245,6 +243,7 @@ class CheckoutController < Spree::StoreController end def update_failed + flash[:error] = order_error if flash.empty? checkout_failed update_failed_response end diff --git a/config/locales/en.yml b/config/locales/en.yml index 86c8f1611e..d8cf8784cd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -40,6 +40,8 @@ en: shipping_category_id: "Shipping Category" variant_unit: "Variant Unit" variant_unit_name: "Variant Unit Name" + spree/credit_card: + base: "Credit Card" order_cycle: orders_close_at: Close date errors: @@ -50,6 +52,10 @@ en: taken: "There's already an account for this email. Please login or reset your password." spree/order: no_card: There are no authorised credit cards available to charge + spree/credit_card: + attributes: + base: + card_expired: "has expired" order_cycle: attributes: orders_close_at: diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index b11ca1ab78..ccbf458674 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -197,13 +197,13 @@ describe CheckoutController, type: :controller do allow(controller).to receive(:current_order).and_return(order) end - it "returns errors" do + it "returns errors and flash if order.update_attributes fails" do spree_post :update, format: :json, order: {} expect(response.status).to eq(400) - expect(response.body).to eq({ errors: assigns[:order].errors, flash: {} }.to_json) + expect(response.body).to eq({ errors: assigns[:order].errors, flash: { error: order.errors.full_messages.to_sentence } }.to_json) end - it "returns flash" do + it "returns errors and flash if order.next fails" do allow(order).to receive(:update_attributes).and_return true allow(order).to receive(:next).and_return false spree_post :update, format: :json, order: {}