<commit_before>class PaymentsController < ApplicationController
  GATEWAY_RESPONSES = %i<success decline>.freeze

  redispatch_request unless: :payment_required?

  before_action :validate_request, only: GATEWAY_RESPONSES

  def payment_request
    @payment_request ||= PaymentGateway::Request.new request,
      amount: fee_calculation.application_fee_after_remission * 100,
      reference: claim.payment_fee_group_reference
  end

  def fee_calculation
    @fee_calculation ||= claim.fee_calculation
  end

  helper_method :payment_request, :fee_calculation

  # BarclayCard transaction result callback actions

  delegate :amount, :reference, :status, :success?, to: :payment_response

  def success
    if success?
      claim.create_payment amount: amount, reference: reference
      claim.create_event Event::PAYMENT_RECEIVED
    else
      # Barclaycard can still push requests to this end point even if there
      # is no guarantee the transaction was successful.
      claim.create_event Event::PAYMENT_UNCERTAIN, message: payment_uncertain_message
    end

    claim.enqueue!
    redirect_to claim_confirmation_path
  end

  def decline
    claim.create_event Event::PAYMENT_DECLINED
    flash[:alert] = t('.payment_declined')
    claim.increment! :payment_attempts
    redirect_to :action => :show
  end

  private

  def payment_response
    @payment_response ||= PaymentGateway::Response.new request
  end

  def validate_request
    # Don't give anything away to attackers poking at the system
    render nothing: true unless payment_response.valid?
  end

  def ensure_payment_is_required
    render nothing: true unless claim.payment_required?
  end

  def payment_uncertain_message
    I18n.t(status, scope: 'barclaycard_gateway.responses', default: :generic, status: status)
  end

  # We want to be able to process a payment even if the session expired
  def claim
    # Strip padding from FGR (FGRs are padded with an incrementing integer
    # when retrying failed transactions)
    @claim ||= begin
      if params['orderID'].present?
        Claim.find_by fee_group_reference: params['orderID'].sub(/\-\d+\Z/, '')
      else
        super
      end
    end
  end
end<commit_msg>Remove unused private method from the payments controller.<commit_after>class PaymentsController < ApplicationController
  GATEWAY_RESPONSES = %i<success decline>.freeze

  redispatch_request unless: :payment_required?

  before_action :validate_request, only: GATEWAY_RESPONSES

  def payment_request
    @payment_request ||= PaymentGateway::Request.new request,
      amount: fee_calculation.application_fee_after_remission * 100,
      reference: claim.payment_fee_group_reference
  end

  def fee_calculation
    @fee_calculation ||= claim.fee_calculation
  end

  helper_method :payment_request, :fee_calculation

  # BarclayCard transaction result callback actions

  delegate :amount, :reference, :status, :success?, to: :payment_response

  def success
    if success?
      claim.create_payment amount: amount, reference: reference
      claim.create_event Event::PAYMENT_RECEIVED
    else
      # Barclaycard can still push requests to this end point even if there
      # is no guarantee the transaction was successful.
      claim.create_event Event::PAYMENT_UNCERTAIN, message: payment_uncertain_message
    end

    claim.enqueue!
    redirect_to claim_confirmation_path
  end

  def decline
    claim.create_event Event::PAYMENT_DECLINED
    flash[:alert] = t('.payment_declined')
    claim.increment! :payment_attempts
    redirect_to :action => :show
  end

  private

  def payment_response
    @payment_response ||= PaymentGateway::Response.new request
  end

  def validate_request
    # Don't give anything away to attackers poking at the system
    render nothing: true unless payment_response.valid?
  end

  def payment_uncertain_message
    I18n.t(status, scope: 'barclaycard_gateway.responses', default: :generic, status: status)
  end

  # We want to be able to process a payment even if the session expired
  def claim
    # Strip padding from FGR (FGRs are padded with an incrementing integer
    # when retrying failed transactions)
    @claim ||= begin
      if params['orderID'].present?
        Claim.find_by fee_group_reference: params['orderID'].sub(/\-\d+\Z/, '')
      else
        super
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06750861079219288, 'fraction_numerical': 0.002296211251435132, 'mean_word_length': 3.888888888888889, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3383903', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1237, 'n_words': 364}