Debian Codegraph @

sepaxml/debit.py

raw symbols SCIP
1 """
2 Copyright (c) 2014 Congressus, The Netherlands
3 Copyright (c) 2017-2023 Raphael Michel and contributors
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is furnished
10 to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in all
13 copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 """
22 import datetime
23 import xml.etree.ElementTree as ET
24
25 from .shared import SepaPaymentInitn
26 from .utils import ADDRESS_MAPPING, int_to_decimal_str, make_id
27
28
29 class SepaDD(SepaPaymentInitn):
30 """
31 This class creates a Sepa Direct Debit XML File.
32 """
33 root_el = "CstmrDrctDbtInitn"
34
35 def __init__(self, config, schema="pain.008.001.02", clean=True):
36 if "instrument" not in config:
37 config["instrument"] = "CORE"
38 super().__init__(config, schema, clean)
39
40 def check_config(self, config):
41 """
42 Check the config file for required fields and validity.
43 @param config: The config dict.
44 @return: True if valid, error string if invalid paramaters where
45 encountered.
46 """
47 validation = ""
48 required = ["name", "IBAN", "batch", "creditor_id", "currency"]
49 if self.schema == 'pain.008.001.02':
50 required += ["BIC"]
51
52 for config_item in required:
53 if config_item not in config:
54 validation += config_item.upper() + "_MISSING "
55
56 if not validation:
57 return True
58 else:
59 raise Exception("Config file did not validate. " + validation)
60
61 def check_payment(self, payment):
62 """
63 Check the payment for required fields and validity.
64 @param payment: The payment dict
65 @return: True if valid, error string if invalid paramaters where
66 encountered.
67 """
68 validation = ""
69
70 if not isinstance(payment['amount'], int):
71 validation += "AMOUNT_NOT_INTEGER "
72
73 if not isinstance(payment['mandate_date'], datetime.date):
74 validation += "MANDATE_DATE_INVALID_OR_NOT_DATETIME_INSTANCE"
75 payment['mandate_date'] = str(payment['mandate_date'])
76
77 if not isinstance(payment['collection_date'], datetime.date):
78 validation += "COLLECTION_DATE_INVALID_OR_NOT_DATETIME_INSTANCE"
79 payment['collection_date'] = str(payment['collection_date'])
80
81 if validation == "":
82 return True
83 else:
84 raise Exception('Payment did not validate: ' + validation)
85
86 def add_payment(self, payment):
87 """
88 Function to add payments
89 @param payment: The payment dict
90 @raise exception: when payment is invalid
91 """
92 if self.clean:
93 from text_unidecode import unidecode
94
95 payment['name'] = unidecode(payment['name'])[:70]
96 payment['description'] = unidecode(payment['description'])[:140]
97
98 # Validate the payment
99 self.check_payment(payment)
100
101 # Get the CstmrDrctDbtInitnNode
102 if not self._config['batch']:
103 # Start building the non batch payment
104 PmtInf_nodes = self._create_PmtInf_node()
105 PmtInf_nodes['PmtInfIdNode'].text = make_id(self._config['name'])
106 PmtInf_nodes['PmtMtdNode'].text = "DD"
107 PmtInf_nodes['BtchBookgNode'].text = "false"
108 PmtInf_nodes['NbOfTxsNode'].text = "1"
109 PmtInf_nodes['CtrlSumNode'].text = int_to_decimal_str(
110 payment['amount'])
111 PmtInf_nodes['Cd_SvcLvl_Node'].text = "SEPA"
112 PmtInf_nodes['Cd_LclInstrm_Node'].text = self._config['instrument']
113 PmtInf_nodes['SeqTpNode'].text = payment['type']
114 PmtInf_nodes['ReqdColltnDtNode'].text = payment['collection_date']
115 PmtInf_nodes['Nm_Cdtr_Node'].text = self._config['name']
116 PmtInf_nodes['IBAN_CdtrAcct_Node'].text = self._config['IBAN']
117
118 if 'BIC' in self._config:
119 PmtInf_nodes['BIC_CdtrAgt_Node'].text = self._config['BIC']
120 else:
121 PmtInf_nodes['Id_CdtrAgt_Node'].text = "NOTPROVIDED"
122
123 PmtInf_nodes['ChrgBrNode'].text = "SLEV"
124 PmtInf_nodes['Id_Othr_Node'].text = self._config['creditor_id']
125 PmtInf_nodes['PrtryNode'].text = "SEPA"
126
127 if 'BIC' in payment:
128 bic = True
129 else:
130 bic = False
131
132 TX_nodes = self._create_TX_node(bic)
133 TX_nodes['InstdAmtNode'].set("Ccy", payment.get('currency', self._config['currency']))
134 TX_nodes['InstdAmtNode'].text = int_to_decimal_str(payment['amount'])
135
136 TX_nodes['MndtIdNode'].text = payment['mandate_id']
137 TX_nodes['DtOfSgntrNode'].text = payment['mandate_date']
138 if bic:
139 TX_nodes['BIC_DbtrAgt_Node'].text = payment['BIC']
140 else:
141 TX_nodes['Id_DbtrAgt_Node'].text = "NOTPROVIDED"
142
143 TX_nodes['Nm_Dbtr_Node'].text = payment['name']
144 if payment.get('address', {}):
145 for d, n in ADDRESS_MAPPING:
146 if payment['address'].get(d):
147 n = ET.Element(n)
148 n.text = payment['address'][d]
149 TX_nodes['PstlAdr_Dbtr_Node'].append(n)
150 for line in payment['address'].get('lines', []):
151 n = ET.Element('AdrLine')
152 n.text = line
153 TX_nodes['PstlAdr_Dbtr_Node'].append(n)
154
155 TX_nodes['IBAN_DbtrAcct_Node'].text = payment['IBAN']
156 TX_nodes['UstrdNode'].text = payment['description']
157 if not payment.get('endtoend_id', ''):
158 payment['endtoend_id'] = make_id(self._config['name'])
159 TX_nodes['EndToEndIdNode'].text = payment['endtoend_id']
160
161 if self._config['batch']:
162 self._add_batch(TX_nodes, payment)
163 else:
164 self._add_non_batch(TX_nodes, PmtInf_nodes)
165
166 def _create_header(self):
167 """
168 Function to create the GroupHeader (GrpHdr) in the
169 CstmrDrctDbtInit Node
170 """
171 # Retrieve the node to which we will append the group header.
172 CstmrDrctDbtInitn_node = self._xml.find('CstmrDrctDbtInitn')
173
174 # Create the header nodes.
175 GrpHdr_node = ET.Element("GrpHdr")
176 MsgId_node = ET.Element("MsgId")
177 CreDtTm_node = ET.Element("CreDtTm")
178 NbOfTxs_node = ET.Element("NbOfTxs")
179 CtrlSum_node = ET.Element("CtrlSum")
180 InitgPty_node = ET.Element("InitgPty")
181 Nm_node = ET.Element("Nm")
182 SupId_node = ET.Element("Id")
183 OrgId_node = ET.Element("OrgId")
184 Othr_node = ET.Element("Othr")
185 Id_node = ET.Element("Id")
186
187 # Add data to some header nodes.
188 MsgId_node.text = self.msg_id
189 CreDtTm_node.text = datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
190 Nm_node.text = self._config['name']
191 Id_node.text = self._config['creditor_id']
192
193 # Append the nodes
194 Othr_node.append(Id_node)
195 OrgId_node.append(Othr_node)
196 SupId_node.append(OrgId_node)
197 InitgPty_node.append(Nm_node)
198 InitgPty_node.append(SupId_node)
199 GrpHdr_node.append(MsgId_node)
200 GrpHdr_node.append(CreDtTm_node)
201 GrpHdr_node.append(NbOfTxs_node)
202 GrpHdr_node.append(CtrlSum_node)
203 GrpHdr_node.append(InitgPty_node)
204
205 # Append the header to its parent
206 CstmrDrctDbtInitn_node.append(GrpHdr_node)
207
208 def _create_PmtInf_node(self):
209 """
210 Method to create the blank payment information nodes as a dict.
211 """
212 ED = dict() # ED is element dict
213 ED['PmtInfNode'] = ET.Element("PmtInf")
214 ED['PmtInfIdNode'] = ET.Element("PmtInfId")
215 ED['PmtMtdNode'] = ET.Element("PmtMtd")
216 ED['BtchBookgNode'] = ET.Element("BtchBookg")
217 ED['NbOfTxsNode'] = ET.Element("NbOfTxs")
218 ED['CtrlSumNode'] = ET.Element("CtrlSum")
219 ED['PmtTpInfNode'] = ET.Element("PmtTpInf")
220 ED['SvcLvlNode'] = ET.Element("SvcLvl")
221 ED['Cd_SvcLvl_Node'] = ET.Element("Cd")
222 ED['LclInstrmNode'] = ET.Element("LclInstrm")
223 ED['Cd_LclInstrm_Node'] = ET.Element("Cd")
224 ED['SeqTpNode'] = ET.Element("SeqTp")
225 ED['ReqdColltnDtNode'] = ET.Element("ReqdColltnDt")
226 ED['CdtrNode'] = ET.Element("Cdtr")
227 ED['Nm_Cdtr_Node'] = ET.Element("Nm")
228 ED['PstlAdr_Cdtr_Node'] = ET.Element("PstlAdr")
229 ED['CdtrAcctNode'] = ET.Element("CdtrAcct")
230 ED['Id_CdtrAcct_Node'] = ET.Element("Id")
231 ED['IBAN_CdtrAcct_Node'] = ET.Element("IBAN")
232 ED['CdtrAgtNode'] = ET.Element("CdtrAgt")
233 ED['FinInstnId_CdtrAgt_Node'] = ET.Element("FinInstnId")
234 if 'BIC' in self._config:
235 if self.schema != 'pain.008.001.02':
236 ED['BIC_CdtrAgt_Node'] = ET.Element("BICFI")
237 else:
238 ED['BIC_CdtrAgt_Node'] = ET.Element("BIC")
239 else:
240 ED['Othr_CdtrAgt_Node'] = ET.Element("Othr")
241 ED['Id_CdtrAgt_Node'] = ET.Element("Id")
242 ED['ChrgBrNode'] = ET.Element("ChrgBr")
243 ED['CdtrSchmeIdNode'] = ET.Element("CdtrSchmeId")
244 ED['Id_CdtrSchmeId_Node'] = ET.Element("Id")
245 ED['PrvtIdNode'] = ET.Element("PrvtId")
246 ED['OthrNode'] = ET.Element("Othr")
247 ED['Id_Othr_Node'] = ET.Element("Id")
248 ED['SchmeNmNode'] = ET.Element("SchmeNm")
249 ED['PrtryNode'] = ET.Element("Prtry")
250 return ED
251
252 def _create_TX_node(self, bic=True):
253 """
254 Method to create the blank transaction nodes as a dict. If bic is True,
255 the BIC node will also be created.
256 """
257 ED = dict()
258 ED['DrctDbtTxInfNode'] = ET.Element("DrctDbtTxInf")
259 ED['PmtIdNode'] = ET.Element("PmtId")
260 ED['EndToEndIdNode'] = ET.Element("EndToEndId")
261 ED['InstdAmtNode'] = ET.Element("InstdAmt")
262 ED['DrctDbtTxNode'] = ET.Element("DrctDbtTx")
263 ED['MndtRltdInfNode'] = ET.Element("MndtRltdInf")
264 ED['MndtIdNode'] = ET.Element("MndtId")
265 ED['DtOfSgntrNode'] = ET.Element("DtOfSgntr")
266 ED['DbtrAgtNode'] = ET.Element("DbtrAgt")
267 ED['FinInstnId_DbtrAgt_Node'] = ET.Element("FinInstnId")
268 if bic:
269 if self.schema != 'pain.008.001.02':
270 ED['BIC_DbtrAgt_Node'] = ET.Element("BICFI")
271 else:
272 ED['BIC_DbtrAgt_Node'] = ET.Element("BIC")
273 else:
274 ED['Id_DbtrAgt_Node'] = ET.Element("Id")
275 ED['Othr_DbtrAgt_Node'] = ET.Element("Othr")
276 ED['DbtrNode'] = ET.Element("Dbtr")
277 ED['Nm_Dbtr_Node'] = ET.Element("Nm")
278 ED['PstlAdr_Dbtr_Node'] = ET.Element("PstlAdr")
279 ED['DbtrAcctNode'] = ET.Element("DbtrAcct")
280 ED['Id_DbtrAcct_Node'] = ET.Element("Id")
281 ED['IBAN_DbtrAcct_Node'] = ET.Element("IBAN")
282 ED['RmtInfNode'] = ET.Element("RmtInf")
283 ED['UstrdNode'] = ET.Element("Ustrd")
284 return ED
285
286 def _add_non_batch(self, TX_nodes, PmtInf_nodes):
287 """
288 Method to add a transaction as non batch, will fold the transaction
289 together with the payment info node and append to the main xml.
290 """
291 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['PmtInfIdNode'])
292 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['PmtMtdNode'])
293 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['BtchBookgNode'])
294 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['NbOfTxsNode'])
295 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CtrlSumNode'])
296
297 PmtInf_nodes['SvcLvlNode'].append(PmtInf_nodes['Cd_SvcLvl_Node'])
298 PmtInf_nodes['LclInstrmNode'].append(PmtInf_nodes['Cd_LclInstrm_Node'])
299 PmtInf_nodes['PmtTpInfNode'].append(PmtInf_nodes['SvcLvlNode'])
300 PmtInf_nodes['PmtTpInfNode'].append(PmtInf_nodes['LclInstrmNode'])
301 PmtInf_nodes['PmtTpInfNode'].append(PmtInf_nodes['SeqTpNode'])
302 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['PmtTpInfNode'])
303 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['ReqdColltnDtNode'])
304
305 PmtInf_nodes['CdtrNode'].append(PmtInf_nodes['Nm_Cdtr_Node'])
306 if PmtInf_nodes['PstlAdr_Cdtr_Node']:
307 PmtInf_nodes['CdtrNode'].append(PmtInf_nodes['PstlAdr_Cdtr_Node'])
308 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CdtrNode'])
309
310 PmtInf_nodes['Id_CdtrAcct_Node'].append(
311 PmtInf_nodes['IBAN_CdtrAcct_Node'])
312 PmtInf_nodes['CdtrAcctNode'].append(PmtInf_nodes['Id_CdtrAcct_Node'])
313 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CdtrAcctNode'])
314
315 if 'BIC' in self._config:
316 PmtInf_nodes['FinInstnId_CdtrAgt_Node'].append(
317 PmtInf_nodes['BIC_CdtrAgt_Node'])
318 else:
319 PmtInf_nodes['Othr_CdtrAgt_Node'].append(
320 PmtInf_nodes['Id_CdtrAgt_Node'])
321 PmtInf_nodes['FinInstnId_CdtrAgt_Node'].append(
322 PmtInf_nodes['Othr_CdtrAgt_Node'])
323
324 PmtInf_nodes['CdtrAgtNode'].append(
325 PmtInf_nodes['FinInstnId_CdtrAgt_Node'])
326 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CdtrAgtNode'])
327
328 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['ChrgBrNode'])
329
330 PmtInf_nodes['OthrNode'].append(PmtInf_nodes['Id_Othr_Node'])
331 PmtInf_nodes['SchmeNmNode'].append(PmtInf_nodes['PrtryNode'])
332 PmtInf_nodes['OthrNode'].append(PmtInf_nodes['SchmeNmNode'])
333 PmtInf_nodes['PrvtIdNode'].append(PmtInf_nodes['OthrNode'])
334 PmtInf_nodes['Id_CdtrSchmeId_Node'].append(PmtInf_nodes['PrvtIdNode'])
335 PmtInf_nodes['CdtrSchmeIdNode'].append(
336 PmtInf_nodes['Id_CdtrSchmeId_Node'])
337 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CdtrSchmeIdNode'])
338
339 TX_nodes['PmtIdNode'].append(TX_nodes['EndToEndIdNode'])
340 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['PmtIdNode'])
341 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['InstdAmtNode'])
342
343 TX_nodes['MndtRltdInfNode'].append(TX_nodes['MndtIdNode'])
344 TX_nodes['MndtRltdInfNode'].append(TX_nodes['DtOfSgntrNode'])
345 TX_nodes['DrctDbtTxNode'].append(TX_nodes['MndtRltdInfNode'])
346 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['DrctDbtTxNode'])
347
348 if 'BIC_DbtrAgt_Node' in TX_nodes and TX_nodes['BIC_DbtrAgt_Node'].text is not None:
349 TX_nodes['FinInstnId_DbtrAgt_Node'].append(
350 TX_nodes['BIC_DbtrAgt_Node'])
351 else:
352 TX_nodes['Othr_DbtrAgt_Node'].append(
353 TX_nodes['Id_DbtrAgt_Node'])
354 TX_nodes['FinInstnId_DbtrAgt_Node'].append(
355 TX_nodes['Othr_DbtrAgt_Node'])
356 TX_nodes['DbtrAgtNode'].append(TX_nodes['FinInstnId_DbtrAgt_Node'])
357 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['DbtrAgtNode'])
358
359 TX_nodes['DbtrNode'].append(TX_nodes['Nm_Dbtr_Node'])
360 if TX_nodes['PstlAdr_Dbtr_Node']:
361 TX_nodes['DbtrNode'].append(TX_nodes['PstlAdr_Dbtr_Node'])
362 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['DbtrNode'])
363
364 TX_nodes['Id_DbtrAcct_Node'].append(TX_nodes['IBAN_DbtrAcct_Node'])
365 TX_nodes['DbtrAcctNode'].append(TX_nodes['Id_DbtrAcct_Node'])
366 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['DbtrAcctNode'])
367
368 TX_nodes['RmtInfNode'].append(TX_nodes['UstrdNode'])
369 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['RmtInfNode'])
370 PmtInf_nodes['PmtInfNode'].append(TX_nodes['DrctDbtTxInfNode'])
371 CstmrDrctDbtInitn_node = self._xml.find('CstmrDrctDbtInitn')
372 CstmrDrctDbtInitn_node.append(PmtInf_nodes['PmtInfNode'])
373
374 def _add_batch(self, TX_nodes, payment):
375 """
376 Method to add a payment as a batch. The transaction details are already
377 present. Will fold the nodes accordingly and the call the
378 _add_to_batch_list function to store the batch.
379 """
380 TX_nodes['PmtIdNode'].append(TX_nodes['EndToEndIdNode'])
381 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['PmtIdNode'])
382 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['InstdAmtNode'])
383
384 TX_nodes['MndtRltdInfNode'].append(TX_nodes['MndtIdNode'])
385 TX_nodes['MndtRltdInfNode'].append(TX_nodes['DtOfSgntrNode'])
386 TX_nodes['DrctDbtTxNode'].append(TX_nodes['MndtRltdInfNode'])
387 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['DrctDbtTxNode'])
388
389 if 'BIC_DbtrAgt_Node' in TX_nodes and TX_nodes['BIC_DbtrAgt_Node'].text is not None:
390 TX_nodes['FinInstnId_DbtrAgt_Node'].append(
391 TX_nodes['BIC_DbtrAgt_Node'])
392 else:
393 TX_nodes['Othr_DbtrAgt_Node'].append(
394 TX_nodes['Id_DbtrAgt_Node'])
395 TX_nodes['FinInstnId_DbtrAgt_Node'].append(
396 TX_nodes['Othr_DbtrAgt_Node'])
397 TX_nodes['DbtrAgtNode'].append(TX_nodes['FinInstnId_DbtrAgt_Node'])
398 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['DbtrAgtNode'])
399
400 TX_nodes['DbtrNode'].append(TX_nodes['Nm_Dbtr_Node'])
401 if TX_nodes['PstlAdr_Dbtr_Node']:
402 TX_nodes['DbtrNode'].append(TX_nodes['PstlAdr_Dbtr_Node'])
403 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['DbtrNode'])
404
405 TX_nodes['Id_DbtrAcct_Node'].append(TX_nodes['IBAN_DbtrAcct_Node'])
406 TX_nodes['DbtrAcctNode'].append(TX_nodes['Id_DbtrAcct_Node'])
407 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['DbtrAcctNode'])
408
409 TX_nodes['RmtInfNode'].append(TX_nodes['UstrdNode'])
410 TX_nodes['DrctDbtTxInfNode'].append(TX_nodes['RmtInfNode'])
411 self._add_to_batch_list(TX_nodes, payment)
412
413 def _add_to_batch_list(self, TX, payment):
414 """
415 Method to add a transaction to the batch list. The correct batch will
416 be determined by the payment dict and the batch will be created if
417 not existant. This will also add the payment amount to the respective
418 batch total.
419 """
420 batch_key = payment['type'] + "::" + payment['collection_date']
421 if batch_key in self._batches.keys():
422 self._batches[batch_key].append(TX['DrctDbtTxInfNode'])
423 else:
424 self._batches[batch_key] = []
425 self._batches[batch_key].append(TX['DrctDbtTxInfNode'])
426
427 if batch_key in self._batch_totals:
428 self._batch_totals[batch_key] += payment['amount']
429 else:
430 self._batch_totals[batch_key] = payment['amount']
431
432 def _finalize_batch(self):
433 """
434 Method to finalize the batch, this will iterate over the _batches dict
435 and create a PmtInf node for each batch. The correct information (from
436 the batch_key and batch_totals) will be inserted and the batch
437 transaction nodes will be folded. Finally, the batches will be added to
438 the main XML.
439 """
440 for batch_meta, batch_nodes in self._batches.items():
441 batch_meta_split = batch_meta.split("::")
442 PmtInf_nodes = self._create_PmtInf_node()
443 PmtInf_nodes['PmtInfIdNode'].text = make_id(self._config['name'])
444 PmtInf_nodes['PmtMtdNode'].text = "DD"
445 PmtInf_nodes['BtchBookgNode'].text = "true"
446 PmtInf_nodes['Cd_SvcLvl_Node'].text = "SEPA"
447 PmtInf_nodes['Cd_LclInstrm_Node'].text = self._config['instrument']
448 PmtInf_nodes['SeqTpNode'].text = batch_meta_split[0]
449 PmtInf_nodes['ReqdColltnDtNode'].text = batch_meta_split[1]
450 PmtInf_nodes['Nm_Cdtr_Node'].text = self._config['name']
451 if self._config.get('address', {}):
452 for d, n in ADDRESS_MAPPING:
453 if self._config['address'].get(d):
454 n = ET.Element(n)
455 n.text = self._config['address'][d]
456 PmtInf_nodes['PstlAdr_Cdtr_Node'].append(n)
457 for line in self._config['address'].get('lines', []):
458 n = ET.Element('AdrLine')
459 n.text = line
460 PmtInf_nodes['PstlAdr_Cdtr_Node'].append(n)
461 PmtInf_nodes['IBAN_CdtrAcct_Node'].text = self._config['IBAN']
462
463 if 'BIC' in self._config:
464 PmtInf_nodes['BIC_CdtrAgt_Node'].text = self._config['BIC']
465 else:
466 PmtInf_nodes['Id_CdtrAgt_Node'].text = "NOTPROVIDED"
467
468 PmtInf_nodes['ChrgBrNode'].text = "SLEV"
469 PmtInf_nodes['Id_Othr_Node'].text = self._config['creditor_id']
470 PmtInf_nodes['PrtryNode'].text = "SEPA"
471
472 PmtInf_nodes['NbOfTxsNode'].text = str(len(batch_nodes))
473 PmtInf_nodes['CtrlSumNode'].text = int_to_decimal_str(self._batch_totals[batch_meta])
474
475 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['PmtInfIdNode'])
476 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['PmtMtdNode'])
477 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['BtchBookgNode'])
478 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['NbOfTxsNode'])
479 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CtrlSumNode'])
480
481 PmtInf_nodes['SvcLvlNode'].append(PmtInf_nodes['Cd_SvcLvl_Node'])
482 PmtInf_nodes['LclInstrmNode'].append(
483 PmtInf_nodes['Cd_LclInstrm_Node'])
484 PmtInf_nodes['PmtTpInfNode'].append(PmtInf_nodes['SvcLvlNode'])
485 PmtInf_nodes['PmtTpInfNode'].append(PmtInf_nodes['LclInstrmNode'])
486 PmtInf_nodes['PmtTpInfNode'].append(PmtInf_nodes['SeqTpNode'])
487 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['PmtTpInfNode'])
488 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['ReqdColltnDtNode'])
489
490 PmtInf_nodes['CdtrNode'].append(PmtInf_nodes['Nm_Cdtr_Node'])
491 if PmtInf_nodes['PstlAdr_Cdtr_Node']:
492 PmtInf_nodes['CdtrNode'].append(PmtInf_nodes['PstlAdr_Cdtr_Node'])
493 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CdtrNode'])
494
495 PmtInf_nodes['Id_CdtrAcct_Node'].append(
496 PmtInf_nodes['IBAN_CdtrAcct_Node'])
497 PmtInf_nodes['CdtrAcctNode'].append(
498 PmtInf_nodes['Id_CdtrAcct_Node'])
499 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CdtrAcctNode'])
500
501 if 'BIC' in self._config:
502 PmtInf_nodes['FinInstnId_CdtrAgt_Node'].append(
503 PmtInf_nodes['BIC_CdtrAgt_Node'])
504 else:
505 PmtInf_nodes['Othr_CdtrAgt_Node'].append(
506 PmtInf_nodes['Id_CdtrAgt_Node'])
507 PmtInf_nodes['FinInstnId_CdtrAgt_Node'].append(
508 PmtInf_nodes['Othr_CdtrAgt_Node'])
509
510 PmtInf_nodes['CdtrAgtNode'].append(
511 PmtInf_nodes['FinInstnId_CdtrAgt_Node'])
512 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CdtrAgtNode'])
513
514 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['ChrgBrNode'])
515
516 PmtInf_nodes['OthrNode'].append(PmtInf_nodes['Id_Othr_Node'])
517 PmtInf_nodes['SchmeNmNode'].append(PmtInf_nodes['PrtryNode'])
518 PmtInf_nodes['OthrNode'].append(PmtInf_nodes['SchmeNmNode'])
519 PmtInf_nodes['PrvtIdNode'].append(PmtInf_nodes['OthrNode'])
520 PmtInf_nodes['Id_CdtrSchmeId_Node'].append(
521 PmtInf_nodes['PrvtIdNode'])
522 PmtInf_nodes['CdtrSchmeIdNode'].append(
523 PmtInf_nodes['Id_CdtrSchmeId_Node'])
524 PmtInf_nodes['PmtInfNode'].append(PmtInf_nodes['CdtrSchmeIdNode'])
525
526 for txnode in batch_nodes:
527 PmtInf_nodes['PmtInfNode'].append(txnode)
528
529 CstmrDrctDbtInitn_node = self._xml.find('CstmrDrctDbtInitn')
530 CstmrDrctDbtInitn_node.append(PmtInf_nodes['PmtInfNode'])