<commit_before>module Alfabank::Api
  class Status < Base
    TEST_URL = "https://test.paymentgate.ru/testpayment/rest/getOrderStatus.do"
    URL = "https://engine.paymentgate.ru/payment/rest/getOrderStatus.do"
    PAID = 2

    def process
      response = make_request.parsed_response
      process_response(response)

      {
        order_status: response["OrderStatus"].to_i,
        binding_id: response["bindingId"],
        card_number: response["Pan"],
        error_code: response["ErrorCode"].to_i,
        error_message: response["ErrorMessage"]
      }
    rescue => e
      Alfabank.logger.error e
      {error_message: 'Internal server error'}
    end

    private

    def process_response(response)
      if response["OrderStatus"].to_i == PAID
        payment.update_attribute(:paid, true)
      end
    end

    def generate_params
      {
        userName: Alfabank::Configuration.username,
        password: <PASSWORD>,
        orderId: payment.alfa_order_id
      }.map { |k, v| "#{k}=#{v}" }.join('&')
    end
  end
end<commit_msg>Set payment attributes after status check<commit_after>module Alfabank::Api
  class Status < Base
    TEST_URL = "https://test.paymentgate.ru/testpayment/rest/getOrderStatus.do"
    URL = "https://engine.paymentgate.ru/payment/rest/getOrderStatus.do"
    PAID = 2

    def process
      response = make_request.parsed_response
      process_response(response)

      {
        order_status: response["OrderStatus"].to_i,
        binding_id: response["bindingId"],
        card_number: response["Pan"],
        error_code: response["ErrorCode"].to_i,
        error_message: response["ErrorMessage"]
      }
    rescue => e
      Alfabank.logger.error e
      {error_message: 'Internal server error'}
    end

    private

    def process_response(response)
      return unless response["OrderStatus"].to_i == PAID

      payment.paid = true
      payment.binding_id = response["bindingId"] if payment.respond_to?(:binding_id)
      payment.card_number = response["Pan"] if payment.respond_to?(:card_number)
      payment.save(validate: false)
    end

    def generate_params
      {
        userName: Alfabank::Configuration.username,
        password: <PASSWORD>,
        orderId: payment.alfa_order_id
      }.map { |k, v| "#{k}=#{v}" }.join('&')
    end
  end
end
{'fraction_non_alphanumeric': 0.11767241379310345, 'fraction_numerical': 0.0008620689655172414, 'mean_word_length': 2.8618968386023296, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, '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': '3070822', 'n_tokens_mistral': 703, 'n_tokens_neox': 695, 'n_words': 136}