class Sepa::DirectDebitOrder::Order

Attributes

creditor_payments[RW]
initiating_party[RW]
message_id[RW]

Public Class Methods

new(message_id, initiating_party, creditor_payments) click to toggle source
# File lib/sepa/direct_debit_order.rb, line 42
def initialize message_id, initiating_party, creditor_payments
  @message_id, @initiating_party, @creditor_payments = message_id, initiating_party, creditor_payments
end

Public Instance Methods

new_payment() click to toggle source
# File lib/sepa/direct_debit_order.rb, line 46
def new_payment
  self.creditor_payments ||= []
  cp = CreditorPayment.new
  cp.id              = props[:payment_identification]
  cp.collection_date = props[:collection_date]
  p   =  cp.creditor = Party.new
  p.name             = props[:name]
  p.address_line_1   = props[:address_1]
  p.address_line_2   = props[:address_2]
  p.postcode         = props[:postcode]
  p.town             = props[:town]
  p.country          = props[:country]
  p.contact_name     = props[:contact]
  p.contact_phone    = props[:phone]
  p.contact_email    = props[:email]

  a       = cp.creditor_account = BankAccount.new
  a.iban  = props[:iban]
  a.swift = props[:bic]

  sepa_id = if props[:sepa_identifier][:private]
              PrivateSepaIdentifier.new(props[:sepa_identifier][:private])
            else
              OrganisationSepaIdentifier.new(props[:sepa_identifier][:organisation])
            end

  cp.sepa_identification = sepa_id

  self.creditor_payments << cp
  cp
end
to_properties(opts) click to toggle source
# File lib/sepa/direct_debit_order.rb, line 78
def to_properties opts
  hsh = {
    "group_header.message_identification"  => message_id,
    "group_header.creation_date_time"      => Time.now,
    "group_header.number_of_transactions"  => creditor_payments.inject(0) { |sum, cp| sum + cp.number_of_transactions },
    "group_header.control_sum"             => creditor_payments.inject(0) { |sum, cp| sum + cp.control_sum            },
  }

  hsh = hsh.merge initiating_party.to_properties("group_header.initiating_party", opts.merge({:context => :initiating_party}))

  cps = []
  if opts[:pain_008_001_version] == "02"
    creditor_payments.each do |creditor_payment|
      creditor_payment.collect_by_sequence_type { |cp| cps << cp }
    end
  else
    cps = creditor_payments
  end

  cps.each_with_index { |cp, i|
    hsh = hsh.merge(cp.to_properties("payment_information[#{i}]", opts))
  }

  hsh
end
to_xml(opts={ }) click to toggle source
# File lib/sepa/direct_debit_order.rb, line 104
def to_xml opts={ }
  Sepa::PaymentsInitiation::Pain00800104::CustomerDirectDebitInitiation.new(to_properties opts).generate_xml(opts)
end