Class: Sepa::DirectDebitOrder::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/sepa/direct_debit_order.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_id, initiating_party, creditor_payments) ⇒ Order

Returns a new instance of Order.



10
11
12
# File 'lib/sepa/direct_debit_order.rb', line 10

def initialize message_id, initiating_party, creditor_payments
  @message_id, @initiating_party, @creditor_payments = message_id, initiating_party, creditor_payments
end

Instance Attribute Details

#creditor_paymentsObject

Returns the value of attribute creditor_payments.



8
9
10
# File 'lib/sepa/direct_debit_order.rb', line 8

def creditor_payments
  @creditor_payments
end

#initiating_partyObject

Returns the value of attribute initiating_party.



8
9
10
# File 'lib/sepa/direct_debit_order.rb', line 8

def initiating_party
  @initiating_party
end

#message_idObject

Returns the value of attribute message_id.



8
9
10
# File 'lib/sepa/direct_debit_order.rb', line 8

def message_id
  @message_id
end

Instance Method Details

#to_propertiesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sepa/direct_debit_order.rb', line 14

def to_properties
  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 },
  }

  hsh = hsh.merge initiating_party.to_properties("group_header.initiating_party")

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

  hsh
end

#to_xmlObject



30
31
32
# File 'lib/sepa/direct_debit_order.rb', line 30

def to_xml
  Sepa::PaymentsInitiation::Pain00800104::CustomerDirectDebitInitiation.new(to_properties).generate_xml
end