<commit_before>module Spree
  class Gateway
    class KlarnaCredit < Gateway
      preference :api_key, :string
      preference :api_secret, :string
      preference :country, :string, default: 'us'

      preference :design, :string
      preference :color_details, :string
      preference :color_button, :string
      preference :color_button_text, :string
      preference :color_checkbox, :string
      preference :color_checkbox_checkmark, :string
      preference :color_header, :string
      preference :color_link, :string
      preference :color_border, :string
      preference :color_border_selected, :string
      preference :color_text, :string
      preference :color_text_secondary, :string
      preference :radius_border, :string

      # Remove the server setting from Gateway
      def defined_preferences
        super - [:server]
      end

      def provider_class
        ActiveMerchant::Billing::KlarnaGateway
      end

      def method_type
        'klarna_credit'
      end

      def payment_source_class
        Spree::KlarnaCreditPayment
      end

      def source_required?
        true
      end

      def credit_card?
        false
      end

      def cancel(order_id)
        if source(order_id).fully_captured?
          provider.refund(payment_amount(order_id), order_id)
        else
          provider.cancel(order_id)
        end
      end

      def payment_profiles_supported?
        false
      end

      def source(order_id)
        payment_source_class.find_by_order_id(order_id)
      end

      def payment_amount(order_id)
        Spree::Payment.find_by(source: source(order_id)).display_amount.cents
      end

      def capture(amount, order_id, options={})
        order = spree_order(options)
        serialized_order = ::KlarnaGateway::OrderSerializer.new(order, preferences[:country]).to_hash
        klarna_options = {shipping_info: serialized_order[:shipping_info]}
        provider.capture(amount, order_id, options.merge(klarna_options))
      end

      private
<commit_msg>Remove reference to `preferences` to allow static settings<commit_after>module Spree
  class Gateway
    class KlarnaCredit < Gateway
      preference :api_key, :string
      preference :api_secret, :string
      preference :country, :string, default: 'us'

      preference :design, :string
      preference :color_details, :string
      preference :color_button, :string
      preference :color_button_text, :string
      preference :color_checkbox, :string
      preference :color_checkbox_checkmark, :string
      preference :color_header, :string
      preference :color_link, :string
      preference :color_border, :string
      preference :color_border_selected, :string
      preference :color_text, :string
      preference :color_text_secondary, :string
      preference :radius_border, :string

      # Remove the server setting from Gateway
      def defined_preferences
        super - [:server]
      end

      def provider_class
        ActiveMerchant::Billing::KlarnaGateway
      end

      def method_type
        'klarna_credit'
      end

      def payment_source_class
        Spree::KlarnaCreditPayment
      end

      def source_required?
        true
      end

      def credit_card?
        false
      end

      def cancel(order_id)
        if source(order_id).fully_captured?
          provider.refund(payment_amount(order_id), order_id)
        else
          provider.cancel(order_id)
        end
      end

      def payment_profiles_supported?
        false
      end

      def source(order_id)
        payment_source_class.find_by_order_id(order_id)
      end

      def payment_amount(order_id)
        Spree::Payment.find_by(source: source(order_id)).display_amount.cents
      end

      def capture(amount, order_id, options={})
        order = spree_order(options)
        serialized_order = ::KlarnaGateway::OrderSerializer.new(order, options[:country]).to_hash
        klarna_options = {shipping_info: serialized_order[:shipping_info]}
        provider.capture(amount, order_id, options.merge(klarna_options))
      end

      private

{'fraction_non_alphanumeric': 0.06943432872056324, 'fraction_numerical': 0.0, 'mean_word_length': 2.6983842010771992, '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': '4727155', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1152, 'n_words': 263}