Class: SEPA::Builders::CreditTransfer::Transaction::TxnInstructionForDebtorAgent

Inherits:
Stage
  • Object
show all
Defined in:
lib/sepa_rator/builders/credit_transfer/transaction/txn_instruction_for_debtor_agent.rb

Overview

Transaction-level InstrForDbtrAgt. Serialized as plain text in older schemas and as a structured InstrInf block in pain.001.001.13.

Instance Method Summary collapse

Methods inherited from Stage

call, #initialize

Constructor Details

This class inherits a constructor from SEPA::Builders::Stage

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sepa_rator/builders/credit_transfer/transaction/txn_instruction_for_debtor_agent.rb', line 10

def call
  return unless profile.supports?(:txn_instruction_for_debtor_agent)
  return unless transaction.instruction_for_debtor_agent || transaction.instruction_for_debtor_agent_code

  case profile.features.instr_for_dbtr_agt_format
  when :structured
    builder.InstrForDbtrAgt do
      builder.Cd(transaction.instruction_for_debtor_agent_code) if transaction.instruction_for_debtor_agent_code
      builder.InstrInf(transaction.instruction_for_debtor_agent) if transaction.instruction_for_debtor_agent
    end
  when :text
    # `instruction_for_debtor_agent_code` is rejected upstream by
    # `CreditTransferTransaction#instr_for_dbtr_agt_code_compatible?`
    # when the profile uses :text format, so a bare code without
    # text is unreachable here.
    builder.InstrForDbtrAgt(transaction.instruction_for_debtor_agent) if transaction.instruction_for_debtor_agent
  else
    raise ArgumentError,
          "Unknown instr_for_dbtr_agt_format: #{profile.features.instr_for_dbtr_agt_format.inspect}"
  end
end