Skip to content
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
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Example:
"IBAN": "NL50BANK1234567890",
"BIC": "BANKNL2A",
"batch": True,
# "split_transactions": True, # optional, split transactions into different payments when batch booking is disabled. Default is 'True'. See https://github.com/raphaelm/python-sepaxml/issues/53
"creditor_id": "DE26ZZZ00000000000", # supplied by your bank or financial authority
"currency": "EUR", # ISO 4217
# "instrument": "B2B", # - default is CORE (B2C)
Expand Down Expand Up @@ -121,6 +122,7 @@ Example:
"IBAN": "NL50BANK1234567890",
"BIC": "BANKNL2A",
"batch": True,
# "split_transactions": True, # optional, split transactions into different payments when batch booking is disabled. Default is 'True'. See https://github.com/raphaelm/python-sepaxml/issues/53
# For non-SEPA transfers, set "domestic" to True, necessary e.g. for CH/LI
"currency": "EUR", # ISO 4217
"address": {
Expand Down
10 changes: 5 additions & 5 deletions sepaxml/debit.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def add_payment(self, payment):
self.check_payment(payment)

# Get the CstmrDrctDbtInitnNode
if not self._config['batch']:
if self._transaction_splitting:
# Start building the non batch payment
PmtInf_nodes = self._create_PmtInf_node()
PmtInf_nodes['PmtInfIdNode'].text = make_id(self._config['name'])
Expand Down Expand Up @@ -159,10 +159,10 @@ def add_payment(self, payment):
payment['endtoend_id'] = make_id(self._config['name'])
TX_nodes['EndToEndIdNode'].text = payment['endtoend_id'][:35]

if self._config['batch']:
self._add_batch(TX_nodes, payment)
else:
if self._transaction_splitting:
self._add_non_batch(TX_nodes, PmtInf_nodes)
else:
self._add_batch(TX_nodes, payment)

def _create_header(self):
"""
Expand Down Expand Up @@ -464,7 +464,7 @@ def _finalize_batch(self):
PmtInf_nodes = self._create_PmtInf_node()
PmtInf_nodes['PmtInfIdNode'].text = make_id(self._config['name'])
PmtInf_nodes['PmtMtdNode'].text = "DD"
PmtInf_nodes['BtchBookgNode'].text = "true"
PmtInf_nodes['BtchBookgNode'].text = str(self._config['batch']).lower()
PmtInf_nodes['Cd_SvcLvl_Node'].text = "SEPA"
PmtInf_nodes['Cd_LclInstrm_Node'].text = self._config['instrument']
PmtInf_nodes['SeqTpNode'].text = batch_meta_split[0]
Expand Down
2 changes: 2 additions & 0 deletions sepaxml/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def __init__(self, config, schema, clean=True):
if self._config.get('msg_id'):
self.msg_id = self._config['msg_id'][:35]

self._transaction_splitting = self._config.get('split_transactions', True) and not self._config['batch']

self._prepare_document()
self._create_header()

Expand Down
10 changes: 5 additions & 5 deletions sepaxml/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def add_payment(self, payment):
payment['description'] = unidecode(payment['description'])[:140]

# Get the CstmrDrctDbtInitnNode
if not self._config['batch']:
if self._transaction_splitting:
# Start building the non batch payment
PmtInf_nodes = self._create_PmtInf_node()
PmtInf_nodes['PmtInfIdNode'].text = make_id(self._config['name'])
Expand Down Expand Up @@ -160,10 +160,10 @@ def add_payment(self, payment):
TX_nodes['IBAN_CdtrAcct_Node'].text = payment['IBAN']
TX_nodes['UstrdNode'].text = payment['description']

if self._config['batch']:
self._add_batch(TX_nodes, payment)
else:
if self._transaction_splitting:
self._add_non_batch(TX_nodes, PmtInf_nodes)
else:
self._add_batch(TX_nodes, payment)

def _create_header(self):
"""
Expand Down Expand Up @@ -397,7 +397,7 @@ def _finalize_batch(self):
PmtInf_nodes = self._create_PmtInf_node()
PmtInf_nodes['PmtInfIdNode'].text = make_id(self._config['name'])
PmtInf_nodes['PmtMtdNode'].text = "TRF"
PmtInf_nodes['BtchBookgNode'].text = "true"
PmtInf_nodes['BtchBookgNode'].text = str(self._config['batch']).lower()
if not self._config.get('domestic', False):
PmtInf_nodes['Cd_SvcLvl_Node'].text = "SEPA"

Expand Down
92 changes: 88 additions & 4 deletions tests/debit/test_non_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def sdd():
<GrpHdr>
<MsgId>20012017014921-ba2dab283fdd</MsgId>
<CreDtTm>2017-01-20T13:49:21</CreDtTm>
<NbOfTxs>2</NbOfTxs>
<CtrlSum>60.12</CtrlSum>
<NbOfTxs>3</NbOfTxs>
<CtrlSum>103.33</CtrlSum>
<InitgPty>
<Nm>TestCreditor</Nm>
<Id>
Expand Down Expand Up @@ -122,7 +122,7 @@ def sdd():
<LclInstrm>
<Cd>CORE</Cd>
</LclInstrm>
<SeqTp>RCUR</SeqTp>
<SeqTp>FRST</SeqTp>
</PmtTpInf>
<ReqdColltnDt>2017-01-20</ReqdColltnDt>
<Cdtr>
Expand Down Expand Up @@ -181,6 +181,78 @@ def sdd():
</RmtInf>
</DrctDbtTxInf>
</PmtInf>
<PmtInf>
<PmtInfId>TestCreditor-d547a1b3882f</PmtInfId>
<PmtMtd>DD</PmtMtd>
<BtchBookg>false</BtchBookg>
<NbOfTxs>1</NbOfTxs>
<CtrlSum>43.21</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>
<BIC>BANKNL2A</BIC>
</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">43.21</InstdAmt>
<DrctDbtTx>
<MndtRltdInf>
<MndtId>1234</MndtId>
<DtOfSgntr>2017-01-20</DtOfSgntr>
<AmdmntInd>false</AmdmntInd>
</MndtRltdInf>
</DrctDbtTx>
<DbtrAgt>
<FinInstnId>
<BIC>BANKNL2A</BIC>
</FinInstnId>
</DbtrAgt>
<Dbtr>
<Nm>Test du Test 2</Nm>
</Dbtr>
<DbtrAcct>
<Id>
<IBAN>NL50BANK1234567890</IBAN>
</Id>
</DbtrAcct>
<RmtInf>
<Ustrd>Test transaction3</Ustrd>
</RmtInf>
</DrctDbtTxInf>
</PmtInf>
</CstmrDrctDbtInitn>
</Document>
"""
Expand All @@ -203,15 +275,27 @@ def test_two_debits(sdd):
"IBAN": "NL50BANK1234567890",
"BIC": "BANKNL2A",
"amount": 5000,
"type": "RCUR",
"type": "FRST",
"collection_date": datetime.date.today(),
"mandate_id": "1234",
"mandate_date": datetime.date.today(),
"description": "Test transaction2"
}
payment3 = {
"name": "Test du Test 2",
"IBAN": "NL50BANK1234567890",
"BIC": "BANKNL2A",
"amount": 4321,
"type": "RCUR",
"collection_date": datetime.date.today(),
"mandate_id": "1234",
"mandate_date": datetime.date.today(),
"description": "Test transaction3"
}

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