<commit_before>require "servipag/version"
require "base64"
require "openssl"
require 'validator'
require 'servipag_configuration'
require 'generator_helper'
require 'crypt_decrypt'
require 'parser'
require 'rest_client'

module Servipag

  include ServipagConfiguration
  include Validator
  include CryptDecrypt
  module ApiRequests
  	class TransactionBegginer < ServipagConfiguration::Configuration
      attr_accessor :eps, 
                    :payment_channel_id, 
                    :id_tx_client, 
                    :payment_date, 
                    :total_amount, 
                    :bill_counter, 
                    :id_sub_trx, 
                    :identifier_code, 
                    :bill, 
                    :amount, 
                    :expiration_date
      
  		def initialize(attrs={})
        super unless defined? @@settings
        @payment_channel_id =  @@settings['payment_channel_id']
        @id_tx_client       =  GeneratorHelper::TokenGenerator.generate_token
        @payment_date       =  GeneratorHelper::DateGenerator.generate_payment_date
        @total_amount       =  Validator.validate_total_amount_length(attrs[:total_amount])
        @bill_counter       =  attrs[:bill_counter].to_i > 0 ? attrs[:bill_counter].to_i : 1
        @id_sub_trx         =  attrs[:id_sub_trx].to_i   > 0 ? attrs[:id_sub_trx].to_i   : 1
        @identifier_code    =  GeneratorHelper::TokenGenerator.generate_numeric_token
        @bill               =  GeneratorHelper::TokenGenerator.generate_numeric_random_token
        @amount             =  @total_amount
        @expiration_date    =  GeneratorHelper::DateGenerator.generate_payment_date  
        @eps                =  CryptDecrypt::Encrypt.encrypt_using_public_key(@@settings['public_key_path'], concatenated_strings).gsub("\n",'')
      end

      def create_request
        RestClient.post(@@settings['servipag_url'], 
                        GeneratorHelper::XML::Xml1.generate_xml(attrs_hash), 
                        content_type: :xml)
      end

      def concatenated_strings
        [ @payment_channel_id,
            @id_tx_client,
            @payment_date,
            @total_amount,
            @bill_counter,
            @id_sub_trx,
            @identifier_code,
            @bill_counter,
            @amount,
            @expiration_date,<commit_msg>metodo para direccion de servipag<commit_after>require "servipag/version"
require "base64"
require "openssl"
require 'validator'
require 'servipag_configuration'
require 'generator_helper'
require 'crypt_decrypt'
require 'parser'
require 'rest_client'

module Servipag

  include ServipagConfiguration
  include Validator
  include CryptDecrypt
  module ApiRequests
  	class TransactionBegginer < ServipagConfiguration::Configuration
      attr_accessor :eps, 
                    :payment_channel_id, 
                    :id_tx_client, 
                    :payment_date, 
                    :total_amount, 
                    :bill_counter, 
                    :id_sub_trx, 
                    :identifier_code, 
                    :bill, 
                    :amount, 
                    :expiration_date
      
  		def initialize(attrs={})
        super unless defined? @@settings
        @payment_channel_id =  @@settings['payment_channel_id']
        @id_tx_client       =  GeneratorHelper::TokenGenerator.generate_token
        @payment_date       =  GeneratorHelper::DateGenerator.generate_payment_date
        @total_amount       =  Validator.validate_total_amount_length(attrs[:total_amount])
        @bill_counter       =  attrs[:bill_counter].to_i > 0 ? attrs[:bill_counter].to_i : 1
        @id_sub_trx         =  attrs[:id_sub_trx].to_i   > 0 ? attrs[:id_sub_trx].to_i   : 1
        @identifier_code    =  GeneratorHelper::TokenGenerator.generate_numeric_token
        @bill               =  GeneratorHelper::TokenGenerator.generate_numeric_random_token
        @amount             =  @total_amount
        @expiration_date    =  GeneratorHelper::DateGenerator.generate_payment_date  
        @eps                =  CryptDecrypt::Encrypt.encrypt_using_public_key(@@settings['public_key_path'], concatenated_strings).gsub("\n",'')
      end

      def create_request
        RestClient.post(@@settings['servipag_url'], 
                        GeneratorHelper::XML::Xml1.generate_xml(attrs_hash), 
                        content_type: :xml)
      end
      
      def servipag_url
        settings['servipag_url']
      end

      def concatenated_strings
        [ @payment_channel_id,
            @id_tx_client,
            @payment_date,
            @total_amount,
            @bill_counter,
            @id_sub_trx,
            @identifier_code,
            @bill_counter,
            @amount,
            @expiration_date,
{'fraction_non_alphanumeric': 0.07911721840516343, 'fraction_numerical': 0.0029148448886112846, 'mean_word_length': 2.071611253196931, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5726095', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1302, 'n_words': 203}