Class: Gateway::TransactionReportFile

Inherits:
Object
  • Object
show all
Defined in:
lib/gateway/transaction_report_file.rb

Instance Method Summary collapse

Instance Method Details

#TransactionReportFileParser(file_to_parse) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gateway/transaction_report_file.rb', line 4

def TransactionReportFileParser(file_to_parse)
  response = {}
  response['CreditCardTransaction'] = []
  response['OnlineDebitTransaction'] = []
  response['BoletoTransaction'] = []

  header_parser = HeaderParser.new
  credit_card_parser = CreditCardTransactionParser.new
  boleto_parser = BoletoTransactionParser.new
  online_debit_parser = OnlineDebitTransactionParser.new
  trailer_parser = TrailerParser.new

  begin
    response_splited = file_to_parse.split("\n")

    response_splited.each do |item|

      to_parse_item = item.split(',')
      if to_parse_item[0] == '01'
        response['Header'] = header_parser.Parse(to_parse_item)
      end

      if to_parse_item[0] == '20'
        response['CreditCardTransaction'] << credit_card_parser.Parse(to_parse_item)
      end

      if to_parse_item[0] == '40'
        response['OnlineDebitTransaction'] << online_debit_parser.Parse(to_parse_item)
      end

      if to_parse_item[0] == '30'
        response['BoletoTransaction'] << boleto_parser.Parse(to_parse_item)
      end

      if to_parse_item[0] == '99'
        response['Trailer'] = trailer_parser.Parse(to_parse_item)
      end
    end
  rescue Exception => err
    return err
  end
  return response
end