Class: SEPA::Validators::MinAmount

Inherits:
Object
  • Object
show all
Defined in:
lib/sepa_rator/validators/min_amount.rb

Overview

Shared minimum-amount validator used by profiles that tighten the ISO baseline (e.g. DK GBIC5, AT PSA/Stuzza). The threshold comes from ‘profile.features.min_amount`; profiles that leave it `nil` are unaffected.

Class Method Summary collapse

Class Method Details

.validate(transaction, profile) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/sepa_rator/validators/min_amount.rb', line 10

def self.validate(transaction, profile)
  min = profile.features.min_amount
  return if min.nil?
  return if transaction.amount.nil? # caught upstream by validates_numericality_of
  return if transaction.amount >= min

  raise SEPA::ValidationError,
        "[#{profile.id}] amount #{format('%.2f', transaction.amount)} is below the " \
        "required minimum #{format('%.2f', min)}"
end