Class: Gateway::BoletoTransactionParser

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

Instance Method Summary collapse

Instance Method Details

#Parse(elements) ⇒ 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
# File 'lib/gateway/Parsers/boleto_transaction_parser.rb', line 4

def Parse(elements)
  @@DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'

  if elements.length < 18
    throw('The expected parameter count is 18')
  end

  boleto_transaction = BoletoTransactionReportFile.new
  boleto_transaction.Order.OrderKey = elements[1]
  boleto_transaction.Order.OrderReference = elements[2]
  boleto_transaction.Order.MerchantKey = elements[3]
  boleto_transaction.Order.MerchantName = elements[4]

  boleto_transaction.TransactionKey = elements[5]
  boleto_transaction.TransactionReference = elements[6]
  boleto_transaction.Status = elements[7]
  boleto_transaction.NossoNumero = elements[8]
  boleto_transaction.BankNumber = elements[9]
  boleto_transaction.Agency = elements[10]
  boleto_transaction.Account = elements[11]
  boleto_transaction.BarCode = elements[12]
  boleto_transaction.ExpirationDate = DateTime.strptime(elements[13], '%m/%d/%Y %H:%M:%S').strftime(@@DATETIME_FORMAT)
  boleto_transaction.AmountInCents = elements[14].to_i
  boleto_transaction.AmountPaidInCents = (elements[15].to_s == '') == false ? elements[15].to_i : 0
  boleto_transaction.PaymentDate = (elements[16].to_s == '') == false ? DateTime.strptime(elements[16], '%m/%d/%Y %H:%M:%S').strftime(@@DATETIME_FORMAT) : nil
  boleto_transaction.CreditDate = (elements[17].chomp.to_s == '') == false ? DateTime.strptime(elements[17], '%m/%d/%Y %H:%M:%S').strftime(@@DATETIME_FORMAT) : nil

  return boleto_transaction
end