From 06d657948635e1e7e1f01f4e327f79989758cd7d Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 4 Feb 2020 13:17:31 +0000 Subject: [PATCH] Refactor construct_saved_card_attributes to fix rubocop issues --- app/controllers/checkout_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 2db9293e00..a854b22236 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -296,13 +296,18 @@ class CheckoutController < Spree::StoreController existing_card_id = params[:order].delete(:existing_card_id) return if existing_card_id.blank? + move_to_payment_attributes(existing_card_id) + + params[:order][:payments_attributes].first.delete :source_attributes + end + + def move_to_payment_attributes(existing_card_id) credit_card = Spree::CreditCard.find(existing_card_id) if credit_card.try(:user_id).blank? || credit_card.user_id != spree_current_user.try(:id) raise Spree::Core::GatewayError, I18n.t(:invalid_credit_card) end params[:order][:payments_attributes].first[:source] = credit_card - params[:order][:payments_attributes].first.delete :source_attributes end def rescue_from_spree_gateway_error(error)