<commit_before>module Spree
  module Api
    class PaymentsController < Spree::Api::BaseController

      before_filter :find_order
      before_filter :find_payment, only: [:update, :show, :authorize, :purchase, :capture, :void, :credit]

      def index
        @payments = @order.payments.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
        respond_with(@payments)
      end

      def new
        @payment_methods = Spree::PaymentMethod.where(environment: Rails.env)
        respond_with(@payment_method)
      end

      def create
        @payment = @order.payments.build(payment_params)
        if @payment.save
          respond_with(@payment, status: 201, default_template: :show)
        else
          invalid_resource!(@payment)
        end
      end

      def update
        authorize! params[:action], @payment
        if ! @payment.pending?
          render 'update_forbidden', status: 403
        elsif @payment.update_attributes(payment_params)
          respond_with(@payment, default_template: :show)
        else
          invalid_resource!(@payment)
        end
      end

      def show
        respond_with(@payment)
      end
<commit_msg>Payment methods should be scoped to available.<commit_after>module Spree
  module Api
    class PaymentsController < Spree::Api::BaseController

      before_filter :find_order
      before_filter :find_payment, only: [:update, :show, :authorize, :purchase, :capture, :void, :credit]

      def index
        @payments = @order.payments.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
        respond_with(@payments)
      end

      def new
        @payment_methods = Spree::PaymentMethod.available
        respond_with(@payment_method)
      end

      def create
        @payment = @order.payments.build(payment_params)
        if @payment.save
          respond_with(@payment, status: 201, default_template: :show)
        else
          invalid_resource!(@payment)
        end
      end

      def update
        authorize! params[:action], @payment
        if ! @payment.pending?
          render 'update_forbidden', status: 403
        elsif @payment.update_attributes(payment_params)
          respond_with(@payment, default_template: :show)
        else
          invalid_resource!(@payment)
        end
      end

      def show
        respond_with(@payment)
      end

{'fraction_non_alphanumeric': 0.09661229611041405, 'fraction_numerical': 0.005018820577164366, 'mean_word_length': 2.548961424332344, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6340424', 'n_tokens_mistral': 686, 'n_tokens_neox': 660, 'n_words': 147}