Sha256: 2057b6679add6476fe28167c5ca55edfa440766748a90e776967e86d6d20c896

Contents?: true

Size: 1.96 KB

Versions: 9

Compression:

Stored size: 1.96 KB

Contents

module Spree
  module Admin
    class PaymentMethodsController < ResourceController
      skip_before_filter :load_resource, :only => [:create]
      before_filter :load_data

      respond_to :html

      def create
        @payment_method = params[:payment_method].delete(:type).constantize.new(params[:payment_method])
        @object = @payment_method
        invoke_callbacks(:create, :before)
        if @payment_method.save
          invoke_callbacks(:create, :after)
          flash[:success] = I18n.t(:successfully_created, :resource => I18n.t(:payment_method))
          respond_with(@payment_method, :location => edit_admin_payment_method_path(@payment_method))
        else
          invoke_callbacks(:create, :fails)
          respond_with(@payment_method)
        end
      end

      def update
        invoke_callbacks(:update, :before)
        payment_method_type = params[:payment_method].delete(:type)
        if @payment_method['type'].to_s != payment_method_type
          @payment_method.update_column(:type, payment_method_type)
          @payment_method = PaymentMethod.find(params[:id])
        end

        payment_method_params = params[ActiveModel::Naming.param_key(@payment_method)] || {}
        attributes = params[:payment_method].merge(payment_method_params)
        attributes.each do |k,v|
          if k.include?("password") && attributes[k].blank?
            attributes.delete(k)
          end
        end

        if @payment_method.update_attributes(attributes)
          invoke_callbacks(:update, :after)
          flash[:success] = I18n.t(:successfully_updated, :resource => I18n.t(:payment_method))
          respond_with(@payment_method, :location => edit_admin_payment_method_path(@payment_method))
        else
          invoke_callbacks(:update, :fails)
          respond_with(@payment_method)
        end
      end

      private

      def load_data
        @providers = Gateway.providers.sort{|p1, p2| p1.name <=> p2.name }
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
spree_core-1.3.5 app/controllers/spree/admin/payment_methods_controller.rb
spree_core-1.3.4 app/controllers/spree/admin/payment_methods_controller.rb
spree_core-1.3.3 app/controllers/spree/admin/payment_methods_controller.rb
spree_core-1.3.2 app/controllers/spree/admin/payment_methods_controller.rb
spree_core-1.3.1 app/controllers/spree/admin/payment_methods_controller.rb
spree_core-1.3.0 app/controllers/spree/admin/payment_methods_controller.rb
spree_core-1.3.0.rc2 app/controllers/spree/admin/payment_methods_controller.rb
dup_spree_core-1.3.0.rc1 app/controllers/spree/admin/payment_methods_controller.rb
spree_core-1.3.0.rc1 app/controllers/spree/admin/payment_methods_controller.rb