Class: Sepa::DirectDebitOrder::Order
- Inherits:
-
Object
- Object
- Sepa::DirectDebitOrder::Order
- Defined in:
- lib/sepa/direct_debit_order.rb
Instance Attribute Summary collapse
-
#creditor_payments ⇒ Object
Returns the value of attribute creditor_payments.
-
#initiating_party ⇒ Object
Returns the value of attribute initiating_party.
-
#message_id ⇒ Object
Returns the value of attribute message_id.
Instance Method Summary collapse
-
#initialize(message_id, initiating_party, creditor_payments) ⇒ Order
constructor
A new instance of Order.
- #new_payment ⇒ Object
- #to_properties(opts) ⇒ Object
- #to_xml(opts = { }) ⇒ Object
Constructor Details
#initialize(message_id, initiating_party, creditor_payments) ⇒ Order
Returns a new instance of Order.
43 44 45 |
# File 'lib/sepa/direct_debit_order.rb', line 43 def initialize , initiating_party, creditor_payments @message_id, @initiating_party, @creditor_payments = , initiating_party, creditor_payments end |
Instance Attribute Details
#creditor_payments ⇒ Object
Returns the value of attribute creditor_payments.
41 42 43 |
# File 'lib/sepa/direct_debit_order.rb', line 41 def creditor_payments @creditor_payments end |
#initiating_party ⇒ Object
Returns the value of attribute initiating_party.
41 42 43 |
# File 'lib/sepa/direct_debit_order.rb', line 41 def initiating_party @initiating_party end |
#message_id ⇒ Object
Returns the value of attribute message_id.
41 42 43 |
# File 'lib/sepa/direct_debit_order.rb', line 41 def @message_id end |
Instance Method Details
#new_payment ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/sepa/direct_debit_order.rb', line 47 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) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/sepa/direct_debit_order.rb', line 79 def to_properties opts hsh = { "group_header.message_identification" => , "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 = { }) ⇒ Object
105 106 107 |
# File 'lib/sepa/direct_debit_order.rb', line 105 def to_xml opts={ } Sepa::PaymentsInitiation::Pain00800104::CustomerDirectDebitInitiation.new(to_properties opts).generate_xml(opts) end |