37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/absa-notify-me/xml_statement.rb', line 37
def self.string_to_hash(string)
hash = {type: 'document', data: {type: 'notifyme_account', data: []}}
Nori.parser = :nokogiri
xml_doc = Nori.parse(string)
converted_xml_doc = self.convert_hash(xml_doc)
converted_xml_doc.each do |k,v|
v.each do |key, value|
if key == :notif_header
hash[:data][:data] << {
type: 'header',
data: {
daily_no: value[:daily_no],
client_code: value[:client_id],
client_name: value[:sname],
processing_date: value[:creation_date],
processing_time: value[:creation_time],
buss_dir_code: value[:buss_dir_code]
}
}
end
if (key == :details) && (!value.blank?)
transactions = value[:transaction].blank? ? value["TRANSACTION"] : value[:transaction]
transactions = [transactions] if transactions.is_a? Hash
transactions.each do |transaction|
amount = (transaction[:amt].to_f * 100).to_i.to_s
account_balance = (transaction[:acc_bal].to_f * 100).to_i.to_s
hash[:data][:data] << {
type: "detail",
data: {
account_number: transaction[:trg_acc].to_i.to_s,
event_number: transaction[:event_no].to_i.to_s,
customer_reference: transaction[:clref],
currency: transaction[:curr],
amount: amount,
account_balance_after_transaction: account_balance,
transaction_type: transaction[:tran_type],
transaction_processing_date: transaction[:pdate],
clearance_payment_indicator: transaction[:clr_paym_ind],
transaction_description: transaction[:paym_desc],
checksum: transaction[:checksum]
}
}
end
end
if key == :notif_trailer
total_credit = (value[:total_cr].to_f * 100).to_i.to_s
total_debit = (value[:total_dt].to_f * 100).to_i.to_s
hash[:data][:data] << {
type: "trailer",
data: {
total_credit: total_credit,
total_debit: total_debit,
total_recs: value[:total_recs],
check_sum: value[:check_sum]
}
}
end
end
end
hash
end
|