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

    def process
      return {url: payment.alfa_form_url} if payment.alfa_order_id

      process_response(make_request.parsed_response)
    rescue => e
      Alfabank.logger.error e
      {error: 'Internal server error'}
    end

    private

    def process_response(response)
      if response.has_key?("orderId")
        set_data_from_response(response)
        {url: payment.alfa_form_url}
      else
        {error: response['errorMessage']}
      end
    end

    def generate_params
      params = {
        userName: Alfabank::Configuration.username,
        password: <PASSWORD>,
        description: payment.description,
        language: Alfabank::Configuration.language,
        orderNumber: "#{Alfabank::Configuration.order_number_prefix}#{payment.id}",
        amount: payment.price * 100,
        currency: Alfabank::Configuration.currency,
        clientId: payment.user_id,
        returnUrl: Alfabank::Configuration.return_url
      }

      params.map { |k, v| "#{k}=#{v}" }.join('&')
    end

    def set_data_from_response(response)
      payment.update_attributes(
        alfa_order_id: response["orderId"],
        alfa_form_url: response["formUrl"]
      )
    end
  end
end<commit_msg>Registration: use to_order_number for payment params<commit_after>module Alfabank::Api
  class Registration < Base
    TEST_URL = "https://test.paymentgate.ru/testpayment/rest/register.do"
    URL = "https://engine.paymentgate.ru/payment/rest/register.do"

    def process
      return {url: payment.alfa_form_url} if payment.alfa_order_id

      process_response(make_request.parsed_response)
    rescue => e
      Alfabank.logger.error e
      {error: 'Internal server error'}
    end

    private

    def process_response(response)
      if response.has_key?("orderId")
        set_data_from_response(response)
        {url: payment.alfa_form_url}
      else
        {error: response['errorMessage']}
      end
    end

    def generate_params
      params = {
        userName: Alfabank::Configuration.username,
        password: <PASSWORD>,
        description: payment.description,
        language: Alfabank::Configuration.language,
        orderNumber: "#{Alfabank::Configuration.order_number_prefix}#{order_number}",
        amount: payment.price * 100,
        currency: Alfabank::Configuration.currency,
        clientId: payment.user_id,
        returnUrl: Alfabank::Configuration.return_url
      }

      params.map { |k, v| "#{k}=#{v}" }.join('&')
    end

    def set_data_from_response(response)
      payment.update_attributes(
        alfa_order_id: response["orderId"],
        alfa_form_url: response["formUrl"]
      )
    end

    def order_number
      payment.to_order_number || payment.id
    end
  end
end
{'fraction_non_alphanumeric': 0.10640460860725177, 'fraction_numerical': 0.0020332090816672314, 'mean_word_length': 2.9047619047619047, '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': '6697111', 'n_tokens_mistral': 898, 'n_tokens_neox': 882, 'n_words': 163}