Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new PAIN versions #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ Limitations
Supported standards:

* SEPA PAIN.001.001.03
* SEPA PAIN.001.001.09
* SEPA PAIN.001.001.10
* SEPA PAIN.001.001.11
* SEPA PAIN.008.001.02
* SEPA PAIN.008.001.08
* SEPA PAIN.008.001.09
* SEPA PAIN.008.001.10

Usage
-----
Expand Down
10 changes: 8 additions & 2 deletions sepaxml/debit.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ def _create_PmtInf_node(self):
ED['CdtrAgtNode'] = ET.Element("CdtrAgt")
ED['FinInstnId_CdtrAgt_Node'] = ET.Element("FinInstnId")
if 'BIC' in self._config:
ED['BIC_CdtrAgt_Node'] = ET.Element("BIC")
if self.schema != 'pain.008.001.02':
ED['BIC_CdtrAgt_Node'] = ET.Element("BICFI")
else:
ED['BIC_CdtrAgt_Node'] = ET.Element("BIC")
else:
ED['Othr_CdtrAgt_Node'] = ET.Element("Othr")
ED['Id_CdtrAgt_Node'] = ET.Element("Id")
Expand Down Expand Up @@ -263,7 +266,10 @@ def _create_TX_node(self, bic=True):
ED['DbtrAgtNode'] = ET.Element("DbtrAgt")
ED['FinInstnId_DbtrAgt_Node'] = ET.Element("FinInstnId")
if bic:
ED['BIC_DbtrAgt_Node'] = ET.Element("BIC")
if self.schema != 'pain.008.001.02':
ED['BIC_DbtrAgt_Node'] = ET.Element("BICFI")
else:
ED['BIC_DbtrAgt_Node'] = ET.Element("BIC")
else:
ED['Id_DbtrAgt_Node'] = ET.Element("Id")
ED['Othr_DbtrAgt_Node'] = ET.Element("Othr")
Expand Down
1,114 changes: 1,114 additions & 0 deletions sepaxml/schemas/pain.001.001.09.xsd

Large diffs are not rendered by default.

1,241 changes: 1,241 additions & 0 deletions sepaxml/schemas/pain.001.001.10.xsd

Large diffs are not rendered by default.

1,244 changes: 1,244 additions & 0 deletions sepaxml/schemas/pain.001.001.11.xsd

Large diffs are not rendered by default.

1,106 changes: 1,106 additions & 0 deletions sepaxml/schemas/pain.008.001.08.xsd

Large diffs are not rendered by default.

1,125 changes: 1,125 additions & 0 deletions sepaxml/schemas/pain.008.001.09.xsd

Large diffs are not rendered by default.

1,128 changes: 1,128 additions & 0 deletions sepaxml/schemas/pain.008.001.10.xsd

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions sepaxml/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def add_payment(self, payment):
if not self._config.get('domestic', False):
PmtInf_nodes['Cd_SvcLvl_Node'].text = "SEPA"
if 'execution_date' in payment:
PmtInf_nodes['ReqdExctnDtNode'].text = payment['execution_date']
if self.schema == "pain.001.001.03":
PmtInf_nodes['ReqdExctnDtNode'].text = payment['execution_date']
else:
PmtInf_nodes['ReqdExctnDt_Dt_Node'].text = payment['execution_date']
else:
del PmtInf_nodes['ReqdExctnDtNode']

Expand Down Expand Up @@ -211,6 +214,7 @@ def _create_PmtInf_node(self):
ED['SvcLvlNode'] = ET.Element("SvcLvl")
ED['Cd_SvcLvl_Node'] = ET.Element("Cd")
ED['ReqdExctnDtNode'] = ET.Element("ReqdExctnDt")
ED['ReqdExctnDt_Dt_Node'] = ET.Element("Dt")

ED['DbtrNode'] = ET.Element("Dbtr")
ED['Nm_Dbtr_Node'] = ET.Element("Nm")
Expand All @@ -221,7 +225,10 @@ def _create_PmtInf_node(self):
ED['DbtrAgtNode'] = ET.Element("DbtrAgt")
ED['FinInstnId_DbtrAgt_Node'] = ET.Element("FinInstnId")
if 'BIC' in self._config:
ED['BIC_DbtrAgt_Node'] = ET.Element("BIC")
if self.schema != 'pain.001.001.03':
ED['BIC_DbtrAgt_Node'] = ET.Element("BICFI")
else:
ED['BIC_DbtrAgt_Node'] = ET.Element("BIC")
ED['ChrgBrNode'] = ET.Element("ChrgBr")
return ED

