sepa_rator 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/sepa_rator/account/address.rb +4 -0
- data/lib/sepa_rator/account/creditor_account.rb +8 -1
- data/lib/sepa_rator/account/debtor_account.rb +6 -1
- data/lib/sepa_rator/account.rb +8 -3
- data/lib/sepa_rator/builders/credit_transfer/group_header.rb +2 -10
- data/lib/sepa_rator/builders/credit_transfer/payment_information.rb +0 -1
- data/lib/sepa_rator/builders/credit_transfer/transaction/credit_transfer_mandate.rb +0 -2
- data/lib/sepa_rator/builders/credit_transfer/transaction/instructions_for_creditor_agent.rb +0 -4
- data/lib/sepa_rator/builders/credit_transfer/transaction/regulatory_reporting.rb +0 -1
- data/lib/sepa_rator/builders/credit_transfer/transaction/txn_instruction_for_debtor_agent.rb +0 -1
- data/lib/sepa_rator/builders/direct_debit/group_header.rb +1 -5
- data/lib/sepa_rator/concerns/capability_requirements.rb +34 -0
- data/lib/sepa_rator/concerns/schema_validation.rb +7 -1
- data/lib/sepa_rator/concerns/xml_builder.rb +16 -8
- data/lib/sepa_rator/message.rb +35 -44
- data/lib/sepa_rator/profile.rb +10 -8
- data/lib/sepa_rator/profiles/at.rb +17 -26
- data/lib/sepa_rator/profiles/dk.rb +10 -11
- data/lib/sepa_rator/profiles/iso.rb +10 -6
- data/lib/sepa_rator/profiles/sps.rb +3 -1
- data/lib/sepa_rator/transaction/credit_transfer_transaction.rb +15 -22
- data/lib/sepa_rator/transaction/direct_debit_transaction.rb +6 -13
- data/lib/sepa_rator/transaction.rb +6 -9
- data/lib/sepa_rator/version.rb +1 -1
- data/lib/sepa_rator.rb +4 -0
- metadata +22 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9e8a4ee1486cf8090a20083f2d9718d5f3f30bb8cc683059c9addf91b94115da
|
|
4
|
+
data.tar.gz: 3885c0f30ef91907a283cde8a83ef6bbef15d8a630c6085831b2d74d4f496f3c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6f648c876775b4e29da46a1279339315332bfb04360c8d23f1408091f9686cc3085bbe2f3f78392c34187b9ab45756cdbea35c85f28e6530a45a56781cb24274
|
|
7
|
+
data.tar.gz: 5c57461fa97002b7fea78bbf0d0ad9338cb5ccc07fcde2335ef2c44b20b62ea1add90e699d5a004bc4ca88eae209a4f1daa931cabf79b63d7ca7cfbadfd3e1a3
|
data/README.md
CHANGED
|
@@ -35,7 +35,7 @@ For the full per-profile detail (XSD, constraints, capabilities), see [DOCUMENTA
|
|
|
35
35
|
## Requirements
|
|
36
36
|
|
|
37
37
|
- Ruby 3.2+ (tested up to 4.0)
|
|
38
|
-
- ActiveModel 7.0+ (tested up to 8.1)
|
|
38
|
+
- ActiveModel and ActiveSupport 7.0+ (tested up to 8.1)
|
|
39
39
|
|
|
40
40
|
## Installation
|
|
41
41
|
|
|
@@ -78,5 +78,9 @@ module SEPA
|
|
|
78
78
|
def uses_address_lines?
|
|
79
79
|
!address_line1.nil? || !address_line2.nil?
|
|
80
80
|
end
|
|
81
|
+
|
|
82
|
+
ELEMENT_FIELDS = (XmlBuilder::POSTAL_ADDRESS_FIELDS.map(&:last) - %i[country_code address_line1 address_line2]).freeze
|
|
83
|
+
|
|
84
|
+
def lines_only? = ELEMENT_FIELDS.none? { |field| public_send(field) }
|
|
81
85
|
end
|
|
82
86
|
end
|
|
@@ -8,9 +8,16 @@ module SEPA
|
|
|
8
8
|
validates_with LEIValidator, field_name: :initiating_party_lei, message: 'is invalid'
|
|
9
9
|
validates_with BICValidator, field_name: :initiating_party_bic, message: 'is invalid'
|
|
10
10
|
|
|
11
|
+
requires_capabilities initiating_party_lei: :lei
|
|
12
|
+
|
|
11
13
|
def initiating_party_id(builder, profile)
|
|
12
|
-
|
|
14
|
+
# Exclusive `InitgPty` allows a single `OrgId` child; the creditor
|
|
15
|
+
# identifier still reaches the bank through `CdtrSchmeId`.
|
|
16
|
+
identifier = creditor_identifier unless profile.features.exclusive_initiating_party
|
|
17
|
+
build_organisation_id(builder, identifier, profile,
|
|
13
18
|
lei: initiating_party_lei, org_bic: initiating_party_bic)
|
|
14
19
|
end
|
|
20
|
+
|
|
21
|
+
def initiating_party_identifiers = [initiating_party_bic, initiating_party_lei].compact
|
|
15
22
|
end
|
|
16
23
|
end
|
|
@@ -12,13 +12,18 @@ module SEPA
|
|
|
12
12
|
validates_length_of :initiating_party_scheme, within: 1..35, allow_nil: true
|
|
13
13
|
validates_with LEIValidator, field_name: :initiating_party_lei, message: 'is invalid'
|
|
14
14
|
validates_with BICValidator, field_name: :initiating_party_bic, message: 'is invalid'
|
|
15
|
+
validates_presence_of :initiating_party_identifier, if: :initiating_party_scheme
|
|
16
|
+
|
|
17
|
+
requires_capabilities initiating_party_lei: :lei
|
|
15
18
|
|
|
16
19
|
def initiating_party_id(builder, profile)
|
|
17
|
-
return
|
|
20
|
+
return if initiating_party_identifiers.empty?
|
|
18
21
|
|
|
19
22
|
build_organisation_id(builder, initiating_party_identifier, profile,
|
|
20
23
|
lei: initiating_party_lei, org_bic: initiating_party_bic,
|
|
21
24
|
scheme: initiating_party_scheme)
|
|
22
25
|
end
|
|
26
|
+
|
|
27
|
+
def initiating_party_identifiers = [initiating_party_bic, initiating_party_lei, initiating_party_identifier].compact
|
|
23
28
|
end
|
|
24
29
|
end
|
data/lib/sepa_rator/account.rb
CHANGED
|
@@ -4,6 +4,7 @@ module SEPA
|
|
|
4
4
|
class Account
|
|
5
5
|
include ActiveModel::Model
|
|
6
6
|
include CharsetApplicable
|
|
7
|
+
include CapabilityRequirements
|
|
7
8
|
extend Converter
|
|
8
9
|
|
|
9
10
|
attr_accessor :name, :iban, :bic, :address, :agent_lei, :contact_details
|
|
@@ -16,15 +17,19 @@ module SEPA
|
|
|
16
17
|
validates_with LEIValidator, field_name: :agent_lei, message: 'is invalid'
|
|
17
18
|
validates :address, :contact_details, nested_model: true, allow_nil: true
|
|
18
19
|
|
|
20
|
+
requires_capabilities agent_lei: :agent_lei, contact_details: :contact_details, address: :account_address
|
|
21
|
+
|
|
19
22
|
# @param _builder [Nokogiri::XML::Builder]
|
|
20
23
|
# @param _profile [SEPA::Profile]
|
|
21
24
|
# @abstract Override in subclasses to emit an `<Id>` block inside `<InitgPty>`.
|
|
22
25
|
def initiating_party_id(_builder, _profile); end
|
|
23
26
|
|
|
27
|
+
# @return [Array<String>] identifiers the caller set for `InitgPty/Id`
|
|
28
|
+
# @abstract Override in subclasses that accept initiating party identifiers.
|
|
29
|
+
def initiating_party_identifiers = [].freeze
|
|
30
|
+
|
|
24
31
|
protected
|
|
25
32
|
|
|
26
|
-
# Builds `<Id><OrgId>` with the schema-appropriate BIC tag (BICOrBEI/AnyBIC)
|
|
27
|
-
# and an optional LEI. Only emits LEI when the profile supports it.
|
|
28
33
|
def build_organisation_id(builder, identifier, profile, **options)
|
|
29
34
|
builder.Id do
|
|
30
35
|
builder.OrgId do
|
|
@@ -41,7 +46,7 @@ module SEPA
|
|
|
41
46
|
|
|
42
47
|
def build_org_bic_and_lei(builder, profile, options)
|
|
43
48
|
builder.__send__(profile.features.org_bic_tag, options[:org_bic]) if options[:org_bic]
|
|
44
|
-
builder.LEI(options[:lei]) if options[:lei]
|
|
49
|
+
builder.LEI(options[:lei]) if options[:lei]
|
|
45
50
|
end
|
|
46
51
|
end
|
|
47
52
|
end
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
module SEPA
|
|
4
4
|
module Builders
|
|
5
5
|
module CreditTransfer
|
|
6
|
-
#
|
|
7
|
-
# from the DirectDebit variant because Credit Transfer adds the
|
|
8
|
-
# `InitnSrc` element (pain.001.001.13 only, gated on the
|
|
9
|
-
# `:initiation_source` capability).
|
|
6
|
+
# Distinct from the DirectDebit variant because pain.001.001.13 adds `InitnSrc`.
|
|
10
7
|
class GroupHeader < Stage
|
|
11
8
|
def call
|
|
12
9
|
builder.GrpHdr do
|
|
@@ -14,11 +11,7 @@ module SEPA
|
|
|
14
11
|
builder.CreDtTm(message.creation_date_time)
|
|
15
12
|
builder.NbOfTxs(message.transactions.length)
|
|
16
13
|
builder.CtrlSum(XmlBuilder.format_amount(message.amount_total))
|
|
17
|
-
builder.
|
|
18
|
-
builder.Nm(message.account.name)
|
|
19
|
-
message.account.initiating_party_id(builder, profile)
|
|
20
|
-
XmlBuilder.build_contact_details(builder, message.account.contact_details)
|
|
21
|
-
end
|
|
14
|
+
XmlBuilder.build_initiating_party(builder, message.account, profile)
|
|
22
15
|
build_initiation_source
|
|
23
16
|
end
|
|
24
17
|
end
|
|
@@ -26,7 +19,6 @@ module SEPA
|
|
|
26
19
|
private
|
|
27
20
|
|
|
28
21
|
def build_initiation_source
|
|
29
|
-
return unless profile.supports?(:initiation_source)
|
|
30
22
|
return unless message.initiation_source_name
|
|
31
23
|
|
|
32
24
|
builder.InitnSrc do
|
|
@@ -5,10 +5,8 @@ module SEPA
|
|
|
5
5
|
module CreditTransfer
|
|
6
6
|
module Transaction
|
|
7
7
|
# MndtRltdInf — CreditTransferMandateData1 (pain.001.001.13 only).
|
|
8
|
-
# No-op for profiles that don't advertise the :mandate_related_info capability.
|
|
9
8
|
class CreditTransferMandate < Stage
|
|
10
9
|
def call
|
|
11
|
-
return unless profile.supports?(:mandate_related_info)
|
|
12
10
|
return unless transaction.credit_transfer_mandate?
|
|
13
11
|
|
|
14
12
|
builder.MndtRltdInf do
|
|
@@ -4,12 +4,8 @@ module SEPA
|
|
|
4
4
|
module Builders
|
|
5
5
|
module CreditTransfer
|
|
6
6
|
module Transaction
|
|
7
|
-
# Unbounded InstrForCdtrAgt blocks. Profile must advertise the
|
|
8
|
-
# :instructions_for_creditor_agent capability (EPC-only schemas
|
|
9
|
-
# don't define this element).
|
|
10
7
|
class InstructionsForCreditorAgent < Stage
|
|
11
8
|
def call
|
|
12
|
-
return unless profile.supports?(:instructions_for_creditor_agent)
|
|
13
9
|
return unless transaction.instructions_for_creditor_agent
|
|
14
10
|
|
|
15
11
|
transaction.instructions_for_creditor_agent.each do |instr|
|
|
@@ -8,7 +8,6 @@ module SEPA
|
|
|
8
8
|
# Version is driven by `profile.features.regulatory_reporting_version`.
|
|
9
9
|
class RegulatoryReporting < Stage
|
|
10
10
|
def call
|
|
11
|
-
return unless profile.supports?(:regulatory_reporting)
|
|
12
11
|
return unless transaction.regulatory_reportings
|
|
13
12
|
|
|
14
13
|
version = profile.features.regulatory_reporting_version
|
data/lib/sepa_rator/builders/credit_transfer/transaction/txn_instruction_for_debtor_agent.rb
CHANGED
|
@@ -8,7 +8,6 @@ module SEPA
|
|
|
8
8
|
# schemas and as a structured {Cd, InstrInf} block in pain.001.001.13.
|
|
9
9
|
class TxnInstructionForDebtorAgent < Stage
|
|
10
10
|
def call
|
|
11
|
-
return unless profile.supports?(:txn_instruction_for_debtor_agent)
|
|
12
11
|
return unless transaction.instruction_for_debtor_agent || transaction.instruction_for_debtor_agent_code
|
|
13
12
|
|
|
14
13
|
case profile.features.instr_for_dbtr_agt_format
|
|
@@ -10,11 +10,7 @@ module SEPA
|
|
|
10
10
|
builder.CreDtTm(message.creation_date_time)
|
|
11
11
|
builder.NbOfTxs(message.transactions.length)
|
|
12
12
|
builder.CtrlSum(XmlBuilder.format_amount(message.amount_total))
|
|
13
|
-
builder.
|
|
14
|
-
builder.Nm(message.account.name)
|
|
15
|
-
message.account.initiating_party_id(builder, profile)
|
|
16
|
-
XmlBuilder.build_contact_details(builder, message.account.contact_details)
|
|
17
|
-
end
|
|
13
|
+
XmlBuilder.build_initiating_party(builder, message.account, profile)
|
|
18
14
|
end
|
|
19
15
|
end
|
|
20
16
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_support/concern'
|
|
4
|
+
|
|
5
|
+
module SEPA
|
|
6
|
+
# Maps each optional field to the profile capability that serialises it, so
|
|
7
|
+
# a field the profile's schema cannot hold is rejected before XML generation.
|
|
8
|
+
module CapabilityRequirements
|
|
9
|
+
extend ActiveSupport::Concern
|
|
10
|
+
|
|
11
|
+
included do
|
|
12
|
+
class_attribute :capability_requirements, instance_writer: false, default: {}.freeze
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class_methods do
|
|
16
|
+
def requires_capabilities(**requirements)
|
|
17
|
+
self.capability_requirements = capability_requirements.merge(requirements).freeze
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @return [Array(Symbol, Symbol), nil] first `[field, capability]` the profile cannot serialise
|
|
22
|
+
def capability_violation(profile)
|
|
23
|
+
capability_requirements.find do |field, capability|
|
|
24
|
+
!profile.supports?(capability) && field_set?(public_send(field))
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def field_set?(value)
|
|
31
|
+
value.respond_to?(:empty?) ? !value.empty? : !value.nil?
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -35,13 +35,19 @@ module SEPA
|
|
|
35
35
|
validation_errors = xsd.validate(document)
|
|
36
36
|
return if validation_errors.empty?
|
|
37
37
|
|
|
38
|
-
sanitized = validation_errors.map { |e| e.message
|
|
38
|
+
sanitized = validation_errors.map { |e| sanitize_schema_error(e.message) }
|
|
39
39
|
raise SEPA::SchemaValidationError.new(
|
|
40
40
|
"Incompatible with profile #{profile.id}: #{sanitized.join(', ')}",
|
|
41
41
|
validation_errors.map(&:message)
|
|
42
42
|
)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
# Values can carry personal data (IBAN, names); element names cannot, and
|
|
46
|
+
# dropping their namespace keeps them under the redaction threshold.
|
|
47
|
+
def sanitize_schema_error(message)
|
|
48
|
+
message.gsub(/\{[^}]*\}/, '').gsub(/'[^']{20,}'/, "'[REDACTED]'")
|
|
49
|
+
end
|
|
50
|
+
|
|
45
51
|
def load_xsd(profile)
|
|
46
52
|
path = resolve_xsd_path(profile)
|
|
47
53
|
cached = SCHEMA_CACHE[path]
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module SEPA
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
# Most helpers are data-only; `build_agent_bic` is the exception that
|
|
7
|
-
# takes a profile to select the right BIC tag and LEI emission.
|
|
4
|
+
# Stateless XML fragments shared by builder stages; only `build_agent_bic` and
|
|
5
|
+
# `build_initiating_party` depend on the profile (BIC tag, `InitgPty` layout).
|
|
8
6
|
module XmlBuilder
|
|
9
7
|
module_function
|
|
10
8
|
|
|
@@ -58,14 +56,24 @@ module SEPA
|
|
|
58
56
|
end
|
|
59
57
|
end
|
|
60
58
|
|
|
61
|
-
def
|
|
62
|
-
|
|
59
|
+
def build_initiating_party(builder, account, profile)
|
|
60
|
+
builder.InitgPty do
|
|
61
|
+
if profile.features.exclusive_initiating_party
|
|
62
|
+
account.initiating_party_identifiers.empty? ? builder.Nm(account.name) : account.initiating_party_id(builder, profile)
|
|
63
|
+
else
|
|
64
|
+
builder.Nm(account.name)
|
|
65
|
+
account.initiating_party_id(builder, profile)
|
|
66
|
+
build_contact_details(builder, account.contact_details)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
63
70
|
|
|
71
|
+
def build_agent_bic(builder, bic, profile, fallback: true, lei: nil)
|
|
64
72
|
builder.FinInstnId do
|
|
65
73
|
# XSD sequence: BICFI/BIC → ClrSysMmbId → LEI → Nm → PstlAdr → Othr
|
|
66
74
|
builder.__send__(profile.features.bic_tag, bic) if bic
|
|
67
|
-
builder.LEI(lei) if
|
|
68
|
-
if !bic && !
|
|
75
|
+
builder.LEI(lei) if lei
|
|
76
|
+
if !bic && !lei && fallback
|
|
69
77
|
builder.Othr do
|
|
70
78
|
builder.Id('NOTPROVIDED')
|
|
71
79
|
end
|
data/lib/sepa_rator/message.rb
CHANGED
|
@@ -52,8 +52,7 @@ module SEPA
|
|
|
52
52
|
@profile = resolve_profile(country: country, version: version, profile: profile)
|
|
53
53
|
@grouped_transactions = {}
|
|
54
54
|
@account = admit(account_class.new(account_options))
|
|
55
|
-
|
|
56
|
-
validate_account_against_profile!(@account)
|
|
55
|
+
validate_message_account_against_profile!
|
|
57
56
|
end
|
|
58
57
|
|
|
59
58
|
# Add a transaction to the message. The transaction is validated both
|
|
@@ -89,8 +88,7 @@ module SEPA
|
|
|
89
88
|
[@account, *transactions].each { |model| model.apply_charset(charset) }
|
|
90
89
|
raise SEPA::ValidationError, errors.full_messages.join("\n") unless valid?
|
|
91
90
|
|
|
92
|
-
|
|
93
|
-
validate_account_against_profile!(@account)
|
|
91
|
+
validate_message_account_against_profile!
|
|
94
92
|
transactions.each { |transaction| validate_transaction_against_profile!(transaction) }
|
|
95
93
|
|
|
96
94
|
doc = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |builder|
|
|
@@ -168,11 +166,8 @@ module SEPA
|
|
|
168
166
|
# profile. Called both from `add_transaction` (at insertion) and from
|
|
169
167
|
# `to_xml` (as a fail-safe against post-insertion mutations).
|
|
170
168
|
def validate_transaction_against_profile!(transaction)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if transaction.respond_to?(:creditor_account) && transaction.creditor_account
|
|
174
|
-
validate_account_against_profile!(transaction.creditor_account, label: 'creditor_account')
|
|
175
|
-
end
|
|
169
|
+
validate_creditor_account_override!(transaction.creditor_account) if transaction.respond_to?(:creditor_account) && transaction.creditor_account
|
|
170
|
+
assert_capabilities!(transaction, 'transaction')
|
|
176
171
|
|
|
177
172
|
raise SEPA::ValidationError, "Transaction not compatible with profile #{profile.id}" unless transaction.compatible_with?(profile)
|
|
178
173
|
|
|
@@ -180,63 +175,59 @@ module SEPA
|
|
|
180
175
|
run_profile_validators(transaction)
|
|
181
176
|
end
|
|
182
177
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
# construction and from `to_xml` as a fail-safe against late mutation.
|
|
187
|
-
def validate_message_against_profile!
|
|
188
|
-
return unless @initiation_source_name && !profile.supports?(:initiation_source)
|
|
178
|
+
def validate_message_account_against_profile!
|
|
179
|
+
validate_account_against_profile!(@account, 'account')
|
|
180
|
+
return unless profile.features.exclusive_initiating_party && @account.initiating_party_identifiers.length > 1
|
|
189
181
|
|
|
190
182
|
raise SEPA::ValidationError,
|
|
191
|
-
"[#{profile.id}]
|
|
183
|
+
"[#{profile.id}] InitgPty/Id holds a single identifier: set only one of " \
|
|
184
|
+
'initiating_party_bic, initiating_party_lei or initiating_party_identifier'
|
|
192
185
|
end
|
|
193
186
|
|
|
194
|
-
#
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
def validate_account_against_profile!(account, label: 'account')
|
|
199
|
-
raise SEPA::ValidationError, "[#{profile.id}] #{label} is missing the required BIC" if profile.features.requires_bic && (account.bic.nil? || account.bic.empty?)
|
|
187
|
+
# `InitgPty` is built from the message account only.
|
|
188
|
+
def validate_creditor_account_override!(account)
|
|
189
|
+
validate_account_against_profile!(account, 'creditor_account')
|
|
190
|
+
return if account.initiating_party_identifiers.empty?
|
|
200
191
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
account.initiating_party_lei && !account.initiating_party_lei.empty?
|
|
208
|
-
raise SEPA::ValidationError,
|
|
209
|
-
"[#{profile.id}] #{label}.initiating_party_lei is set but the profile does not support LEI"
|
|
210
|
-
end
|
|
211
|
-
end
|
|
192
|
+
raise SEPA::ValidationError, "[#{profile.id}] creditor_account.initiating_party_* is ignored: set it on the message account instead"
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# Shared by the message account and the direct debit `creditor_account` override.
|
|
196
|
+
def validate_account_against_profile!(account, label)
|
|
197
|
+
raise SEPA::ValidationError, "[#{profile.id}] #{label} is missing the required BIC" if profile.features.requires_bic && (account.bic.nil? || account.bic.empty?)
|
|
212
198
|
|
|
213
|
-
|
|
199
|
+
assert_capabilities!(account, label)
|
|
200
|
+
assert_address_format!(account.address, "#{label}.address")
|
|
214
201
|
assert_address_has_country_code!(account.address, "#{label}.address")
|
|
215
202
|
end
|
|
216
203
|
|
|
204
|
+
def assert_capabilities!(model, label)
|
|
205
|
+
field, capability = model.capability_violation(profile)
|
|
206
|
+
raise SEPA::ValidationError, "[#{profile.id}] #{label}.#{field} requires capability :#{capability}, not supported by this profile" if field
|
|
207
|
+
end
|
|
208
|
+
|
|
217
209
|
# Transaction-level addresses (`creditor_address`, `debtor_address`) are
|
|
218
210
|
# serialised in `PmtInf/*/PstlAdr` and must satisfy the same structured
|
|
219
211
|
# requirement as the message account when the profile mandates it.
|
|
220
212
|
def validate_transaction_addresses_against_profile!(transaction)
|
|
221
|
-
if
|
|
222
|
-
|
|
223
|
-
assert_address_structured!(transaction.debtor_address, 'debtor_address') if transaction.respond_to?(:debtor_address)
|
|
224
|
-
end
|
|
225
|
-
|
|
213
|
+
assert_address_format!(transaction.creditor_address, 'creditor_address') if transaction.respond_to?(:creditor_address)
|
|
214
|
+
assert_address_format!(transaction.debtor_address, 'debtor_address') if transaction.respond_to?(:debtor_address)
|
|
226
215
|
return unless profile.features.requires_country_code_on_address
|
|
227
216
|
|
|
228
217
|
assert_address_has_country_code!(transaction.creditor_address, 'creditor_address') if transaction.respond_to?(:creditor_address)
|
|
229
218
|
assert_address_has_country_code!(transaction.debtor_address, 'debtor_address') if transaction.respond_to?(:debtor_address)
|
|
230
219
|
end
|
|
231
220
|
|
|
232
|
-
def
|
|
233
|
-
return unless profile.features.requires_structured_address
|
|
221
|
+
def assert_address_format!(address, label)
|
|
234
222
|
return if address.nil?
|
|
235
|
-
|
|
223
|
+
|
|
224
|
+
if profile.features.requires_structured_address && !address.structured?
|
|
225
|
+
raise SEPA::ValidationError, "[#{profile.id}] #{label} must use structured fields (StrtNm, PstCd, TwnNm, …), not AdrLine"
|
|
226
|
+
end
|
|
227
|
+
return if address.lines_only? || profile.supports?(:structured_address)
|
|
236
228
|
|
|
237
229
|
raise SEPA::ValidationError,
|
|
238
|
-
"[#{profile.id}] #{label}
|
|
239
|
-
'(StrtNm, PstCd, TwnNm, …), not AdrLine'
|
|
230
|
+
"[#{profile.id}] #{label} requires capability :structured_address, not supported by this profile: set only country_code and address lines"
|
|
240
231
|
end
|
|
241
232
|
|
|
242
233
|
def assert_address_has_country_code!(address, label)
|
data/lib/sepa_rator/profile.rb
CHANGED
|
@@ -14,6 +14,8 @@ module SEPA
|
|
|
14
14
|
:min_amount,
|
|
15
15
|
:requires_structured_address,
|
|
16
16
|
:requires_country_code_on_address,
|
|
17
|
+
# PSA subsets: `InitgPty` holds exactly one of `Nm` or `Id`.
|
|
18
|
+
:exclusive_initiating_party,
|
|
17
19
|
:extras
|
|
18
20
|
) do
|
|
19
21
|
def self.default
|
|
@@ -29,6 +31,7 @@ module SEPA
|
|
|
29
31
|
min_amount: nil,
|
|
30
32
|
requires_structured_address: false,
|
|
31
33
|
requires_country_code_on_address: false,
|
|
34
|
+
exclusive_initiating_party: false,
|
|
32
35
|
extras: {}.freeze
|
|
33
36
|
)
|
|
34
37
|
end
|
|
@@ -97,8 +100,9 @@ module SEPA
|
|
|
97
100
|
# Freeze collection fields so a caller cannot mutate a registered
|
|
98
101
|
# profile's arrays under our feet. Individual stages/validators are
|
|
99
102
|
# classes (already immutable by reference).
|
|
100
|
-
%i[validators
|
|
103
|
+
%i[validators transaction_stages payment_info_stages group_header_stages]
|
|
101
104
|
.each { |key| attrs[key] = attrs[key].dup.freeze unless attrs[key].frozen? }
|
|
105
|
+
attrs[:capabilities] = attrs[:capabilities].to_set.freeze
|
|
102
106
|
|
|
103
107
|
# Catch "forgot to point at a stage class" coquilles at registration
|
|
104
108
|
# time instead of at XML build time.
|
|
@@ -143,13 +147,10 @@ module SEPA
|
|
|
143
147
|
end
|
|
144
148
|
end
|
|
145
149
|
|
|
146
|
-
#
|
|
147
|
-
#
|
|
148
|
-
# operations (`insert_after:`, `replace:`/`with:`, `remove:`).
|
|
149
|
-
#
|
|
150
|
-
# Array = append (common case), `{ replace: [...] }` = drop the parent
|
|
151
|
-
# list, `{ add: [...] }` = explicit append.
|
|
150
|
+
# Flat lists only (`validators`, `capabilities`): order is irrelevant, so no
|
|
151
|
+
# positional operations as in `StageList.merge`.
|
|
152
152
|
def merge_list(old, value, unique:)
|
|
153
|
+
old = old.to_a
|
|
153
154
|
combined =
|
|
154
155
|
case value
|
|
155
156
|
when Array
|
|
@@ -158,10 +159,11 @@ module SEPA
|
|
|
158
159
|
case value
|
|
159
160
|
in { replace: new } then Array(new)
|
|
160
161
|
in { add: new } then old + Array(new)
|
|
162
|
+
in { remove: removed } then old - Array(removed)
|
|
161
163
|
else
|
|
162
164
|
raise ArgumentError,
|
|
163
165
|
"merge_list: unsupported Hash operation #{value.inspect}. " \
|
|
164
|
-
'Expected `{ replace: [...] }` or `{
|
|
166
|
+
'Expected `{ replace: [...] }`, `{ add: [...] }` or `{ remove: [...] }`.'
|
|
165
167
|
end
|
|
166
168
|
else
|
|
167
169
|
raise ArgumentError,
|
|
@@ -2,19 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
module SEPA
|
|
4
4
|
module Profiles
|
|
5
|
-
# PSA
|
|
6
|
-
#
|
|
7
|
-
# PSA publishes Austrian "Technical Validation Subsets" that tighten the
|
|
8
|
-
# ISO baseline with a minimum amount of 0.01 and (for v09+) structured
|
|
9
|
-
# postal addresses. The vendored XSDs live in `lib/schema/at/`
|
|
10
|
-
# (downloaded from https://zv.psa.at).
|
|
11
|
-
#
|
|
12
|
-
# The original PSA XSDs use a STUZZA-specific targetNamespace
|
|
13
|
-
# (`ISO:pain.*:APC:STUZZA:payments:*`); the vendored copies keep the
|
|
14
|
-
# ISO namespace because Austrian banks require the ISO namespace for
|
|
15
|
-
# transmission. XSD 1.1 `xs:assert` elements (cross-field checks
|
|
16
|
-
# already handled in Ruby) have been stripped from v09/v08 schemas so
|
|
17
|
-
# Nokogiri/libxml2 (XSD 1.0 only) can load them.
|
|
5
|
+
# Vendored PSA XSDs keep the ISO namespace banks require, not STUZZA's, and drop
|
|
6
|
+
# XSD 1.1 asserts libxml2 cannot load. v13/v12 have no PSA subset: plain ISO.
|
|
18
7
|
module AT
|
|
19
8
|
VALIDATORS = [Validators::MinAmount].freeze
|
|
20
9
|
|
|
@@ -24,23 +13,27 @@ module SEPA
|
|
|
24
13
|
requires_structured_address: true
|
|
25
14
|
}.freeze
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
16
|
+
SUBSET = {
|
|
17
|
+
features: FEATURES.merge(exclusive_initiating_party: true),
|
|
18
|
+
validators: VALIDATORS,
|
|
19
|
+
capabilities: { remove: %i[contact_details agent_lei account_address] }
|
|
20
|
+
}.freeze
|
|
21
|
+
|
|
22
|
+
# PSA v03/v02 PostalAddress6 only supports Ctry + AdrLine.
|
|
23
|
+
LEGACY_SUBSET = {
|
|
24
|
+
features: { charset: Charset::AT, min_amount: BigDecimal('0.01'), exclusive_initiating_party: true },
|
|
25
|
+
validators: VALIDATORS,
|
|
26
|
+
capabilities: { remove: %i[contact_details structured_address] }
|
|
32
27
|
}.freeze
|
|
33
28
|
|
|
34
29
|
# ─── SEPA Credit Transfer ────────────────────────────────────────────
|
|
35
30
|
|
|
36
31
|
SCT_03 = ProfileRegistry.register(
|
|
37
|
-
EPC::SCT_03.with(id: 'at.sct.03', xsd_path: 'at/pain.001.001.03.at.004.xsd',
|
|
38
|
-
features: LEGACY_FEATURES, validators: VALIDATORS)
|
|
32
|
+
EPC::SCT_03.with(id: 'at.sct.03', xsd_path: 'at/pain.001.001.03.at.004.xsd', **LEGACY_SUBSET)
|
|
39
33
|
)
|
|
40
34
|
|
|
41
35
|
SCT_09 = ProfileRegistry.register(
|
|
42
|
-
EPC::SCT_09.with(id: 'at.sct.09', xsd_path: 'at/pain.001.001.09.at.005.xsd',
|
|
43
|
-
features: FEATURES, validators: VALIDATORS)
|
|
36
|
+
EPC::SCT_09.with(id: 'at.sct.09', xsd_path: 'at/pain.001.001.09.at.005.xsd', **SUBSET)
|
|
44
37
|
)
|
|
45
38
|
|
|
46
39
|
SCT_13 = ProfileRegistry.register(
|
|
@@ -50,13 +43,11 @@ module SEPA
|
|
|
50
43
|
# ─── SEPA Direct Debit ───────────────────────────────────────────────
|
|
51
44
|
|
|
52
45
|
SDD_02 = ProfileRegistry.register(
|
|
53
|
-
EPC::SDD_02.with(id: 'at.sdd.02', xsd_path: 'at/pain.008.001.02.at.004.xsd',
|
|
54
|
-
features: LEGACY_FEATURES, validators: VALIDATORS)
|
|
46
|
+
EPC::SDD_02.with(id: 'at.sdd.02', xsd_path: 'at/pain.008.001.02.at.004.xsd', **LEGACY_SUBSET)
|
|
55
47
|
)
|
|
56
48
|
|
|
57
49
|
SDD_08 = ProfileRegistry.register(
|
|
58
|
-
EPC::SDD_08.with(id: 'at.sdd.08', xsd_path: 'at/pain.008.001.08.at.004.xsd',
|
|
59
|
-
features: FEATURES, validators: VALIDATORS)
|
|
50
|
+
EPC::SDD_08.with(id: 'at.sdd.08', xsd_path: 'at/pain.008.001.08.at.004.xsd', **SUBSET)
|
|
60
51
|
)
|
|
61
52
|
|
|
62
53
|
SDD_12 = ProfileRegistry.register(
|
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module SEPA
|
|
4
4
|
module Profiles
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
# DK publishes its own XSDs that tighten the ISO baseline with a minimum
|
|
8
|
-
# transaction amount of 0.01 and structured postal addresses. The vendored
|
|
9
|
-
# XSDs live in `lib/schema/dk/` (downloaded from https://www.ebics.de).
|
|
5
|
+
# DK (DFÜ-Abkommen, EBICS) GBIC3/GBIC5 subsets; v13/v12 have no DK schema: plain ISO.
|
|
10
6
|
module DK
|
|
11
7
|
VALIDATORS = [Validators::DK::MinAmount].freeze
|
|
12
8
|
|
|
@@ -16,8 +12,7 @@ module SEPA
|
|
|
16
12
|
requires_structured_address: true
|
|
17
13
|
}.freeze
|
|
18
14
|
|
|
19
|
-
# GBIC3 (v03/v02) PostalAddressSEPA only supports Ctry + AdrLine
|
|
20
|
-
# not structured fields — so we must not require structured addresses.
|
|
15
|
+
# GBIC3 (v03/v02) PostalAddressSEPA only supports Ctry + AdrLine.
|
|
21
16
|
LEGACY_FEATURES = {
|
|
22
17
|
charset: Charset::DK,
|
|
23
18
|
min_amount: BigDecimal('0.01')
|
|
@@ -27,12 +22,14 @@ module SEPA
|
|
|
27
22
|
|
|
28
23
|
SCT_03_GBIC3 = ProfileRegistry.register(
|
|
29
24
|
EPC::SCT_03.with(id: 'dk.sct.03.gbic3', xsd_path: 'dk/pain.001.001.03_GBIC_3.xsd',
|
|
30
|
-
features: LEGACY_FEATURES, validators: VALIDATORS
|
|
25
|
+
features: LEGACY_FEATURES, validators: VALIDATORS,
|
|
26
|
+
capabilities: { remove: %i[contact_details structured_address] })
|
|
31
27
|
)
|
|
32
28
|
|
|
33
29
|
SCT_09_GBIC5 = ProfileRegistry.register(
|
|
34
30
|
EPC::SCT_09.with(id: 'dk.sct.09.gbic5', xsd_path: 'dk/pain.001.001.09_GBIC_5.xsd',
|
|
35
|
-
features: FEATURES, validators: VALIDATORS
|
|
31
|
+
features: FEATURES, validators: VALIDATORS,
|
|
32
|
+
capabilities: { remove: %i[contact_details agent_lei] })
|
|
36
33
|
)
|
|
37
34
|
|
|
38
35
|
SCT_13_GBIC5 = ProfileRegistry.register(
|
|
@@ -43,12 +40,14 @@ module SEPA
|
|
|
43
40
|
|
|
44
41
|
SDD_02_GBIC3 = ProfileRegistry.register(
|
|
45
42
|
EPC::SDD_02.with(id: 'dk.sdd.02.gbic3', xsd_path: 'dk/pain.008.001.02_GBIC_3.xsd',
|
|
46
|
-
features: LEGACY_FEATURES, validators: VALIDATORS
|
|
43
|
+
features: LEGACY_FEATURES, validators: VALIDATORS,
|
|
44
|
+
capabilities: { remove: %i[contact_details structured_address] })
|
|
47
45
|
)
|
|
48
46
|
|
|
49
47
|
SDD_08_GBIC5 = ProfileRegistry.register(
|
|
50
48
|
EPC::SDD_08.with(id: 'dk.sdd.08.gbic5', xsd_path: 'dk/pain.008.001.08_GBIC_5.xsd',
|
|
51
|
-
features: FEATURES, validators: VALIDATORS
|
|
49
|
+
features: FEATURES, validators: VALIDATORS,
|
|
50
|
+
capabilities: { remove: %i[contact_details agent_lei] })
|
|
52
51
|
)
|
|
53
52
|
|
|
54
53
|
SDD_12_GBIC5 = ProfileRegistry.register(
|
|
@@ -70,6 +70,9 @@ module SEPA
|
|
|
70
70
|
instructions_for_creditor_agent
|
|
71
71
|
txn_instruction_for_debtor_agent
|
|
72
72
|
regulatory_reporting
|
|
73
|
+
contact_details
|
|
74
|
+
account_address
|
|
75
|
+
structured_address
|
|
73
76
|
].freeze,
|
|
74
77
|
transaction_stages: CREDIT_TRANSFER_STAGES,
|
|
75
78
|
payment_info_stages: CREDIT_TRANSFER_PAYMENT_INFO_STAGES,
|
|
@@ -85,7 +88,7 @@ module SEPA
|
|
|
85
88
|
xsd_path: 'iso/pain.001.001.09.xsd',
|
|
86
89
|
namespace: 'urn:iso:std:iso:20022:tech:xsd:pain.001.001.09',
|
|
87
90
|
features: { bic_tag: :BICFI, wrap_date: true, org_bic_tag: :AnyBIC },
|
|
88
|
-
capabilities: %i[uetr lei pmtinf_debtor_agent_instruction]
|
|
91
|
+
capabilities: %i[uetr lei agent_lei pmtinf_debtor_agent_instruction]
|
|
89
92
|
)
|
|
90
93
|
)
|
|
91
94
|
|
|
@@ -121,9 +124,8 @@ module SEPA
|
|
|
121
124
|
xsd_path: 'iso/pain.001.002.03.xsd',
|
|
122
125
|
namespace: 'urn:iso:std:iso:20022:tech:xsd:pain.001.002.03',
|
|
123
126
|
features: { requires_bic: true, charset: Charset::EPC },
|
|
124
|
-
# EPC AOS drops InstrForCdtrAgt, InstrForDbtrAgt and
|
|
125
|
-
|
|
126
|
-
capabilities: { replace: [].freeze },
|
|
127
|
+
# EPC AOS drops InstrForCdtrAgt, InstrForDbtrAgt, RgltryRptg, CtctDtls and structured PstlAdr.
|
|
128
|
+
capabilities: { replace: %i[account_address].freeze },
|
|
127
129
|
transaction_stages: [
|
|
128
130
|
CT_STAGE::PaymentId,
|
|
129
131
|
CT_STAGE::Amount,
|
|
@@ -178,7 +180,7 @@ module SEPA
|
|
|
178
180
|
org_bic_tag: :BICOrBEI
|
|
179
181
|
),
|
|
180
182
|
validators: [].freeze,
|
|
181
|
-
capabilities: [].freeze,
|
|
183
|
+
capabilities: %i[contact_details account_address structured_address].freeze,
|
|
182
184
|
transaction_stages: DIRECT_DEBIT_STAGES,
|
|
183
185
|
payment_info_stages: DIRECT_DEBIT_PAYMENT_INFO_STAGES,
|
|
184
186
|
group_header_stages: DIRECT_DEBIT_GROUP_HEADER_STAGES,
|
|
@@ -193,7 +195,7 @@ module SEPA
|
|
|
193
195
|
xsd_path: 'iso/pain.008.001.08.xsd',
|
|
194
196
|
namespace: 'urn:iso:std:iso:20022:tech:xsd:pain.008.001.08',
|
|
195
197
|
features: { bic_tag: :BICFI, org_bic_tag: :AnyBIC },
|
|
196
|
-
capabilities: %i[uetr lei],
|
|
198
|
+
capabilities: %i[uetr lei agent_lei],
|
|
197
199
|
# v08+ lifts the v1 sequence type constraint (RPRE supported).
|
|
198
200
|
accept_transaction: nil
|
|
199
201
|
)
|
|
@@ -215,6 +217,7 @@ module SEPA
|
|
|
215
217
|
xsd_path: 'iso/pain.008.002.02.xsd',
|
|
216
218
|
namespace: 'urn:iso:std:iso:20022:tech:xsd:pain.008.002.02',
|
|
217
219
|
features: { requires_bic: true, charset: Charset::EPC },
|
|
220
|
+
capabilities: { remove: %i[contact_details structured_address] },
|
|
218
221
|
accept_transaction: DD_EPC_RULES
|
|
219
222
|
)
|
|
220
223
|
)
|
|
@@ -226,6 +229,7 @@ module SEPA
|
|
|
226
229
|
xsd_path: 'iso/pain.008.003.02.xsd',
|
|
227
230
|
namespace: 'urn:iso:std:iso:20022:tech:xsd:pain.008.003.02',
|
|
228
231
|
features: { charset: Charset::EPC },
|
|
232
|
+
capabilities: { remove: %i[contact_details structured_address] },
|
|
229
233
|
accept_transaction: DD_EPC_RULES
|
|
230
234
|
)
|
|
231
235
|
)
|
|
@@ -49,7 +49,9 @@ module SEPA
|
|
|
49
49
|
|
|
50
50
|
SCT_09 = ProfileRegistry.register(
|
|
51
51
|
ISO::SCT_09.with(id: 'sps.sct.09', xsd_path: 'sps/pain.001.001.09.ch.03.xsd',
|
|
52
|
-
features: FEATURES, accept_transaction: CT_SPS_RULES
|
|
52
|
+
features: FEATURES, accept_transaction: CT_SPS_RULES,
|
|
53
|
+
# The SPS XSD allows CtctDtls in InitgPty only; contact_details also feeds Dbtr and Cdtr.
|
|
54
|
+
capabilities: { remove: %i[contact_details] })
|
|
53
55
|
)
|
|
54
56
|
|
|
55
57
|
SCT_13 = ProfileRegistry.register(
|
|
@@ -45,11 +45,21 @@ module SEPA
|
|
|
45
45
|
validates_length_of :credit_transfer_mandate_id, within: 1..35, allow_nil: true
|
|
46
46
|
validates_inclusion_of :credit_transfer_mandate_frequency, in: FREQUENCY_CODES, allow_nil: true
|
|
47
47
|
|
|
48
|
-
validate { |t| t.validate_requested_date_after(Date.
|
|
48
|
+
validate { |t| t.validate_requested_date_after(Date.current) }
|
|
49
49
|
validate :validate_instructions_for_creditor_agent
|
|
50
50
|
validate :validate_regulatory_reportings
|
|
51
51
|
validate :validate_credit_transfer_mandate_date_of_signature
|
|
52
52
|
|
|
53
|
+
requires_capabilities debtor_agent_instruction: :pmtinf_debtor_agent_instruction,
|
|
54
|
+
credit_transfer_mandate_id: :mandate_related_info,
|
|
55
|
+
credit_transfer_mandate_date_of_signature: :mandate_related_info,
|
|
56
|
+
credit_transfer_mandate_frequency: :mandate_related_info,
|
|
57
|
+
instruction_for_debtor_agent: :txn_instruction_for_debtor_agent,
|
|
58
|
+
instruction_for_debtor_agent_code: :txn_instruction_for_debtor_agent,
|
|
59
|
+
instructions_for_creditor_agent: :instructions_for_creditor_agent,
|
|
60
|
+
regulatory_reportings: :regulatory_reporting,
|
|
61
|
+
creditor_contact_details: :contact_details
|
|
62
|
+
|
|
53
63
|
def initialize(attributes = {})
|
|
54
64
|
super
|
|
55
65
|
# Ergonomic default: EUR transactions get SvcLvl=SEPA unless the
|
|
@@ -72,20 +82,11 @@ module SEPA
|
|
|
72
82
|
credit_transfer_mandate_id || credit_transfer_mandate_date_of_signature || credit_transfer_mandate_frequency
|
|
73
83
|
end
|
|
74
84
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
# in the base Transaction#compatible_with?.
|
|
78
|
-
def compatible_capabilities?(profile)
|
|
79
|
-
requires_capability?(uetr, profile, :uetr) &&
|
|
80
|
-
requires_capability?(agent_lei, profile, :lei) &&
|
|
81
|
-
requires_capability?(debtor_agent_instruction, profile, :pmtinf_debtor_agent_instruction) &&
|
|
82
|
-
requires_capability?(credit_transfer_mandate?, profile, :mandate_related_info) &&
|
|
83
|
-
requires_capability?(instruction_for_debtor_agent, profile, :txn_instruction_for_debtor_agent) &&
|
|
84
|
-
requires_capability?(regulatory_reportings&.any?, profile, :regulatory_reporting) &&
|
|
85
|
+
def compatible_features?(profile)
|
|
86
|
+
super &&
|
|
85
87
|
instr_for_dbtr_agt_code_compatible?(profile) &&
|
|
86
88
|
instructions_for_creditor_agent_compatible?(profile) &&
|
|
87
|
-
regulatory_reportings_compatible?(profile)
|
|
88
|
-
(!profile.features.requires_bic || (bic && !bic.empty?))
|
|
89
|
+
regulatory_reportings_compatible?(profile)
|
|
89
90
|
end
|
|
90
91
|
|
|
91
92
|
private
|
|
@@ -100,23 +101,15 @@ module SEPA
|
|
|
100
101
|
end
|
|
101
102
|
end
|
|
102
103
|
|
|
103
|
-
def requires_capability?(field_present, profile, capability)
|
|
104
|
-
!field_present || profile.supports?(capability)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
104
|
# `instruction_for_debtor_agent_code` is the `Cd` element inside the
|
|
108
105
|
# structured InstrForDbtrAgt block, which only exists when the profile
|
|
109
106
|
# emits that block in structured form (pain.001.001.13+).
|
|
110
107
|
def instr_for_dbtr_agt_code_compatible?(profile)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
profile.supports?(:txn_instruction_for_debtor_agent) &&
|
|
114
|
-
profile.features.instr_for_dbtr_agt_format == :structured
|
|
108
|
+
!instruction_for_debtor_agent_code || profile.features.instr_for_dbtr_agt_format == :structured
|
|
115
109
|
end
|
|
116
110
|
|
|
117
111
|
def instructions_for_creditor_agent_compatible?(profile)
|
|
118
112
|
return true unless instructions_for_creditor_agent&.any?
|
|
119
|
-
return false unless profile.supports?(:instructions_for_creditor_agent)
|
|
120
113
|
|
|
121
114
|
instructions_for_creditor_agent.all? { |instr| valid_instruction_code?(instr[:code], profile) }
|
|
122
115
|
end
|
|
@@ -25,7 +25,9 @@ module SEPA
|
|
|
25
25
|
validates_inclusion_of :sequence_type, in: SEQUENCE_TYPES
|
|
26
26
|
validates_inclusion_of :charge_bearer, in: CHARGE_BEARERS, allow_nil: true
|
|
27
27
|
validates :debtor_address, :debtor_contact_details, :creditor_account, nested_model: true, allow_nil: true
|
|
28
|
-
validate { |t| t.validate_requested_date_after(Date.
|
|
28
|
+
validate { |t| t.validate_requested_date_after(Date.current.next) }
|
|
29
|
+
|
|
30
|
+
requires_capabilities debtor_contact_details: :contact_details
|
|
29
31
|
|
|
30
32
|
validate do |t|
|
|
31
33
|
errors.add(:original_mandate_id, 'is invalid') if original_mandate_id && !original_mandate_id.to_s.match?(MandateIdentifierValidator::REGEX)
|
|
@@ -35,7 +37,7 @@ module SEPA
|
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
if t.mandate_date_of_signature.is_a?(Date)
|
|
38
|
-
errors.add(:mandate_date_of_signature, 'is in the future') if t.mandate_date_of_signature > Date.
|
|
40
|
+
errors.add(:mandate_date_of_signature, 'is in the future') if t.mandate_date_of_signature > Date.current
|
|
39
41
|
else
|
|
40
42
|
errors.add(:mandate_date_of_signature, 'is not a Date')
|
|
41
43
|
end
|
|
@@ -55,17 +57,8 @@ module SEPA
|
|
|
55
57
|
original_mandate_id || original_debtor_account || same_mandate_new_debtor_agent || original_creditor_account
|
|
56
58
|
end
|
|
57
59
|
|
|
58
|
-
def
|
|
59
|
-
|
|
60
|
-
requires_capability?(agent_lei, profile, :lei) &&
|
|
61
|
-
requires_capability?(creditor_account&.agent_lei, profile, :lei) &&
|
|
62
|
-
(!profile.features.requires_bic || (bic && !bic.empty?))
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
private
|
|
66
|
-
|
|
67
|
-
def requires_capability?(field_present, profile, capability)
|
|
68
|
-
!field_present || profile.supports?(capability)
|
|
60
|
+
def compatible_with?(profile)
|
|
61
|
+
super && (creditor_account.nil? || creditor_account.capability_violation(profile).nil?)
|
|
69
62
|
end
|
|
70
63
|
end
|
|
71
64
|
end
|
|
@@ -4,6 +4,7 @@ module SEPA
|
|
|
4
4
|
class Transaction
|
|
5
5
|
include ActiveModel::Model
|
|
6
6
|
include CharsetApplicable
|
|
7
|
+
include CapabilityRequirements
|
|
7
8
|
extend Converter
|
|
8
9
|
|
|
9
10
|
# Convention SEPA: 1999-01-01 signifies "execute as soon as possible" (ASAP).
|
|
@@ -60,6 +61,8 @@ module SEPA
|
|
|
60
61
|
validates_with IBANValidator
|
|
61
62
|
validates_with LEIValidator, field_name: :agent_lei, message: 'is invalid'
|
|
62
63
|
|
|
64
|
+
requires_capabilities uetr: :uetr, agent_lei: :agent_lei
|
|
65
|
+
|
|
63
66
|
validate do |t|
|
|
64
67
|
if t.remittance_information && (t.structured_remittance_information || t.additional_remittance_information)
|
|
65
68
|
t.errors.add(:base, 'remittance_information and structured remittance fields are mutually exclusive')
|
|
@@ -91,18 +94,12 @@ module SEPA
|
|
|
91
94
|
self
|
|
92
95
|
end
|
|
93
96
|
|
|
94
|
-
# @return [Boolean] whether this transaction can be rendered under the
|
|
95
|
-
# given profile. Delegates to `profile.accepts?` for profile-level rules
|
|
96
|
-
# (e.g. EPC currency restrictions) and to `#compatible_capabilities?` for
|
|
97
|
-
# capability-level checks (UETR, LEI, mandate info, …).
|
|
98
97
|
def compatible_with?(profile)
|
|
99
|
-
profile.accepts?(self) &&
|
|
98
|
+
profile.accepts?(self) && capability_violation(profile).nil? && compatible_features?(profile)
|
|
100
99
|
end
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
def compatible_capabilities?(_profile)
|
|
105
|
-
true
|
|
101
|
+
def compatible_features?(profile)
|
|
102
|
+
!profile.features.requires_bic || (bic && !bic.empty?)
|
|
106
103
|
end
|
|
107
104
|
|
|
108
105
|
protected
|
data/lib/sepa_rator/version.rb
CHANGED
data/lib/sepa_rator.rb
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'date'
|
|
4
|
+
require 'time'
|
|
3
5
|
require 'active_model'
|
|
6
|
+
require 'active_support/core_ext/date/calculations'
|
|
4
7
|
require 'bigdecimal'
|
|
5
8
|
require 'nokogiri'
|
|
6
9
|
require 'ibandit'
|
|
@@ -14,6 +17,7 @@ require 'sepa_rator/validator'
|
|
|
14
17
|
require 'sepa_rator/nested_model_validator'
|
|
15
18
|
require 'sepa_rator/concerns/charset_applicable'
|
|
16
19
|
require 'sepa_rator/concerns/regulatory_reporting_charset'
|
|
20
|
+
require 'sepa_rator/concerns/capability_requirements'
|
|
17
21
|
require 'sepa_rator/concerns/schema_validation'
|
|
18
22
|
require 'sepa_rator/concerns/xml_builder'
|
|
19
23
|
require 'sepa_rator/concerns/regulatory_reporting_validator'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sepa_rator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Georg Leciejewski
|
|
@@ -31,6 +31,26 @@ dependencies:
|
|
|
31
31
|
- - "<"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '9'
|
|
34
|
+
- !ruby/object:Gem::Dependency
|
|
35
|
+
name: activesupport
|
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 7.0.1
|
|
41
|
+
- - "<"
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '9'
|
|
44
|
+
type: :runtime
|
|
45
|
+
prerelease: false
|
|
46
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: 7.0.1
|
|
51
|
+
- - "<"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '9'
|
|
34
54
|
- !ruby/object:Gem::Dependency
|
|
35
55
|
name: ibandit
|
|
36
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -126,6 +146,7 @@ files:
|
|
|
126
146
|
- lib/sepa_rator/builders/direct_debit/transaction/ultimate_debtor.rb
|
|
127
147
|
- lib/sepa_rator/builders/stage.rb
|
|
128
148
|
- lib/sepa_rator/charset.rb
|
|
149
|
+
- lib/sepa_rator/concerns/capability_requirements.rb
|
|
129
150
|
- lib/sepa_rator/concerns/charset_applicable.rb
|
|
130
151
|
- lib/sepa_rator/concerns/regulatory_reporting_charset.rb
|
|
131
152
|
- lib/sepa_rator/concerns/regulatory_reporting_validator.rb
|