Class: Cmxl::Fields::Transaction
Constant Summary
Constants inherited
from Cmxl::Field
Cmxl::Field::DATE
Instance Attribute Summary collapse
Attributes inherited from Cmxl::Field
#data, #match, #modifier, #source, #tag
Instance Method Summary
collapse
Methods inherited from Cmxl::Field
#initialize, #method_missing, parse, parsers, #to_amount, #to_amount_in_cents, #to_date
Constructor Details
This class inherits a constructor from Cmxl::Field
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Cmxl::Field
Instance Attribute Details
#details ⇒ Object
Returns the value of attribute details.
7
8
9
|
# File 'lib/cmxl/fields/transaction.rb', line 7
def details
@details
end
|
Instance Method Details
9
10
11
|
# File 'lib/cmxl/fields/transaction.rb', line 9
def add_meta_data(content)
self.details = Cmxl::Fields::StatementDetails.parse(content) unless content.nil?
end
|
#amount ⇒ Object
81
82
83
|
# File 'lib/cmxl/fields/transaction.rb', line 81
def amount
to_amount(data['amount'])
end
|
#amount_in_cents ⇒ Object
85
86
87
|
# File 'lib/cmxl/fields/transaction.rb', line 85
def amount_in_cents
to_amount_in_cents(data['amount'])
end
|
#bic ⇒ Object
141
142
143
|
# File 'lib/cmxl/fields/transaction.rb', line 141
def bic
details.bic if details
end
|
#charges_currency ⇒ Object
127
128
129
|
# File 'lib/cmxl/fields/transaction.rb', line 127
def charges_currency
supplementary.charges_currency
end
|
#charges_in_cents ⇒ Object
123
124
125
|
# File 'lib/cmxl/fields/transaction.rb', line 123
def charges_in_cents
supplementary.charges_in_cents
end
|
#credit? ⇒ Boolean
17
18
19
|
# File 'lib/cmxl/fields/transaction.rb', line 17
def credit?
credit_debit_indicator.include?('C')
end
|
#credit_debit_indicator ⇒ Object
64
65
66
|
# File 'lib/cmxl/fields/transaction.rb', line 64
def credit_debit_indicator
data['credit_debit_indicator'].to_s
end
|
#date ⇒ Object
89
90
91
|
# File 'lib/cmxl/fields/transaction.rb', line 89
def date
to_date(data['date'])
end
|
#debit? ⇒ Boolean
21
22
23
|
# File 'lib/cmxl/fields/transaction.rb', line 21
def debit?
credit_debit_indicator.include?('D')
end
|
#description ⇒ Object
133
134
135
|
# File 'lib/cmxl/fields/transaction.rb', line 133
def description
details.description if details
end
|
#entry_date ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/cmxl/fields/transaction.rb', line 93
def entry_date
return if !date || !data['entry_date']
e_date = to_date(data['entry_date'], date.year)
e_date = to_date(data['entry_date'], date.year - 1) if date.month == 1 && e_date.month == 12
e_date = to_date(data['entry_date'], date.year + 1) if date.month == 12 && e_date.month == 1
e_date
end
|
#expected? ⇒ Boolean
60
61
62
|
# File 'lib/cmxl/fields/transaction.rb', line 60
def expected?
credit_debit_indicator.include?('E')
end
|
#expected_credit? ⇒ Boolean
52
53
54
|
# File 'lib/cmxl/fields/transaction.rb', line 52
def expected_credit?
credit? && expected?
end
|
#expected_debit? ⇒ Boolean
56
57
58
|
# File 'lib/cmxl/fields/transaction.rb', line 56
def expected_debit?
debit? && expected?
end
|
#funds_code ⇒ Object
68
69
70
71
|
# File 'lib/cmxl/fields/transaction.rb', line 68
def funds_code
warn "[DEPRECATION] `funds_code` is deprecated. Please use `credit_debit_indicator` instead. It will be removed in version 3.0."
data['credit_debit_indicator'].to_s
end
|
#iban ⇒ Object
149
150
151
|
# File 'lib/cmxl/fields/transaction.rb', line 149
def iban
details.iban if details
end
|
137
138
139
|
# File 'lib/cmxl/fields/transaction.rb', line 137
def information
details.information if details
end
|
#initial_amount_in_cents ⇒ Object
Fields from supplementary
115
116
117
|
# File 'lib/cmxl/fields/transaction.rb', line 115
def initial_amount_in_cents
supplementary.initial_amount_in_cents
end
|
#initial_currency ⇒ Object
119
120
121
|
# File 'lib/cmxl/fields/transaction.rb', line 119
def initial_currency
supplementary.initial_currency
end
|
#name ⇒ Object
145
146
147
|
# File 'lib/cmxl/fields/transaction.rb', line 145
def name
details.name if details
end
|
#primanota ⇒ Object
161
162
163
|
# File 'lib/cmxl/fields/transaction.rb', line 161
def primanota
details.primanota if details
end
|
#reversal? ⇒ Boolean
48
49
50
|
# File 'lib/cmxl/fields/transaction.rb', line 48
def reversal?
credit_debit_indicator.include?('R')
end
|
#reversal_credit? ⇒ Boolean
30
31
32
|
# File 'lib/cmxl/fields/transaction.rb', line 30
def reversal_credit?
credit? && storno?
end
|
#reversal_debit? ⇒ Boolean
39
40
41
|
# File 'lib/cmxl/fields/transaction.rb', line 39
def reversal_debit?
debit? && storno?
end
|
#sepa ⇒ Object
153
154
155
|
# File 'lib/cmxl/fields/transaction.rb', line 153
def sepa
details.sepa if details
end
|
#sha ⇒ Object
13
14
15
|
# File 'lib/cmxl/fields/transaction.rb', line 13
def sha
Digest::SHA2.new.update(source).to_s
end
|
#sign ⇒ Object
77
78
79
|
# File 'lib/cmxl/fields/transaction.rb', line 77
def sign
credit? ? 1 : -1
end
|
#storno? ⇒ Boolean
43
44
45
46
|
# File 'lib/cmxl/fields/transaction.rb', line 43
def storno?
warn "[DEPRECATION] `storno?` is deprecated. Please use `reversal?` instead. It will be removed in version 3.0."
reversal?
end
|
#storno_credit? ⇒ Boolean
25
26
27
28
|
# File 'lib/cmxl/fields/transaction.rb', line 25
def storno_credit?
warn "[DEPRECATION] `storno_credit?` is deprecated. Please use `reversal_credit?` instead. It will be removed in version 3.0."
reversal_credit?
end
|
#storno_debit? ⇒ Boolean
34
35
36
37
|
# File 'lib/cmxl/fields/transaction.rb', line 34
def storno_debit?
warn "[DEPRECATION] `storno_debit?` is deprecated. Please use `reversal_debit?` instead. It will be removed in version 3.0."
reversal_debit?
end
|
#storno_flag ⇒ Object
73
74
75
|
# File 'lib/cmxl/fields/transaction.rb', line 73
def storno_flag
reversal? ? 'R' : ''
end
|
#sub_fields ⇒ Object
157
158
159
|
# File 'lib/cmxl/fields/transaction.rb', line 157
def sub_fields
details.sub_fields if details
end
|
#to_h ⇒ Object
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/cmxl/fields/transaction.rb', line 165
def to_h
{
'sha' => sha,
'date' => date,
'entry_date' => entry_date,
'amount' => amount,
'amount_in_cents' => amount_in_cents,
'sign' => sign,
'debit' => debit?,
'credit' => credit?,
'storno' => reversal?,
'reversal' => reversal?,
'expected' => expected?,
'funds_code' => credit_debit_indicator,
'credit_debit_indicator' => credit_debit_indicator,
'swift_code' => swift_code,
'reference' => reference,
'bank_reference' => bank_reference,
'currency_letter' => currency_letter
}.tap do |h|
h.merge!(details.to_h) if details
h.merge!(supplementary.to_h) if supplementary.source
end
end
|
#to_hash ⇒ Object
190
191
192
|
# File 'lib/cmxl/fields/transaction.rb', line 190
def to_hash
to_h
end
|
#to_json(*args) ⇒ Object
194
195
196
|
# File 'lib/cmxl/fields/transaction.rb', line 194
def to_json(*args)
to_h.to_json(*args)
end
|