Skip to content

Commit

Permalink
doc(pain001): updated content for v04
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Jun 19, 2023
1 parent 8a8941f commit fcd31c5
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 50 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ When running **Pain001**, you will need to specify four arguments:

The currently supported types are:
- pain.001.001.03
- pain.001.001.04
- pain.001.001.09
- An `xml_template_file_path`: This is the path to the XML template file you
are using that contains variables that will be replaced by the values in your
Expand Down
10 changes: 0 additions & 10 deletions pain001/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,6 @@ def check_variable(variable, name):
print(f"The data file '{data_file_path}' does not exist.")
sys.exit(1)

# Validate the XML file and raise a SystemExit exception if invalid
# is_valid = validate_via_xsd(
# xml_template_file_path, xsd_schema_file_path
# )
# if not is_valid:
# logger.error(
# f"Error: XML located at {xml_template_file_path} is invalid."
# )
# sys.exit(1)

process_files(
xml_message_type,
xml_template_file_path,
Expand Down
99 changes: 67 additions & 32 deletions pain001/xml/generate_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,37 @@


def create_common_elements(parent, row, mapping):
"""Create common elements "PmtInfId" and "PmtMtd" in the XML tree using
data from the CSV or SQLite Data Files.
Parameters
----------
parent : xml.etree.ElementTree.Element
Parent element in the XML tree.
row : list
List of strings, each string is a row of the Data file.
mapping : dict
Dictionary with the mapping between XML tags and Data columns.
"""

for xml_tag, csv_column in mapping.items():
if xml_tag in ["PmtInfId", "PmtMtd"]:
create_xml_element(parent, xml_tag, row[csv_column])


def create_xml_v3(root, data, mapping):
# print("XML v3")
"""Create the XML tree for the pain.001.001.03 schema.
Args:
root (ElementTree.Element): The root element of the XML tree.
data (list): A list of dictionaries containing the data to be added
to the XML document.
mapping (dict): A dictionary mapping the Data column names to the XML
element names.
Returns:
The root element of the XML tree.
"""

# Create CstmrCdtTrfInitn element
cstmr_cdt_trf_initn_element = ET.Element("CstmrCdtTrfInitn")
Expand Down Expand Up @@ -61,23 +85,23 @@ def create_xml_v3(root, data, mapping):
create_common_elements(PmtInf_element, row, mapping)

# Create new "BtchBookg" element in the XML tree using data
# from the CSV file
# from the Data file
create_xml_element(
PmtInf_element, "BtchBookg", row["batch_booking"].lower()
)

# Create new "NbOfTxs" element in the XML tree using data from
# the CSV file
# the Data file
create_xml_element(PmtInf_element, "NbOfTxs", row["nb_of_txs"])

# Create new "CtrlSum" element in the XML tree using data from
# the CSV file
# the Data file
create_xml_element(
PmtInf_element, "CtrlSum", f"{row['control_sum']}"
)

# Create new "PmtTpInf" element in the XML tree using data from
# the CSV file
# the Data file
PmtTpInf_element = ET.Element("PmtTpInf")
child_element = ET.Element("SvcLvl")
child_element2 = ET.Element("Cd")
Expand All @@ -87,23 +111,23 @@ def create_xml_v3(root, data, mapping):
PmtInf_element.append(PmtTpInf_element)

# Create new "ReqdExctnDt" element in the XML tree using data
# from the CSV file
# from the Data file
create_xml_element(
PmtInf_element,
"ReqdExctnDt",
row["requested_execution_date"],
)

# Create new "Dbtr" element in the XML tree using data from
# the CSV file
# the Data file
Dbtr_element = ET.Element("Dbtr")
child_element = ET.Element("Nm")
child_element.text = row["debtor_name"]
Dbtr_element.append(child_element)
PmtInf_element.append(Dbtr_element)

# Create new "DbtrAcct" element in the XML tree using data
# from the CSV file
# from the Data file
DbtrAcct_element = ET.Element("DbtrAcct")
child_element = ET.Element("Id")
child_element2 = ET.Element("IBAN")
Expand All @@ -114,7 +138,7 @@ def create_xml_v3(root, data, mapping):
PmtInf_element.append(DbtrAcct_element)

# Create new "DbtrAgt" element in the XML tree using data
# from the CSV file
# from the Data file
DbtrAgt_element = ET.Element("DbtrAgt")
child_element = ET.Element("FinInstnId")
child_element2 = ET.Element("BIC")
Expand All @@ -125,26 +149,26 @@ def create_xml_v3(root, data, mapping):
PmtInf_element.append(DbtrAgt_element)

# Create new "ChrgBr" element in the XML tree using data
# from the CSV file
# from the Data file
child_element = ET.Element("ChrgBr")
# replace with the appropriate value
child_element.text = row["charge_bearer"]
PmtInf_element.append(child_element)

# Create new "CdtTrfTxInf" element in the XML tree using data
# from the CSV file
# from the Data file
CdtTrfTxInf_element = ET.Element("CdtTrfTxInf")

# Create new "PmtId" element in the XML tree using data
# from the CSV file
# from the Data file
PmtId_element = ET.Element("PmtId")
child_element = ET.Element("EndToEndId")
child_element.text = row["payment_id"]
PmtId_element.append(child_element)
CdtTrfTxInf_element.append(PmtId_element)

# Create new "Amt" element in the XML tree using data
# from the CSV file
# from the Data file
Amt_element = ET.Element("Amt")
child_element = ET.Element("InstdAmt")
child_element.text = row["payment_amount"]
Expand All @@ -153,7 +177,7 @@ def create_xml_v3(root, data, mapping):
CdtTrfTxInf_element.append(Amt_element)

# Create new "CdtrAgt" element in the XML tree using data
# from the CSV file
# from the Data file
CdtrAgt_element = ET.Element("CdtrAgt")
child_element = ET.Element("FinInstnId")
child_element2 = ET.Element("BIC")
Expand All @@ -163,15 +187,15 @@ def create_xml_v3(root, data, mapping):
CdtTrfTxInf_element.append(CdtrAgt_element)

# Create new "Cdtr" element in the XML tree using data
# from the CSV file
# from the Data file
Cdtr_element = ET.Element("Cdtr")
child_element = ET.Element("Nm")
child_element.text = row["creditor_name"]
Cdtr_element.append(child_element)
CdtTrfTxInf_element.append(Cdtr_element)

# Create new "RmtInf" element in the XML tree using data
# from the CSV file
# from the Data file
RmtInf_element = ET.Element("RmtInf")
child_element = ET.Element("Ustrd")
child_element.text = row["remittance_information"]
Expand All @@ -191,7 +215,7 @@ def create_xml_v4(root, data, mapping):
Args:
root: The root element of the XML document.
data: A list of dictionaries containing the payment data.
mapping: A dictionary that maps XML element names to CSV column names.
mapping: A dictionary that maps XML element names to Data column names.
Returns:
The root element of the XML document.
Expand All @@ -205,7 +229,7 @@ def create_xml_v4(root, data, mapping):
GrpHdr_element = ET.Element("GrpHdr")
cstmr_cdt_trf_initn_element.append(GrpHdr_element)

# Loop through the first row of the CSV file and create new
# Loop through the first row of the Data file and create new
# "MsgId", "CreDtTm" and "NbOfTxs" elements in the XML tree
for xml_tag, csv_column in mapping.items():
if xml_tag in ["MsgId", "CreDtTm", "NbOfTxs"]:
Expand Down Expand Up @@ -319,7 +343,18 @@ def create_xml_v4(root, data, mapping):


def create_xml_v9(root, data, mapping):
print("XML v9")
"""Creates an XML document for the pain.001.001.09 schema.
Args:
root (ElementTree.Element): The root element of the XML tree.
data (list): A list of dictionaries containing the data to be added
to the XML document.
mapping (dict): A dictionary mapping the Data column names to the XML
element names.
Returns:
The root element of the XML tree.
"""

# Create CstmrCdtTrfInitn element
cstmr_cdt_trf_initn_element = ET.Element("CstmrCdtTrfInitn")
Expand All @@ -337,7 +372,7 @@ def create_xml_v9(root, data, mapping):
)

