app/models/spree/braintree_vzero/order_decorator.rb
def update_from_params(params, permitted_params, request_env = {})
        success = false
        @updating_params = params
        run_callbacks :updating_from_params do
          # Set existing card after setting permitted parameters because
          # rails would slice parameters containg ruby objects, apparently
          existing_card_id = @updating_params[:order] ? @updating_params[:order].delete(:existing_card) : nil

          attributes = @updating_params[:order] ? @updating_params[:order].permit(permitted_params).delete_if { |_k, v| v.nil? } : {}
          payment_attributes = attributes[:payments_attributes].first if attributes[:payments_attributes].present?

          if existing_card_id.present?
            credit_card = Spree::CreditCard.find existing_card_id
            if credit_card.user_id != user_id || credit_card.user_id.blank?
              raise Spree::Core::GatewayError, Spree.t(:invalid_credit_card)
            end

            credit_card.verification_value = params[:cvc_confirm] if params[:cvc_confirm].present?

            attributes[:payments_attributes].first[:source] = credit_card
            attributes[:payments_attributes].first[:payment_method_id] = credit_card.payment_method_id
            attributes[:payments_attributes].first.delete :source_attributes
          end

          if payment_attributes.present?
            payment_attributes[:request_env] = request_env

            if (token = payment_attributes[:braintree_token]).present?
              payment_attributes[:source] = Spree::BraintreeCheckout.create_from_token(token, payment_attributes[:payment_method_id])
            elsif payment_attributes[:braintree_nonce].present?
              payment_attributes[:source] = Spree::BraintreeCheckout.create_from_params(params)
            end
          end

          success = update(attributes)
          set_shipments_cost if shipments.any?
        end

        @updating_params = nil
        success
      end
# override needed to add braintree source attribute
override needed to add braintree source attribute
override needed to add braintree source attribute
def update_from_params(params, permitted_params, request_env = {})
        success = false
        @updating_params = params
        run_callbacks :updating_from_params do
          existing_card_id = @updating_params[:order] ? @updating_params[:order].delete(:existing_card) : nil
          attributes = @updating_params[:order] ? @updating_params[:order].permit(permitted_params).delete_if { |_k, v| v.nil? } : {}
          payment_attributes = attributes[:payments_attributes].first if attributes[:payments_attributes].present?
          if existing_card_id.present?
            credit_card = Spree::CreditCard.find existing_card_id
            if credit_card.user_id != user_id || credit_card.user_id.blank?
              raise Spree::Core::GatewayError, Spree.t(:invalid_credit_card)
            end
            credit_card.verification_value = params[:cvc_confirm] if params[:cvc_confirm].present?
            attributes[:payments_attributes].first[:source] = credit_card
            attributes[:payments_attributes].first[:payment_method_id] = credit_card.payment_method_id
            attributes[:payments_attributes].first.delete :source_attributes
          end
          if payment_attributes.present?
            payment_attributes[:request_env] = request_env
            if (token = payment_attributes[:braintree_token]).present?
              payment_attributes[:source] = Spree::BraintreeCheckout.create_from_token(token, payment_attributes[:payment_method_id])
            elsif payment_attributes[:braintree_nonce].present?
              payment_attributes[:source] = Spree::BraintreeCheckout.create_from_params(params)
            end
          end
          success = update(attributes)
          set_shipments_cost if shipments.any?
        end
        @updating_params = nil
        success
      end
def update_from_params ( params , permitted_params , request_env = { } ) success = false @updating_params = params run_callbacks :updating_from_params do existing_card_id = @updating_params [ :order ] ? @updating_params [ :order ] . delete ( :existing_card ) : nil attributes = @updating_params [ :order ] ? @updating_params [ :order ] . permit ( permitted_params ) . delete_if { | _k , v | v . nil? } : { } payment_attributes = attributes [ :payments_attributes ] . first if attributes [ :payments_attributes ] . present? if existing_card_id . present? credit_card = Spree :: CreditCard . find existing_card_id if credit_card . user_id != user_id || credit_card . user_id . blank? raise Spree :: Core :: GatewayError , Spree . t ( :invalid_credit_card ) end credit_card . verification_value = params [ :cvc_confirm ] if params [ :cvc_confirm ] . present? attributes [ :payments_attributes ] . first [ :source ] = credit_card attributes [ :payments_attributes ] . first [ :payment_method_id ] = credit_card . payment_method_id attributes [ :payments_attributes ] . first . delete :source_attributes end if payment_attributes . present? payment_attributes [ :request_env ] = request_env if ( token = payment_attributes [ :braintree_token ] ) . present? payment_attributes [ :source ] = Spree :: BraintreeCheckout . create_from_token ( token , payment_attributes [ :payment_method_id ] ) elsif payment_attributes [ :braintree_nonce ] . present? payment_attributes [ :source ] = Spree :: BraintreeCheckout . create_from_params ( params ) end end success = update ( attributes ) set_shipments_cost if shipments . any? end @updating_params = nil success end
override needed to add braintree source attribute
override needed to add braintree source attribute
# Set existing card after setting permitted parameters because # rails would slice parameters containg ruby objects, apparently
params
permitted_params
request_env