<commit_before>module KlarnaGateway
  # TODO: pull this out of the checkout controller
  module SessionController
    def self.included(base)
      # TODO: only on klarna_session (maybe even not there)
      base.skip_action_callback(:ensure_valid_state)
    end

    def klarna_session
      @order.state = "payment"

      if @order.klarna_session_expired?
        klarna_payment_method.provider.create_session(klarna_order(skip_personal_data: true).to_hash).tap do |response|
          @order.update_klarna_session(
            session_id: response.session_id,
            client_token: response.client_token
            ) if response.success?
        end
      else
        klarna_payment_method.provider.update_session(
          @order.klarna_session_id,
          klarna_order(skip_personal_data: true).to_hash
        ).tap do |response|
          @order.update_klarna_session_time() if response.success?
        end
      end

      render json: {token: @order.reload.klarna_client_token}
    end

    def order_status<commit_msg>Only skip ensure_valid_state on klarna* actions<commit_after>module KlarnaGateway
  # TODO: pull this out of the checkout controller
  module SessionController
    def self.included(base)
      base.skip_before_action(:ensure_valid_state, only: [:klarna_session, :order_status, :order_addresses])
    end

    def klarna_session
      @order.state = "payment"

      if @order.klarna_session_expired?
        klarna_payment_method.provider.create_session(klarna_order(skip_personal_data: true).to_hash).tap do |response|
          @order.update_klarna_session(
            session_id: response.session_id,
            client_token: response.client_token
            ) if response.success?
        end
      else
        klarna_payment_method.provider.update_session(
          @order.klarna_session_id,
          klarna_order(skip_personal_data: true).to_hash
        ).tap do |response|
          @order.update_klarna_session_time() if response.success?
        end
      end

      render json: {token: @order.reload.klarna_client_token}
    end

    def order_status
{'fraction_non_alphanumeric': 0.07210626185958255, 'fraction_numerical': 0.0, 'mean_word_length': 2.9128014842300556, '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': '7145415', 'n_tokens_mistral': 627, 'n_tokens_neox': 612, 'n_words': 124}