Expand All @@ -242,7 +249,10 @@ def _create_TX_node(self, bic=True):
ED['CdtrAgtNode'] = ET.Element("CdtrAgt")
ED['FinInstnId_CdtrAgt_Node'] = ET.Element("FinInstnId")
if bic:
ED['BIC_CdtrAgt_Node'] = ET.Element("BIC")
if self.schema != 'pain.001.001.03':
ED['BIC_CdtrAgt_Node'] = ET.Element("BICFI")
else:
ED['BIC_CdtrAgt_Node'] = ET.Element("BIC")
ED['CdtrAcctNode'] = ET.Element("CdtrAcct")
ED['Id_CdtrAcct_Node'] = ET.Element("Id")
ED['IBAN_CdtrAcct_Node'] = ET.Element("IBAN")
Expand All @@ -267,6 +277,8 @@ def _add_non_batch(self, TX_nodes, PmtInf_nodes):
PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['PmtTpInfNode'])
if 'ReqdExctnDtNode' in PmtInf_nodes:
PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['ReqdExctnDtNode'])
if self.schema != "pain.001.001.03":
PmtInf_nodes['ReqdExctnDtNode'].append(PmtInf_nodes['ReqdExctnDt_Dt_Node'])

PmtInf_nodes['DbtrNode'].append(PmtInf_nodes['Nm_Dbtr_Node'])
if PmtInf_nodes['PstlAdr_Dbtr_Node']:
Expand Down Expand Up @@ -376,7 +388,10 @@ def _finalize_batch(self):
PmtInf_nodes['Cd_SvcLvl_Node'].text = "SEPA"

if batch_meta:
PmtInf_nodes['ReqdExctnDtNode'].text = batch_meta
if self.schema == "pain.001.001.03":
PmtInf_nodes['ReqdExctnDtNode'].text = batch_meta
else:
PmtInf_nodes['ReqdExctnDt_Dt_Node'].text = batch_meta
else:
del PmtInf_nodes['ReqdExctnDtNode']
PmtInf_nodes['Nm_Dbtr_Node'].text = self._config['name']
Expand Down Expand Up @@ -412,6 +427,8 @@ def _finalize_batch(self):
PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['PmtTpInfNode'])
if 'ReqdExctnDtNode' in PmtInf_nodes:
PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['ReqdExctnDtNode'])
if self.schema != "pain.001.001.03":
PmtInf_nodes['ReqdExctnDtNode'].append(PmtInf_nodes['ReqdExctnDt_Dt_Node'])

PmtInf_nodes['DbtrNode'].append(PmtInf_nodes['Nm_Dbtr_Node'])
if PmtInf_nodes['PstlAdr_Dbtr_Node']:
Expand Down
216 changes: 216 additions & 0 deletions tests/debit/test_00800108.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import datetime

import pytest

from sepaxml import SepaDD
from sepaxml.validation import ValidationError
from tests.utils import clean_ids, validate_xml


@pytest.fixture
def sdd():
return SepaDD({
"name": "TestCreditor",
"IBAN": "NL50BANK1234567890",
"BIC": "BANKNL2A",
"batch": True,
"creditor_id": "DE26ZZZ00000000000",
"currency": "EUR"
}, schema="pain.008.001.08")


