Sha256: e338ed6ea6656a5c6ca35dbee6c5ff134501463fd8732dac1b7f59843afc951b

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

# encoding: utf-8
module SEPA
  class DirectDebitTransaction < Transaction
    SEQUENCE_TYPES = %w(FRST OOFF RCUR FNAL)
    LOCAL_INSTRUMENTS = %w(CORE COR1 B2B)

    attr_accessor :mandate_id, :mandate_date_of_signature, :local_instrument, :sequence_type, :creditor_account

    validates_with MandateIdentifierValidator, field_name: :mandate_id
    validates_presence_of :mandate_date_of_signature
    validates_inclusion_of :local_instrument, in: LOCAL_INSTRUMENTS
    validates_inclusion_of :sequence_type, in: SEQUENCE_TYPES

    validate do |t|
      if creditor_account
        errors.add(:creditor_account, 'is not correct') unless creditor_account.valid?
      end

      if t.mandate_date_of_signature.is_a?(Date)
        errors.add(:mandate_date_of_signature, 'is in the future') if t.mandate_date_of_signature > Date.today
      else
        errors.add(:mandate_date_of_signature, 'is not a Date')
      end

      if t.requested_date.is_a?(Date)
        errors.add(:requested_date, 'is not in the future') if t.requested_date <= Date.today
      end
    end

    def initialize(attributes = {})
      super
      self.local_instrument ||= 'CORE'
      self.sequence_type ||= 'OOFF'
    end

    def schema_compatible?(schema_name)
      case schema_name
      when PAIN_008_002_02
        self.bic.present? && %w(CORE B2B).include?(self.local_instrument)
      when PAIN_008_003_02
        true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sepa_king-0.2.0 lib/sepa_king/transaction/direct_debit_transaction.rb