<commit_before>Spree::Gateway::BraintreeGateway.class_eval do
  def authorize_with_cse(money, creditcard, options = {})
    if creditcard.gateway_payment_profile_id && !creditcard.gateway_customer_profile_id && preferred_use_client_side_encryption
      payment_method = creditcard.gateway_payment_profile_id
      options[:payment_method_nonce] = true
      provider.authorize(money, payment_method, options)
    else
      authorize_without_cse(money, creditcard, options)
    end
  end

  def method_type
    if preferred_use_client_side_encryption
      'braintree'
    else
      super
    end
  end

  def options_for_payment_with_cse(p)
    if p.source.gateway_customer_profile_id.blank? && p.source.gateway_payment_profile_id.blank? && p.source.encrypted_data.present?
      options = options_for_payment_without_cse(p)
      options.merge!({ payment_method_nonce: p.source.encrypted_data })
    else
      options_for_payment_without_cse(p)
    end
  end

  unless method_defined? :options_for_payment_without_cse
    preference :use_client_side_encryption, :boolean
    alias_method_chain :authorize, :cse
    alias_method_chain :options_for_payment, :cse
  end
end<commit_msg>Refactor overrides to use prepend.<commit_after>Spree::Gateway::BraintreeGateway.class_eval do
  preference :use_client_side_encryption, :boolean

  module CSE
    def authorize money, creditcard, options = {}
      if creditcard.gateway_payment_profile_id && !creditcard.gateway_customer_profile_id && preferred_use_client_side_encryption
        payment_method = creditcard.gateway_payment_profile_id
        options[:payment_method_nonce] = true
        provider.authorize money, payment_method, options
      else
        super
      end
    end

    def method_type
      if preferred_use_client_side_encryption
        'braintree'
      else
        super
      end
    end

    def options_for_payment payment
      if payment.source.gateway_customer_profile_id.blank? && payment.source.gateway_payment_profile_id.blank? && payment.source.encrypted_data.present?
        super.merge payment_method_nonce: payment.source.encrypted_data
      else
        super
      end
    end
  end
  prepend CSE
end
{'fraction_non_alphanumeric': 0.06241457858769932, 'fraction_numerical': 0.0, 'mean_word_length': 3.9237668161434978, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4260322', 'n_tokens_mistral': 686, 'n_tokens_neox': 679, 'n_words': 119}