Skip to content

Commit

Permalink
Add pain.001.001.09 and pain.008.001.08
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Schoknecht committed May 24, 2024
1 parent 41d5613 commit 46f0c4b
Show file tree
Hide file tree
Showing 10 changed files with 5,183 additions and 18 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ We love building payment applications! So after developing the [DTAUS library fo

This gem implements the following two messages out of the ISO 20022 standard:

* Credit Transfer Initiation (`pain.001.003.03`, `pain.001.002.03` and `pain.001.001.03`)
* Direct Debit Initiation (`pain.008.003.02`, `pain.008.002.02` and `pain.008.001.02`)
* Credit Transfer Initiation (`pain.001.003.03`, `pain.001.002.03`, `pain.001.001.03`, and `pain.001.001.09`)
* Direct Debit Initiation (`pain.008.003.02`, `pain.008.002.02`, `pain.008.001.02`, and `pain.008.001.08`)

It handles the _Specification of Data Formats_ v3.3 (2019-11-17).
It handles the _Specification of Data Formats_ v3.3 (2019-11-17) and partially v3.7 (2023-11-19).

BTW: **pain** is a shortcut for **Pa**yment **In**itiation.

Expand Down Expand Up @@ -118,7 +118,7 @@ sdd.add_transaction(

# OPTIONAL: Enables or disables batch booking, in German "Sammelbuchung / Einzelbuchung"
# True or False
batch_booking: true
batch_booking: true,

# OPTIONAL: Use a different creditor account
# CreditorAccount
Expand Down
2,423 changes: 2,423 additions & 0 deletions lib/schema/pain.001.001.09.xsd

Large diffs are not rendered by default.

2,705 changes: 2,705 additions & 0 deletions lib/schema/pain.008.001.08.xsd

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion lib/sepa_king/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

module SEPA
PAIN_008_001_02 = 'pain.008.001.02'
PAIN_008_001_08 = 'pain.008.001.08'
PAIN_008_002_02 = 'pain.008.002.02'
PAIN_008_003_02 = 'pain.008.003.02'
PAIN_001_001_03 = 'pain.001.001.03'
PAIN_001_001_09 = 'pain.001.001.09'
PAIN_001_002_03 = 'pain.001.002.03'
PAIN_001_003_03 = 'pain.001.003.03'
PAIN_001_001_03_CH_02 = 'pain.001.001.03.ch.02'
Expand Down Expand Up @@ -65,7 +67,7 @@ def schema_compatible?(schema_name)
case schema_name
when PAIN_001_002_03, PAIN_008_002_02
account.bic.present? && transactions.all? { |t| t.schema_compatible?(schema_name) }
when PAIN_001_001_03, PAIN_001_001_03_CH_02, PAIN_001_003_03, PAIN_008_003_02, PAIN_008_001_02
when PAIN_001_001_03, PAIN_001_001_09, PAIN_001_001_03_CH_02, PAIN_001_003_03, PAIN_008_003_02, PAIN_008_001_02, PAIN_008_001_08
transactions.all? { |t| t.schema_compatible?(schema_name) }
end
end
Expand Down
26 changes: 20 additions & 6 deletions lib/sepa_king/message/credit_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class CreditTransfer < Message
self.account_class = DebtorAccount
self.transaction_class = CreditTransferTransaction
self.xml_main_tag = 'CstmrCdtTrfInitn'
self.known_schemas = [ PAIN_001_001_03, PAIN_001_001_03_CH_02, PAIN_001_003_03, PAIN_001_002_03 ]
self.known_schemas = [ PAIN_001_001_03, PAIN_001_001_03_CH_02, PAIN_001_001_09, PAIN_001_003_03, PAIN_001_002_03 ]

private
# Find groups of transactions which share the same values of some attributes
Expand Down Expand Up @@ -39,7 +39,13 @@ def build_payment_informations(builder, schema_name)
end
end
end
builder.ReqdExctnDt(group[:requested_date].iso8601)
if schema_name == PAIN_001_001_09
builder.ReqdExctnDt do
builder.Dt(group[:requested_date].iso8601)
end
else
builder.ReqdExctnDt(group[:requested_date].to_date.iso8601)
end
builder.Dbtr do
builder.Nm(account.name)
end
Expand All @@ -51,7 +57,11 @@ def build_payment_informations(builder, schema_name)
builder.DbtrAgt do
builder.FinInstnId do
if account.bic
builder.BIC(account.bic)
if schema_name == PAIN_001_001_09
builder.BICFI(account.bic)
else
builder.BIC(account.bic)
end
elsif schema_name != PAIN_001_001_03_CH_02
builder.Othr do
builder.Id('NOTPROVIDED')
Expand All @@ -64,13 +74,13 @@ def build_payment_informations(builder, schema_name)
end

transactions.each do |transaction|
build_transaction(builder, transaction)
build_transaction(builder, transaction, schema_name)
end
end
end
end

def build_transaction(builder, transaction)
def build_transaction(builder, transaction, schema_name)
builder.CdtTrfTxInf do
builder.PmtId do
if transaction.instruction.present?
Expand All @@ -84,7 +94,11 @@ def build_transaction(builder, transaction)
if transaction.bic
builder.CdtrAgt do
builder.FinInstnId do
builder.BIC(transaction.bic)
if schema_name == PAIN_001_001_09
builder.BICFI(transaction.bic)
else
builder.BIC(transaction.bic)
end
end
end
end
Expand Down
18 changes: 13 additions & 5 deletions lib/sepa_king/message/direct_debit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DirectDebit < Message
self.account_class = CreditorAccount
self.transaction_class = DirectDebitTransaction
self.xml_main_tag = 'CstmrDrctDbtInitn'
self.known_schemas = [ PAIN_008_001_02, PAIN_008_003_02, PAIN_008_002_02 ]
self.known_schemas = [ PAIN_008_001_02, PAIN_008_001_08, PAIN_008_003_02, PAIN_008_002_02 ]

validate do |record|
if record.transactions.map(&:local_instrument).uniq.size > 1
Expand Down Expand Up @@ -54,7 +54,11 @@ def build_payment_informations(builder, schema_name)
builder.CdtrAgt do
builder.FinInstnId do
if group[:account].bic
builder.BIC(group[:account].bic)
if schema_name == PAIN_008_001_08
builder.BICFI(account.bic)
else
builder.BIC(account.bic)
end
else
builder.Othr do
builder.Id('NOTPROVIDED')
Expand All @@ -77,7 +81,7 @@ def build_payment_informations(builder, schema_name)
end

transactions.each do |transaction|
build_transaction(builder, transaction)
build_transaction(builder, transaction, schema_name)
end
end
end
Expand Down Expand Up @@ -123,7 +127,7 @@ def build_amendment_informations(builder, transaction)
end
end

def build_transaction(builder, transaction)
def build_transaction(builder, transaction, schema_name)
builder.DrctDbtTxInf do
builder.PmtId do
if transaction.instruction.present?
Expand All @@ -142,7 +146,11 @@ def build_transaction(builder, transaction)
builder.DbtrAgt do
builder.FinInstnId do
if transaction.bic
builder.BIC(transaction.bic)
if schema_name == PAIN_008_001_08
builder.BICFI(transaction.bic)
else
builder.BIC(transaction.bic)
end
else
builder.Othr do
builder.Id('NOTPROVIDED')
Expand Down
2 changes: 1 addition & 1 deletion lib/sepa_king/transaction/credit_transfer_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(attributes = {})

def schema_compatible?(schema_name)
case schema_name
when PAIN_001_001_03
when PAIN_001_001_03, PAIN_001_001_09
!self.service_level || (self.service_level == 'SEPA' && self.currency == 'EUR')
when PAIN_001_002_03
self.bic.present? && self.service_level == 'SEPA' && self.currency == 'EUR'
Expand Down
2 changes: 1 addition & 1 deletion lib/sepa_king/transaction/direct_debit_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def schema_compatible?(schema_name)
self.bic.present? && %w(CORE B2B).include?(self.local_instrument) && self.currency == 'EUR'
when PAIN_008_003_02
self.currency == 'EUR'
when PAIN_008_001_02
when PAIN_008_001_02, PAIN_008_001_08
true
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/credit_transfer_transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :currency => 'CHF')).to be_schema_compatible('pain.001.001.03.ch.02')
end
end

context 'for pain.001.001.09' do
it 'should succeed for valid attributes' do
expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :currency => 'EUR')).to be_schema_compatible('pain.001.001.09')
expect(SEPA::CreditTransferTransaction.new(:bic => nil)).to be_schema_compatible('pain.001.001.09')
end
end
end

context 'Requested date' do
Expand Down
6 changes: 6 additions & 0 deletions spec/direct_debit_transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
expect(SEPA::DirectDebitTransaction.new(:bic => 'SPUEDE2UXXX', :currency => 'CHF')).to be_schema_compatible('pain.008.001.02')
end
end

context 'for pain.008.001.08' do
it 'should succeed for valid attributes' do
expect(SEPA::DirectDebitTransaction.new(:bic => 'SPUEDE2UXXX', :currency => 'EUR')).to be_schema_compatible('pain.008.001.08')
end
end
end

context 'Mandate Date of Signature' do
Expand Down

0 comments on commit 46f0c4b

Please sign in to comment.