class Sepa::DirectDebitOrder::CreditorPayment

Attributes

collection_date[RW]
creditor[RW]
creditor_account[RW]
direct_debits[RW]
id[RW]
sepa_identification[RW]
sequence_type[RW]

Public Class Methods

new(creditor, creditor_account, id, collection_date, sepa_identification, direct_debits) click to toggle source
# File lib/sepa/direct_debit_order.rb, line 162
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

Public Instance Methods

collect_by_sequence_type() { |ncp| ... } click to toggle source

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

# File lib/sepa/direct_debit_order.rb, line 171
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() click to toggle source
# File lib/sepa/direct_debit_order.rb, line 196
def control_sum
  direct_debits.inject(0) { |sum, dd| sum + dd.amount }
end
number_of_transactions() click to toggle source
# File lib/sepa/direct_debit_order.rb, line 192
def number_of_transactions
  direct_debits.length
end
to_properties(prefix, opts) click to toggle source
# File lib/sepa/direct_debit_order.rb, line 200
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