Sha256: 3d698b65a1745a4e87cc59d7c6383a08f64925514f9294df5be9c427a490461b

Contents?: true

Size: 1.16 KB

Versions: 84

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Spree
  module Api
    class CreditCardsController < Spree::Api::BaseController
      before_action :user, only: [:index]
      before_action :find_credit_card, only: [:update]

      def index
        @credit_cards = user
          .credit_cards
          .accessible_by(current_ability)
          .with_payment_profile
          .ransack(params[:q]).result

        @credit_cards = paginate(@credit_cards)
        respond_with(@credit_cards)
      end

      def update
        if @credit_card.update(credit_card_update_params)
          respond_with(@credit_card, default_template: :show)
        else
          invalid_resource!(@credit_card)
        end
      end

      private

      def user
        if params[:user_id].present?
          @user ||= Spree.user_class.accessible_by(current_ability, :show).find(params[:user_id])
        end
      end

      def find_credit_card
        @credit_card = Spree::CreditCard.find(params[:id])
        authorize! :update, @credit_card
      end

      def credit_card_update_params
        params.require(:credit_card).permit(permitted_credit_card_update_attributes)
      end
    end
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
solidus_api-4.4.1 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.4.0 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.3.4 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.2.4 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.1.5 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.3.3 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.3.2 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.1.4 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.3.1 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.3.0 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.2.3 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.1.3 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.0.4 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-3.4.6 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.0.3 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.1.2 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.2.2 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-3.4.5 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.2.1 app/controllers/spree/api/credit_cards_controller.rb
solidus_api-4.2.0 app/controllers/spree/api/credit_cards_controller.rb