sepa_rator 2.0.2 → 2.1.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/lib/sepa_rator/account/address.rb +3 -2
- data/lib/sepa_rator/account/contact_details.rb +1 -0
- data/lib/sepa_rator/account/debtor_account.rb +2 -2
- data/lib/sepa_rator/account.rb +1 -0
- data/lib/sepa_rator/charset.rb +87 -0
- data/lib/sepa_rator/concerns/charset_applicable.rb +35 -0
- data/lib/sepa_rator/concerns/regulatory_reporting_charset.rb +46 -0
- data/lib/sepa_rator/converter.rb +26 -20
- data/lib/sepa_rator/message.rb +16 -9
- data/lib/sepa_rator/profile.rb +1 -1
- data/lib/sepa_rator/profiles/at.rb +2 -0
- data/lib/sepa_rator/profiles/dk.rb +2 -0
- data/lib/sepa_rator/profiles/epc.rb +8 -9
- data/lib/sepa_rator/profiles/gb.rb +1 -0
- data/lib/sepa_rator/profiles/iso.rb +3 -2
- data/lib/sepa_rator/profiles/sps.rb +1 -0
- data/lib/sepa_rator/transaction/credit_transfer_transaction.rb +20 -2
- data/lib/sepa_rator/transaction.rb +11 -3
- data/lib/sepa_rator/version.rb +1 -1
- data/lib/sepa_rator.rb +3 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 49df91223ab71149cc5e6abe1d64c9a447ecfd0afc8973848f0d6c3fc3666dd3
|
|
4
|
+
data.tar.gz: 9e5c32f7881616f5ad7f020195ddde9c1a6c7bff94771342a2f18e617de93eae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9aeced9ae51bc70f1128dcdcd9ca0e153b9622fd1360272185e89671eb71bba0ab09c292f7bb86a4e6f23165b7d6070891bb11b83e461c0f5f6dfd70d443d66c
|
|
7
|
+
data.tar.gz: 46b2151061a3478b7b80dc10aa9b1d9823584a405fcca382548cbf05d8c04235ae60963027579eb9fe88920666782e25616018fd3e079bf8628471876551cff4
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
module SEPA
|
|
4
4
|
class Address
|
|
5
5
|
include ActiveModel::Model
|
|
6
|
+
include CharsetApplicable
|
|
6
7
|
extend Converter
|
|
7
8
|
|
|
8
9
|
# PostalAddress6 fields (all schemas)
|
|
@@ -31,7 +32,7 @@ module SEPA
|
|
|
31
32
|
convert :building_number, to: :text
|
|
32
33
|
convert :post_code, to: :text
|
|
33
34
|
convert :town_name, to: :text
|
|
34
|
-
convert :country_code, to: :
|
|
35
|
+
convert :country_code, to: :code
|
|
35
36
|
convert :address_line1, to: :text
|
|
36
37
|
convert :address_line2, to: :text
|
|
37
38
|
convert :department, to: :text
|
|
@@ -52,7 +53,7 @@ module SEPA
|
|
|
52
53
|
validates_length_of :building_number, maximum: 16
|
|
53
54
|
validates_length_of :post_code, maximum: 16
|
|
54
55
|
validates_length_of :town_name, maximum: 140
|
|
55
|
-
|
|
56
|
+
validates_format_of :country_code, with: /\A[A-Z]{2}\z/
|
|
56
57
|
validates_length_of :address_line1, maximum: 70
|
|
57
58
|
validates_length_of :address_line2, maximum: 70
|
|
58
59
|
validates_length_of :department, maximum: 70, allow_nil: true
|
|
@@ -4,8 +4,8 @@ module SEPA
|
|
|
4
4
|
class DebtorAccount < Account
|
|
5
5
|
attr_accessor :initiating_party_identifier, :initiating_party_scheme, :initiating_party_lei, :initiating_party_bic
|
|
6
6
|
|
|
7
|
-
convert :initiating_party_identifier, to: :
|
|
8
|
-
convert :initiating_party_scheme, to: :
|
|
7
|
+
convert :initiating_party_identifier, to: :identifier
|
|
8
|
+
convert :initiating_party_scheme, to: :identifier
|
|
9
9
|
# Max256Text (v13 GenericOrganisationIdentification3); stricter v03/v09
|
|
10
10
|
# limits are enforced by XSD validation at output time.
|
|
11
11
|
validates_length_of :initiating_party_identifier, within: 1..256, allow_nil: true
|
data/lib/sepa_rator/account.rb
CHANGED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SEPA
|
|
4
|
+
# Out-of-repertoire characters follow EPC217-08: §6.2 replacements, then
|
|
5
|
+
# one-to-one transliteration, else dropped.
|
|
6
|
+
class Charset
|
|
7
|
+
CONTROL_SPACES = /[\r\n\t]+/
|
|
8
|
+
CONTROLS = /[\x00-\x1F\x7F]/
|
|
9
|
+
MARKS = /\p{Mn}/
|
|
10
|
+
|
|
11
|
+
EPC_REPLACEMENTS = { '€' => 'E', '@' => '(at)', '_' => '-', '&' => '+', "\u00A0" => ' ' }.freeze
|
|
12
|
+
|
|
13
|
+
TRANSLITERATIONS = {
|
|
14
|
+
'ß' => 's', 'Æ' => 'A', 'æ' => 'a', 'Œ' => 'O', 'œ' => 'o', 'Ø' => 'O', 'ø' => 'o',
|
|
15
|
+
'Ł' => 'L', 'ł' => 'l', 'Đ' => 'D', 'đ' => 'd', 'Þ' => 'T', 'þ' => 't', 'Ð' => 'D', 'ð' => 'd', 'ı' => 'i'
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
IDENTIFIER_BODY = "A-Za-z0-9+?/:().,' -"
|
|
19
|
+
EPC_BODY = "A-Za-z0-9/?:().,'+ -"
|
|
20
|
+
DK_BODY = "ÄäÖöÜüß&*$%#{EPC_BODY}".freeze
|
|
21
|
+
AT_BODY = %q{A-Za-z0-9+/?:().,'äöüßÄÖÜ&><"|€$§%!=#~;*{}\[\]@\\\\_°\^ -}
|
|
22
|
+
SPS_BODY = "\u0020-\u007E\u00A0-\u00AC\u00AE-\u017F\u0218-\u021B\u20AC"
|
|
23
|
+
|
|
24
|
+
class Alphabet
|
|
25
|
+
def initialize(body)
|
|
26
|
+
@accepted = /\A[#{body}]*\z/
|
|
27
|
+
@rejected = /[^#{body}]/
|
|
28
|
+
freeze
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def fit(value)
|
|
32
|
+
return value if value.match?(@accepted)
|
|
33
|
+
|
|
34
|
+
value.gsub(@rejected) { |char| replacement(char) }.strip
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def replacement(char)
|
|
40
|
+
[EPC_REPLACEMENTS[char], TRANSLITERATIONS[char]].find { |candidate| candidate&.match?(@accepted) } ||
|
|
41
|
+
char.unicode_normalize(:nfd).gsub(MARKS, '').then { |base| base.match?(@accepted) ? base : '' }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
private_constant :Alphabet
|
|
45
|
+
|
|
46
|
+
attr_reader :id
|
|
47
|
+
|
|
48
|
+
def self.sanitize(value)
|
|
49
|
+
return if value.nil?
|
|
50
|
+
|
|
51
|
+
value.to_s
|
|
52
|
+
.encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
|
|
53
|
+
.scrub('')
|
|
54
|
+
.gsub(CONTROL_SPACES, ' ')
|
|
55
|
+
.gsub(CONTROLS, '')
|
|
56
|
+
.strip
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def initialize(charset_id, text_body)
|
|
60
|
+
@id = charset_id
|
|
61
|
+
@text = text_body && Alphabet.new(text_body)
|
|
62
|
+
@identifier = text_body && Alphabet.new(IDENTIFIER_BODY)
|
|
63
|
+
freeze
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def text(value)
|
|
67
|
+
fit(@text, value)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def identifier(value)
|
|
71
|
+
fit(@identifier, value)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
ISO = new(:iso, nil)
|
|
75
|
+
EPC = new(:epc, EPC_BODY)
|
|
76
|
+
DK = new(:dk, DK_BODY)
|
|
77
|
+
AT = new(:at, AT_BODY)
|
|
78
|
+
SPS = new(:sps, SPS_BODY)
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
def fit(alphabet, value)
|
|
83
|
+
sanitized = self.class.sanitize(value)
|
|
84
|
+
alphabet && sanitized ? alphabet.fit(sanitized) : sanitized
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SEPA
|
|
4
|
+
module CharsetApplicable
|
|
5
|
+
def apply_charset(charset)
|
|
6
|
+
self.class.text_attributes.each { |attribute| convert_attribute(attribute, charset, :text) }
|
|
7
|
+
self.class.identifier_attributes.each { |attribute| convert_attribute(attribute, charset, :identifier) }
|
|
8
|
+
each_nested_model { |_name, nested| nested.apply_charset(charset) }
|
|
9
|
+
self
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# One copy per caller object: conversion must never mutate caller objects,
|
|
13
|
+
# and direct debit groups compare accounts by identity.
|
|
14
|
+
def detach_nested_models(copies)
|
|
15
|
+
each_nested_model do |name, nested|
|
|
16
|
+
instance_variable_set(name, copies[nested] ||= nested.dup.detach_nested_models(copies))
|
|
17
|
+
end
|
|
18
|
+
self
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def each_nested_model
|
|
24
|
+
instance_variables.each do |name|
|
|
25
|
+
nested = instance_variable_get(name)
|
|
26
|
+
yield name, nested if nested.respond_to?(:apply_charset)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def convert_attribute(attribute, charset, kind)
|
|
31
|
+
name = :"@#{attribute}"
|
|
32
|
+
instance_variable_set(name, charset.public_send(kind, instance_variable_get(name)))
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SEPA
|
|
4
|
+
module RegulatoryReportingCharset
|
|
5
|
+
private
|
|
6
|
+
|
|
7
|
+
def charset_regulatory_reportings(reportings, charset)
|
|
8
|
+
return reportings unless reportings.is_a?(Array)
|
|
9
|
+
|
|
10
|
+
reportings.map do |reporting|
|
|
11
|
+
next reporting unless reporting.is_a?(Hash)
|
|
12
|
+
|
|
13
|
+
reporting.merge(
|
|
14
|
+
authority: charset_authority(reporting[:authority], charset),
|
|
15
|
+
details: charset_details(reporting[:details], charset)
|
|
16
|
+
).compact
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def charset_authority(authority, charset)
|
|
21
|
+
return authority unless authority.is_a?(Hash) && authority[:name]
|
|
22
|
+
|
|
23
|
+
authority.merge(name: charset.text(authority[:name]))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def charset_details(details, charset)
|
|
27
|
+
return details unless details.is_a?(Array)
|
|
28
|
+
|
|
29
|
+
details.map do |detail|
|
|
30
|
+
next detail unless detail.is_a?(Hash)
|
|
31
|
+
|
|
32
|
+
detail.merge(
|
|
33
|
+
type: charset.text(detail[:type]),
|
|
34
|
+
type_proprietary: charset.text(detail[:type_proprietary]),
|
|
35
|
+
information: charset_information(detail[:information], charset)
|
|
36
|
+
).compact
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def charset_information(information, charset)
|
|
41
|
+
return charset.text(information) unless information.is_a?(Array)
|
|
42
|
+
|
|
43
|
+
information.map { |entry| charset.text(entry) }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/lib/sepa_rator/converter.rb
CHANGED
|
@@ -2,36 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
module SEPA
|
|
4
4
|
module Converter
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
KINDS = %i[text identifier code decimal].freeze
|
|
6
|
+
|
|
7
|
+
def convert(*attributes, **options)
|
|
8
|
+
to = options.fetch(:to)
|
|
9
|
+
raise ArgumentError, "Converter '#{to}' does not exist!" unless KINDS.include?(to)
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
raise ArgumentError, "Converter '#{options[:to]}' does not exist!" unless InstanceMethods.method_defined?(method_name)
|
|
11
|
+
include InstanceMethods
|
|
10
12
|
|
|
13
|
+
converted_attributes[to]&.concat(attributes)
|
|
11
14
|
attributes.each do |attribute|
|
|
12
15
|
define_method "#{attribute}=" do |value|
|
|
13
|
-
instance_variable_set("@#{attribute}",
|
|
16
|
+
instance_variable_set("@#{attribute}", to == :decimal ? convert_decimal(value) : Charset.sanitize(value))
|
|
14
17
|
end
|
|
15
18
|
end
|
|
16
19
|
end
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
def text_attributes
|
|
22
|
+
inherited_attributes(:text)
|
|
23
|
+
end
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.gsub(%r{[^a-zA-Z0-9\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F ':?,\-(+.)/]}, '')
|
|
32
|
-
.strip
|
|
33
|
-
end
|
|
25
|
+
def identifier_attributes
|
|
26
|
+
inherited_attributes(:identifier)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def converted_attributes
|
|
32
|
+
@converted_attributes ||= { text: [], identifier: [] }
|
|
33
|
+
end
|
|
34
34
|
|
|
35
|
+
def inherited_attributes(kind)
|
|
36
|
+
parent = superclass.respond_to?(:text_attributes) ? superclass.public_send(:"#{kind}_attributes") : []
|
|
37
|
+
(parent + converted_attributes[kind]).freeze
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
module InstanceMethods
|
|
35
41
|
def convert_decimal(value)
|
|
36
42
|
return unless value
|
|
37
43
|
|
data/lib/sepa_rator/message.rb
CHANGED
|
@@ -10,8 +10,7 @@ module SEPA
|
|
|
10
10
|
# Root element inside <Document>. Overridden by subclasses.
|
|
11
11
|
XML_MAIN_TAG = nil
|
|
12
12
|
|
|
13
|
-
attr_reader :account, :grouped_transactions, :profile, :initiation_source_name
|
|
14
|
-
attr_accessor :initiation_source_provider
|
|
13
|
+
attr_reader :account, :grouped_transactions, :profile, :initiation_source_name, :initiation_source_provider
|
|
15
14
|
|
|
16
15
|
def initiation_source_name=(value)
|
|
17
16
|
if value && !profile.supports?(:initiation_source)
|
|
@@ -19,7 +18,11 @@ module SEPA
|
|
|
19
18
|
"[#{profile.id}] initiation_source_name is set but the profile does not support InitnSrc"
|
|
20
19
|
end
|
|
21
20
|
|
|
22
|
-
@initiation_source_name = value
|
|
21
|
+
@initiation_source_name = charset.text(value)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def initiation_source_provider=(value)
|
|
25
|
+
@initiation_source_provider = charset.text(value)
|
|
23
26
|
end
|
|
24
27
|
|
|
25
28
|
validates_presence_of :transactions
|
|
@@ -48,7 +51,7 @@ module SEPA
|
|
|
48
51
|
def initialize(country: nil, version: :latest, profile: nil, **account_options)
|
|
49
52
|
@profile = resolve_profile(country: country, version: version, profile: profile)
|
|
50
53
|
@grouped_transactions = {}
|
|
51
|
-
@account = account_class.new(account_options)
|
|
54
|
+
@account = admit(account_class.new(account_options))
|
|
52
55
|
validate_message_against_profile!
|
|
53
56
|
validate_account_against_profile!(@account)
|
|
54
57
|
end
|
|
@@ -60,14 +63,13 @@ module SEPA
|
|
|
60
63
|
# @param options [Hash] transaction attributes
|
|
61
64
|
# @raise [SEPA::ValidationError] if the transaction is invalid
|
|
62
65
|
def add_transaction(options)
|
|
63
|
-
transaction = transaction_class.new(options)
|
|
66
|
+
transaction = admit(transaction_class.new(options))
|
|
64
67
|
raise SEPA::ValidationError, transaction.errors.full_messages.join("\n") unless transaction.valid?
|
|
65
68
|
|
|
66
69
|
validate_transaction_against_profile!(transaction)
|
|
67
70
|
|
|
68
71
|
group = transaction_group(transaction)
|
|
69
|
-
@grouped_transactions[group] ||= []
|
|
70
|
-
@grouped_transactions[group] << transaction
|
|
72
|
+
(@grouped_transactions[group] ||= []) << transaction
|
|
71
73
|
@transactions = nil
|
|
72
74
|
end
|
|
73
75
|
|
|
@@ -82,10 +84,11 @@ module SEPA
|
|
|
82
84
|
# @raise [SEPA::ValidationError] if the message or account is invalid
|
|
83
85
|
# @raise [SEPA::SchemaValidationError] if the generated XML fails XSD validation
|
|
84
86
|
def to_xml
|
|
85
|
-
raise SEPA::ValidationError, errors.full_messages.join("\n") unless valid?
|
|
86
|
-
|
|
87
87
|
# Fail-safe against post-insertion mutations of the account or
|
|
88
88
|
# transactions (e.g. a caller flipping `currency` after adding).
|
|
89
|
+
[@account, *transactions].each { |model| model.apply_charset(charset) }
|
|
90
|
+
raise SEPA::ValidationError, errors.full_messages.join("\n") unless valid?
|
|
91
|
+
|
|
89
92
|
validate_message_against_profile!
|
|
90
93
|
validate_account_against_profile!(@account)
|
|
91
94
|
transactions.each { |transaction| validate_transaction_against_profile!(transaction) }
|
|
@@ -157,6 +160,10 @@ module SEPA
|
|
|
157
160
|
|
|
158
161
|
private
|
|
159
162
|
|
|
163
|
+
def charset = profile.features.charset
|
|
164
|
+
|
|
165
|
+
def admit(model) = model.detach_nested_models(@nested_copies ||= {}.compare_by_identity).apply_charset(charset)
|
|
166
|
+
|
|
160
167
|
# Single entry point for validating a transaction against the message's
|
|
161
168
|
# profile. Called both from `add_transaction` (at insertion) and from
|
|
162
169
|
# `to_xml` (as a fail-safe against post-insertion mutations).
|
data/lib/sepa_rator/profile.rb
CHANGED
|
@@ -25,7 +25,7 @@ module SEPA
|
|
|
25
25
|
instr_for_dbtr_agt_format: :text,
|
|
26
26
|
instr_for_cdtr_agt_code_type: :instruction3_code,
|
|
27
27
|
regulatory_reporting_version: :v3,
|
|
28
|
-
charset:
|
|
28
|
+
charset: Charset::ISO,
|
|
29
29
|
min_amount: nil,
|
|
30
30
|
requires_structured_address: false,
|
|
31
31
|
requires_country_code_on_address: false,
|
|
@@ -19,6 +19,7 @@ module SEPA
|
|
|
19
19
|
VALIDATORS = [Validators::MinAmount].freeze
|
|
20
20
|
|
|
21
21
|
FEATURES = {
|
|
22
|
+
charset: Charset::AT,
|
|
22
23
|
min_amount: BigDecimal('0.01'),
|
|
23
24
|
requires_structured_address: true
|
|
24
25
|
}.freeze
|
|
@@ -26,6 +27,7 @@ module SEPA
|
|
|
26
27
|
# PSA v03/v02 PostalAddress6 only supports Ctry + AdrLine, not the
|
|
27
28
|
# full structured fields — so we must not require structured addresses.
|
|
28
29
|
LEGACY_FEATURES = {
|
|
30
|
+
charset: Charset::AT,
|
|
29
31
|
min_amount: BigDecimal('0.01')
|
|
30
32
|
}.freeze
|
|
31
33
|
|
|
@@ -11,6 +11,7 @@ module SEPA
|
|
|
11
11
|
VALIDATORS = [Validators::DK::MinAmount].freeze
|
|
12
12
|
|
|
13
13
|
FEATURES = {
|
|
14
|
+
charset: Charset::DK,
|
|
14
15
|
min_amount: BigDecimal('0.01'),
|
|
15
16
|
requires_structured_address: true
|
|
16
17
|
}.freeze
|
|
@@ -18,6 +19,7 @@ module SEPA
|
|
|
18
19
|
# GBIC3 (v03/v02) PostalAddressSEPA only supports Ctry + AdrLine,
|
|
19
20
|
# not structured fields — so we must not require structured addresses.
|
|
20
21
|
LEGACY_FEATURES = {
|
|
22
|
+
charset: Charset::DK,
|
|
21
23
|
min_amount: BigDecimal('0.01')
|
|
22
24
|
}.freeze
|
|
23
25
|
|
|
@@ -14,36 +14,35 @@ module SEPA
|
|
|
14
14
|
#
|
|
15
15
|
# EPC sits between ISO and the national layers (CFONB, DK/DFÜ). Country
|
|
16
16
|
# profiles that carry SEPA semantics compose from EPC, not from ISO.
|
|
17
|
-
#
|
|
18
|
-
# The SEPA character set is enforced at assignment time by the `Converter`
|
|
19
|
-
# DSL (text sanitisation), so no dedicated validator is needed here.
|
|
20
17
|
module EPC
|
|
18
|
+
FEATURES = { charset: Charset::EPC }.freeze
|
|
19
|
+
|
|
21
20
|
# ─── SEPA Credit Transfer ────────────────────────────────────────────
|
|
22
21
|
|
|
23
22
|
SCT_03 = ProfileRegistry.register(
|
|
24
|
-
ISO::SCT_03.with(id: 'epc.sct.03', accept_transaction: ISO::CT_EPC_RULES)
|
|
23
|
+
ISO::SCT_03.with(id: 'epc.sct.03', features: FEATURES, accept_transaction: ISO::CT_EPC_RULES)
|
|
25
24
|
)
|
|
26
25
|
|
|
27
26
|
SCT_09 = ProfileRegistry.register(
|
|
28
|
-
ISO::SCT_09.with(id: 'epc.sct.09', accept_transaction: ISO::CT_EPC_RULES)
|
|
27
|
+
ISO::SCT_09.with(id: 'epc.sct.09', features: FEATURES, accept_transaction: ISO::CT_EPC_RULES)
|
|
29
28
|
)
|
|
30
29
|
|
|
31
30
|
SCT_13 = ProfileRegistry.register(
|
|
32
|
-
ISO::SCT_13.with(id: 'epc.sct.13', accept_transaction: ISO::CT_EPC_RULES)
|
|
31
|
+
ISO::SCT_13.with(id: 'epc.sct.13', features: FEATURES, accept_transaction: ISO::CT_EPC_RULES)
|
|
33
32
|
)
|
|
34
33
|
|
|
35
34
|
# ─── SEPA Direct Debit ───────────────────────────────────────────────
|
|
36
35
|
|
|
37
36
|
SDD_02 = ProfileRegistry.register(
|
|
38
|
-
ISO::SDD_02.with(id: 'epc.sdd.02', accept_transaction: ISO::DD_EPC_RULES)
|
|
37
|
+
ISO::SDD_02.with(id: 'epc.sdd.02', features: FEATURES, accept_transaction: ISO::DD_EPC_RULES)
|
|
39
38
|
)
|
|
40
39
|
|
|
41
40
|
SDD_08 = ProfileRegistry.register(
|
|
42
|
-
ISO::SDD_08.with(id: 'epc.sdd.08', accept_transaction: ISO::DD_EPC_RULES)
|
|
41
|
+
ISO::SDD_08.with(id: 'epc.sdd.08', features: FEATURES, accept_transaction: ISO::DD_EPC_RULES)
|
|
43
42
|
)
|
|
44
43
|
|
|
45
44
|
SDD_12 = ProfileRegistry.register(
|
|
46
|
-
ISO::SDD_12.with(id: 'epc.sdd.12', accept_transaction: ISO::DD_EPC_RULES)
|
|
45
|
+
ISO::SDD_12.with(id: 'epc.sdd.12', features: FEATURES, accept_transaction: ISO::DD_EPC_RULES)
|
|
47
46
|
)
|
|
48
47
|
end
|
|
49
48
|
end
|
|
@@ -120,7 +120,7 @@ module SEPA
|
|
|
120
120
|
iso_schema: 'pain.001.002.03',
|
|
121
121
|
xsd_path: 'iso/pain.001.002.03.xsd',
|
|
122
122
|
namespace: 'urn:iso:std:iso:20022:tech:xsd:pain.001.002.03',
|
|
123
|
-
features: { requires_bic: true },
|
|
123
|
+
features: { requires_bic: true, charset: Charset::EPC },
|
|
124
124
|
# EPC AOS drops InstrForCdtrAgt, InstrForDbtrAgt and RgltryRptg —
|
|
125
125
|
# `{ replace: }` clears SCT_03's capabilities rather than appending.
|
|
126
126
|
capabilities: { replace: [].freeze },
|
|
@@ -214,7 +214,7 @@ module SEPA
|
|
|
214
214
|
iso_schema: 'pain.008.002.02',
|
|
215
215
|
xsd_path: 'iso/pain.008.002.02.xsd',
|
|
216
216
|
namespace: 'urn:iso:std:iso:20022:tech:xsd:pain.008.002.02',
|
|
217
|
-
features: { requires_bic: true },
|
|
217
|
+
features: { requires_bic: true, charset: Charset::EPC },
|
|
218
218
|
accept_transaction: DD_EPC_RULES
|
|
219
219
|
)
|
|
220
220
|
)
|
|
@@ -225,6 +225,7 @@ module SEPA
|
|
|
225
225
|
iso_schema: 'pain.008.003.02',
|
|
226
226
|
xsd_path: 'iso/pain.008.003.02.xsd',
|
|
227
227
|
namespace: 'urn:iso:std:iso:20022:tech:xsd:pain.008.003.02',
|
|
228
|
+
features: { charset: Charset::EPC },
|
|
228
229
|
accept_transaction: DD_EPC_RULES
|
|
229
230
|
)
|
|
230
231
|
)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
module SEPA
|
|
4
4
|
class CreditTransferTransaction < Transaction
|
|
5
5
|
include RegulatoryReportingValidator
|
|
6
|
+
include RegulatoryReportingCharset
|
|
6
7
|
|
|
7
8
|
attr_accessor :service_level,
|
|
8
9
|
:category_purpose,
|
|
@@ -35,8 +36,8 @@ module SEPA
|
|
|
35
36
|
validates_inclusion_of :charge_bearer, in: CHARGE_BEARERS, allow_nil: true
|
|
36
37
|
validates :creditor_address, :creditor_contact_details, nested_model: true, allow_nil: true
|
|
37
38
|
|
|
38
|
-
convert :debtor_agent_instruction, :instruction_for_debtor_agent,
|
|
39
|
-
|
|
39
|
+
convert :debtor_agent_instruction, :instruction_for_debtor_agent, to: :text
|
|
40
|
+
convert :credit_transfer_mandate_id, to: :identifier
|
|
40
41
|
|
|
41
42
|
validates_length_of :debtor_agent_instruction, within: 1..140, allow_nil: true
|
|
42
43
|
validates_length_of :instruction_for_debtor_agent, within: 1..140, allow_nil: true
|
|
@@ -60,6 +61,13 @@ module SEPA
|
|
|
60
61
|
self.service_level ||= 'SEPA' if currency == 'EUR'
|
|
61
62
|
end
|
|
62
63
|
|
|
64
|
+
def apply_charset(charset)
|
|
65
|
+
super
|
|
66
|
+
@regulatory_reportings = charset_regulatory_reportings(regulatory_reportings, charset)
|
|
67
|
+
@instructions_for_creditor_agent = charset_creditor_agent_instructions(charset)
|
|
68
|
+
self
|
|
69
|
+
end
|
|
70
|
+
|
|
63
71
|
def credit_transfer_mandate?
|
|
64
72
|
credit_transfer_mandate_id || credit_transfer_mandate_date_of_signature || credit_transfer_mandate_frequency
|
|
65
73
|
end
|
|
@@ -82,6 +90,16 @@ module SEPA
|
|
|
82
90
|
|
|
83
91
|
private
|
|
84
92
|
|
|
93
|
+
def charset_creditor_agent_instructions(charset)
|
|
94
|
+
return instructions_for_creditor_agent unless instructions_for_creditor_agent.is_a?(Array)
|
|
95
|
+
|
|
96
|
+
instructions_for_creditor_agent.map do |instruction|
|
|
97
|
+
next instruction unless instruction.is_a?(Hash) && instruction[:instruction_info]
|
|
98
|
+
|
|
99
|
+
instruction.merge(instruction_info: charset.text(instruction[:instruction_info]))
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
85
103
|
def requires_capability?(field_present, profile, capability)
|
|
86
104
|
!field_present || profile.supports?(capability)
|
|
87
105
|
end
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
module SEPA
|
|
4
4
|
class Transaction
|
|
5
5
|
include ActiveModel::Model
|
|
6
|
+
include CharsetApplicable
|
|
6
7
|
extend Converter
|
|
7
8
|
|
|
8
9
|
# Convention SEPA: 1999-01-01 signifies "execute as soon as possible" (ASAP).
|
|
@@ -31,9 +32,10 @@ module SEPA
|
|
|
31
32
|
:ultimate_debtor_name,
|
|
32
33
|
:ultimate_creditor_name
|
|
33
34
|
|
|
34
|
-
convert :name, :
|
|
35
|
-
:
|
|
36
|
-
|
|
35
|
+
convert :name, :remittance_information, :structured_remittance_issuer,
|
|
36
|
+
:ultimate_debtor_name, :ultimate_creditor_name, to: :text
|
|
37
|
+
convert :instruction, :reference, :structured_remittance_information, to: :identifier
|
|
38
|
+
convert :structured_remittance_reference_type, :purpose_code, to: :code
|
|
37
39
|
convert :amount, to: :decimal
|
|
38
40
|
|
|
39
41
|
validates_length_of :name, within: 1..70
|
|
@@ -83,6 +85,12 @@ module SEPA
|
|
|
83
85
|
self.currency ||= 'EUR'
|
|
84
86
|
end
|
|
85
87
|
|
|
88
|
+
def apply_charset(charset)
|
|
89
|
+
super
|
|
90
|
+
@additional_remittance_information = additional_remittance_information.map { |info| charset.text(info) } if additional_remittance_information.is_a?(Array)
|
|
91
|
+
self
|
|
92
|
+
end
|
|
93
|
+
|
|
86
94
|
# @return [Boolean] whether this transaction can be rendered under the
|
|
87
95
|
# given profile. Delegates to `profile.accepts?` for profile-level rules
|
|
88
96
|
# (e.g. EPC currency restrictions) and to `#compatible_capabilities?` for
|
data/lib/sepa_rator/version.rb
CHANGED
data/lib/sepa_rator.rb
CHANGED
|
@@ -6,11 +6,14 @@ require 'nokogiri'
|
|
|
6
6
|
require 'ibandit'
|
|
7
7
|
|
|
8
8
|
require 'sepa_rator/error'
|
|
9
|
+
require 'sepa_rator/charset'
|
|
9
10
|
require 'sepa_rator/profile'
|
|
10
11
|
require 'sepa_rator/builders/stage'
|
|
11
12
|
require 'sepa_rator/converter'
|
|
12
13
|
require 'sepa_rator/validator'
|
|
13
14
|
require 'sepa_rator/nested_model_validator'
|
|
15
|
+
require 'sepa_rator/concerns/charset_applicable'
|
|
16
|
+
require 'sepa_rator/concerns/regulatory_reporting_charset'
|
|
14
17
|
require 'sepa_rator/concerns/schema_validation'
|
|
15
18
|
require 'sepa_rator/concerns/xml_builder'
|
|
16
19
|
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.0
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Georg Leciejewski
|
|
@@ -125,6 +125,9 @@ files:
|
|
|
125
125
|
- lib/sepa_rator/builders/direct_debit/transaction/ultimate_creditor.rb
|
|
126
126
|
- lib/sepa_rator/builders/direct_debit/transaction/ultimate_debtor.rb
|
|
127
127
|
- lib/sepa_rator/builders/stage.rb
|
|
128
|
+
- lib/sepa_rator/charset.rb
|
|
129
|
+
- lib/sepa_rator/concerns/charset_applicable.rb
|
|
130
|
+
- lib/sepa_rator/concerns/regulatory_reporting_charset.rb
|
|
128
131
|
- lib/sepa_rator/concerns/regulatory_reporting_validator.rb
|
|
129
132
|
- lib/sepa_rator/concerns/schema_validation.rb
|
|
130
133
|
- lib/sepa_rator/concerns/xml_builder.rb
|