SAMPLE_RESULT = b"""
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.08" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CstmrDrctDbtInitn>
<GrpHdr>
<MsgId>20012017014921-ba2dab283fdd</MsgId>
<CreDtTm>2017-01-20T13:49:21</CreDtTm>
<NbOfTxs>2</NbOfTxs>
<CtrlSum>60.12</CtrlSum>
<InitgPty>
<Nm>TestCreditor</Nm>
<Id>
<OrgId>
<Othr>
<Id>DE26ZZZ00000000000</Id>
</Othr>
</OrgId>
</Id>
</InitgPty>
</GrpHdr>
<PmtInf>
<PmtInfId>TestCreditor-ecd6a2f680ce</PmtInfId>
<PmtMtd>DD</PmtMtd>
<BtchBookg>true</BtchBookg>
<NbOfTxs>1</NbOfTxs>
<CtrlSum>10.12</CtrlSum>
<PmtTpInf>
<SvcLvl>
<Cd>SEPA</Cd>
</SvcLvl>
<LclInstrm>
<Cd>CORE</Cd>
</LclInstrm>
<SeqTp>FRST</SeqTp>
</PmtTpInf>
<ReqdColltnDt>2017-01-20</ReqdColltnDt>
<Cdtr>
<Nm>TestCreditor</Nm>
</Cdtr>
<CdtrAcct>
<Id>
<IBAN>NL50BANK1234567890</IBAN>
</Id>
</CdtrAcct>
<CdtrAgt>
<FinInstnId>
<BICFI>BANKNL2A</BICFI>
</FinInstnId>
</CdtrAgt>
<ChrgBr>SLEV</ChrgBr>
<CdtrSchmeId>
<Id>
<PrvtId>
<Othr>
<Id>DE26ZZZ00000000000</Id>
<SchmeNm>
<Prtry>SEPA</Prtry>
</SchmeNm>
</Othr>
</PrvtId>
</Id>
</CdtrSchmeId>
<DrctDbtTxInf>
<PmtId>
<EndToEndId>TestCreditor-4431989789fb</EndToEndId>
</PmtId>
<InstdAmt Ccy="EUR">10.12</InstdAmt>
<DrctDbtTx>
<MndtRltdInf>
<MndtId>1234</MndtId>
<DtOfSgntr>2017-01-20</DtOfSgntr>
</MndtRltdInf>
</DrctDbtTx>
<DbtrAgt>
<FinInstnId>
<BICFI>BANKNL2A</BICFI>
</FinInstnId>
</DbtrAgt>
<Dbtr>
<Nm>Test von Testenstein</Nm>
</Dbtr>
<DbtrAcct>
<Id>
<IBAN>NL50BANK1234567890</IBAN>
</Id>
</DbtrAcct>
<RmtInf>
<Ustrd>Test transaction1</Ustrd>
</RmtInf>
</DrctDbtTxInf>
</PmtInf>
<PmtInf>
<PmtInfId>TestCreditor-d547a1b3882f</PmtInfId>
<PmtMtd>DD</PmtMtd>
<BtchBookg>true</BtchBookg>
<NbOfTxs>1</NbOfTxs>
<CtrlSum>50.00</CtrlSum>
<PmtTpInf>
<SvcLvl>
<Cd>SEPA</Cd>
</SvcLvl>
<LclInstrm>
<Cd>CORE</Cd>
</LclInstrm>
<SeqTp>RCUR</SeqTp>
</PmtTpInf>
<ReqdColltnDt>2017-01-20</ReqdColltnDt>
<Cdtr>
<Nm>TestCreditor</Nm>
</Cdtr>
<CdtrAcct>
<Id>
<IBAN>NL50BANK1234567890</IBAN>
</Id>
</CdtrAcct>
<CdtrAgt>
<FinInstnId>
<BICFI>BANKNL2A</BICFI>
</FinInstnId>
</CdtrAgt>
<ChrgBr>SLEV</ChrgBr>
<CdtrSchmeId>
<Id>
<PrvtId>
<Othr>
<Id>DE26ZZZ00000000000</Id>
<SchmeNm>
<Prtry>SEPA</Prtry>
</SchmeNm>
</Othr>
</PrvtId>
</Id>
</CdtrSchmeId>
<DrctDbtTxInf>
<PmtId>
<EndToEndId>TestCreditor-7e989083e265</EndToEndId>
</PmtId>
<InstdAmt Ccy="EUR">50.00</InstdAmt>
<DrctDbtTx>
<MndtRltdInf>
<MndtId>1234</MndtId>
<DtOfSgntr>2017-01-20</DtOfSgntr>
</MndtRltdInf>
</DrctDbtTx>
<DbtrAgt>
<FinInstnId>
<BICFI>BANKNL2A</BICFI>
</FinInstnId>
</DbtrAgt>
<Dbtr>
<Nm>Test du Test</Nm>
</Dbtr>
<DbtrAcct>
<Id>
<IBAN>NL50BANK1234567890</IBAN>
</Id>
</DbtrAcct>
<RmtInf>
<Ustrd>Test transaction2</Ustrd>
</RmtInf>
</DrctDbtTxInf>
</PmtInf>
</CstmrDrctDbtInitn>
</Document>
"""


def test_two_debits(sdd):
payment1 = {
"name": "Test von Testenstein",
"IBAN": "NL50BANK1234567890",
"BIC": "BANKNL2A",
"amount": 1012,
"type": "FRST",
"collection_date": datetime.date.today(),
"mandate_id": "1234",
"mandate_date": datetime.date.today(),
"description": "Test transaction1"
}
payment2 = {
"name": "Test du Test",
"IBAN": "NL50BANK1234567890",
"BIC": "BANKNL2A",
"amount": 5000,
"type": "RCUR",
"collection_date": datetime.date.today(),
"mandate_id": "1234",
"mandate_date": datetime.date.today(),
"description": "Test transaction2"
}

sdd.add_payment(payment1)
sdd.add_payment(payment2)
xmlout = sdd.export()
xmlpretty = validate_xml(xmlout, "pain.008.001.08")
assert clean_ids(xmlpretty.strip()).decode() == clean_ids(SAMPLE_RESULT.strip()).decode()
Loading