Class: Sepa::DirectDebitOrder::CreditorPayment
- Inherits:
-
Object
- Object
- Sepa::DirectDebitOrder::CreditorPayment
- Defined in:
- lib/sepa/direct_debit_order.rb
Instance Attribute Summary collapse
-
#collection_date ⇒ Object
Returns the value of attribute collection_date.
-
#creditor ⇒ Object
Returns the value of attribute creditor.
-
#creditor_account ⇒ Object
Returns the value of attribute creditor_account.
-
#direct_debits ⇒ Object
Returns the value of attribute direct_debits.
-
#id ⇒ Object
Returns the value of attribute id.
-
#sepa_identification ⇒ Object
Returns the value of attribute sepa_identification.
-
#sequence_type ⇒ Object
Returns the value of attribute sequence_type.
Instance Method Summary collapse
-
#collect_by_sequence_type ⇒ Object
This is only called for V02, in which case SequenceType is mandatory.
- #control_sum ⇒ Object
-
#initialize(creditor, creditor_account, id, collection_date, sepa_identification, direct_debits) ⇒ CreditorPayment
constructor
A new instance of CreditorPayment.
- #number_of_transactions ⇒ Object
- #to_properties(prefix, opts) ⇒ Object
Constructor Details
#initialize(creditor, creditor_account, id, collection_date, sepa_identification, direct_debits) ⇒ CreditorPayment
Returns a new instance of CreditorPayment.
163 164 165 166 167 |
# File 'lib/sepa/direct_debit_order.rb', line 163 def initialize creditor, creditor_account, id, collection_date, sepa_identification, direct_debits @creditor, @creditor_account = creditor, creditor_account @id, @collection_date, @sepa_identification = id, collection_date, sepa_identification @direct_debits = direct_debits end |
Instance Attribute Details
#collection_date ⇒ Object
Returns the value of attribute collection_date.
160 161 162 |
# File 'lib/sepa/direct_debit_order.rb', line 160 def collection_date @collection_date end |
#creditor ⇒ Object
Returns the value of attribute creditor.
160 161 162 |
# File 'lib/sepa/direct_debit_order.rb', line 160 def creditor @creditor end |
#creditor_account ⇒ Object
Returns the value of attribute creditor_account.
160 161 162 |
# File 'lib/sepa/direct_debit_order.rb', line 160 def creditor_account @creditor_account end |
#direct_debits ⇒ Object
Returns the value of attribute direct_debits.
161 162 163 |
# File 'lib/sepa/direct_debit_order.rb', line 161 def direct_debits @direct_debits end |
#id ⇒ Object
Returns the value of attribute id.
160 161 162 |
# File 'lib/sepa/direct_debit_order.rb', line 160 def id @id end |
#sepa_identification ⇒ Object
Returns the value of attribute sepa_identification.
160 161 162 |
# File 'lib/sepa/direct_debit_order.rb', line 160 def sepa_identification @sepa_identification end |
#sequence_type ⇒ Object
Returns the value of attribute sequence_type.
161 162 163 |
# File 'lib/sepa/direct_debit_order.rb', line 161 def sequence_type @sequence_type end |
Instance Method Details
#collect_by_sequence_type ⇒ Object
This is only called for V02, in which case SequenceType is mandatory. Necessary because each PaymentInformation container contains a single SequenceType element (inside PaymentTypeInformation) whereas in V04, there is one SequenceType element per DirectDebitTransactionInformation
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/sepa/direct_debit_order.rb', line 172 def collect_by_sequence_type seq_types = { "FRST" => [], "RCUR" => [], "FNAL" => [], "OOFF" => [] } direct_debits.each do |dd| seq_types[dd.sequence_type] << dd end %w{FRST RCUR FNAL OOFF}.each do |seq_type| dds = seq_types[seq_type] next if dds.empty? ncp = CreditorPayment.new(creditor, creditor_account, "#{id}-#{seq_type}", collection_date, sepa_identification, dds) ncp.sequence_type = seq_type yield ncp end end |
#control_sum ⇒ Object
197 198 199 |
# File 'lib/sepa/direct_debit_order.rb', line 197 def control_sum direct_debits.inject(0) { |sum, dd| sum + dd.amount } end |
#number_of_transactions ⇒ Object
193 194 195 |
# File 'lib/sepa/direct_debit_order.rb', line 193 def number_of_transactions direct_debits.length end |
#to_properties(prefix, opts) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/sepa/direct_debit_order.rb', line 201 def to_properties prefix, opts hsh = { "#{prefix}.payment_information_identification" => id, "#{prefix}.payment_type_information.service_level.code" => "SEPA", "#{prefix}.payment_type_information.local_instrument.code" => "CORE", "#{prefix}.payment_method" => "DD", "#{prefix}.requested_collection_date" => collection_date, "#{prefix}.number_of_transactions" => number_of_transactions, "#{prefix}.control_sum" => control_sum, "#{prefix}.charge_bearer" => "SLEV" } if opts[:pain_008_001_version] == "02" hsh["#{prefix}.payment_type_information.sequence_type"] = sequence_type end hsh = hsh.merge creditor.to_properties("#{prefix}.creditor", opts.merge({ :context => :creditor })) hsh = hsh.merge creditor_account.to_properties("#{prefix}.creditor", opts) hsh = hsh.merge sepa_identification.to_properties("#{prefix}.creditor_scheme_identification", opts) direct_debits.each_with_index { |dd, j| hsh = hsh.merge(dd.to_properties("#{prefix}.direct_debit_transaction_information[#{j}]", opts)) } hsh end |