# Create new "InitgPty" element in the XML tree using data from the
# CSV file
# Data file
InitgPty_element = ET.Element("InitgPty")
create_xml_element(
InitgPty_element, "Nm", data[0]["initiator_name"]
Expand All @@ -346,7 +381,7 @@ def create_xml_v9(root, data, mapping):

for row in data:
# Create new "PmtInf" element in the XML tree using data from
# the CSV file
# the Data file
PmtInf_element = ET.Element("PmtInf")
cstmr_cdt_trf_initn_element.append(PmtInf_element)

Expand All @@ -359,15 +394,15 @@ def create_xml_v9(root, data, mapping):
PmtInf_element.append(Dbtr_element)

# Create new "Dbtr" element in the XML tree using data from
# the CSV file
# the Data file
Dbtr_element = ET.Element("Dbtr")
child_element = ET.Element("Nm")
child_element.text = row["debtor_name"]
Dbtr_element.append(child_element)
PmtInf_element.append(Dbtr_element)

# Create new "DbtrAcct" element in the XML tree using data
# from the CSV file
# from the Data file
DbtrAcct_element = ET.Element("DbtrAcct")
child_element = ET.Element("Id")
child_element2 = ET.Element("IBAN")
Expand All @@ -378,7 +413,7 @@ def create_xml_v9(root, data, mapping):
PmtInf_element.append(DbtrAcct_element)

# Create new "DbtrAgt" element in the XML tree using data
# from the CSV file
# from the Data file
DbtrAgt_element = ET.Element("DbtrAgt")
child_element = ET.Element("FinInstnId")
child_element2 = ET.Element("BICFI")
Expand All @@ -392,26 +427,26 @@ def create_xml_v9(root, data, mapping):
PmtInf_element.append(DbtrAgt_element)

# Create new "ChrgBr" element in the XML tree using data
# from the CSV file
# from the Data file
child_element = ET.Element("ChrgBr")
# replace with the appropriate value
child_element.text = row["charge_bearer"]
PmtInf_element.append(child_element)

# Create new "CdtTrfTxInf" element in the XML tree using data
# from the CSV file
# from the Data file
CdtTrfTxInf_element = ET.Element("CdtTrfTxInf")

# Create new "PmtId" element in the XML tree using data
# from the CSV file
# from the Data file
PmtId_element = ET.Element("PmtId")
child_element = ET.Element("EndToEndId")
child_element.text = row["payment_id"]
PmtId_element.append(child_element)
CdtTrfTxInf_element.append(PmtId_element)

# Create new "Amt" element in the XML tree using data
# from the CSV file
# from the Data file
Amt_element = ET.Element("Amt")
child_element = ET.Element("InstdAmt")
child_element.text = row["payment_amount"]
Expand All @@ -420,7 +455,7 @@ def create_xml_v9(root, data, mapping):
CdtTrfTxInf_element.append(Amt_element)

# Create new "CdtrAgt" element in the XML tree using data
# from the CSV file
# from the Data file
CdtrAgt_element = ET.Element("CdtrAgt")
child_element = ET.Element("FinInstnId")
child_element2 = ET.Element("BICFI")
Expand All @@ -434,15 +469,15 @@ def create_xml_v9(root, data, mapping):
CdtTrfTxInf_element.append(CdtrAgt_element)

# Create new "Cdtr" element in the XML tree using data
# from the CSV file
# from the Data file
Cdtr_element = ET.Element("Cdtr")
child_element = ET.Element("Nm")
child_element.text = row["creditor_name"]
Cdtr_element.append(child_element)
CdtTrfTxInf_element.append(Cdtr_element)

# Create new "RmtInf" element in the XML tree using data
# from the CSV file
# from the Data file
RmtInf_element = ET.Element("RmtInf")
child_element = ET.Element("Ustrd")
child_element.text = row["remittance_information"]
Expand All @@ -456,7 +491,7 @@ def create_xml_v9(root, data, mapping):
cstmr_cdt_trf_initn_element.append(PmtInf_element)

# Create new "SplmtryData" elements in the XML tree using data
# from the CSV file"
# from the Data file"
# Create the main elements
SplmtryData_element = ET.Element("SplmtryData")
Envlp_element = ET.SubElement(SplmtryData_element, "Envlp")
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ repository = "https://github.com/sebastienrousseau/pain001"
homepage = "https://pain001.com"

[tool.poetry.dependencies]
python = "^3.9"
xmlschema = "^2.3.0"
click = "^8.1.3"
defusedxml = "^0.7.1"
python = "^3.9"
rich = "^13.4.2"
xmlschema = "^2.3.1"

[build-system]
requires = ["poetry-core"]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
]

TEST_DEPENDENCIES = [
"pytest>=7.3.1",
"pytest>=7.3.2",
]

NAME = "pain001"
Expand Down
8 changes: 3 additions & 5 deletions templates/pain.001.001.03/pain.001.001.03.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03 pain.001.001.03.xsd">
<?xml version="1.0" ?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03 pain.001.001.03.xsd">
<CstmrCdtTrfInitn>
<GrpHdr>
<MsgId>1</MsgId>
Expand Down Expand Up @@ -472,4 +470,4 @@
</CdtTrfTxInf>
</PmtInf>
</CstmrCdtTrfInitn>
</Document>
</Document>

0 comments on commit fcd31c5

Please sign in to comment.