pain001.pain002 package#
Pain.002 payment status report parsing and generation utilities.
Submodules#
pain001.pain002.generator module#
Builder for ISO 20022 pain.002 payment status reports.
The complement to pain001.pain002.parse_pain002_report(): given the
status a bank (or a test harness simulating one) wants to report, produce a
well-formed pain.002 XML document. Generation uses the standard library’s
ElementTree (output is fully under our control); the result round-trips
cleanly back through the parser.
- pain001.pain002.generator.VALID_STATUS_CODES = frozenset({'ACCP', 'ACSC', 'ACSP', 'ACTC', 'ACWC', 'PART', 'PDNG', 'RCVD', 'RJCT'})#
Status codes defined by ISO 20022 for group/payment/transaction status.
- pain001.pain002.generator.build_pain002_report(message_id: str, original_message_id: str, group_status: str, payment_statuses: list[dict[str, Any]], *, original_message_name_id: str = 'pain.001.001.03', creation_datetime: str | None = None, version: str = 'pain.002.001.03') str[source]#
Build a pain.002 payment status report as an XML string.
- Parameters:
message_id – Identifier for this status report (
GrpHdr/MsgId).original_message_id – The id of the pain.001 message being reported on (
OrgnlGrpInfAndSts/OrgnlMsgId).group_status – Group-level status code (e.g.
ACCP,RJCT).payment_statuses – One dict per original payment information block. Recognised keys:
original_payment_information_id(required),payment_information_status(required), and the optional transaction tripletoriginal_end_to_end_id,transaction_status,status_reason.original_message_name_id – Name id of the original message (default
pain.001.001.03).creation_datetime – ISO-8601 creation timestamp; defaults to now (UTC).
version – pain.002 message version (drives the namespace).
- Returns:
The pain.002 report as a UTF-8 XML string (with declaration).
- Raises:
ValueError – If
group_statusor any row status is not a known ISO 20022 status code, or a required row key is missing.
pain001.pain002.parser module#
Parser for ISO 20022 pain.002 payment status reports.
- pain001.pain002.parser.SCHEMA_DIR = PosixPath('/home/runner/work/pain001/pain001/pain001/pain002/schemas')#
Bundled ISO schemas for validating a bank’s pain.002 response. The parser itself is namespace-agnostic, so a bank may send any version; only these can be validated without supplying a path.
- pain001.pain002.parser.bundled_schema_versions() list[str][source]#
Return the pain.002 versions this package can validate.
- pain001.pain002.parser.parse_pain002_report(xml_file_path: str, xsd_file_path: str | None = None, validate: bool = False) dict[str, object][source]#
Parse a pain.002 payment status report into structured data.
- Parameters:
xml_file_path – The bank’s pain.002 response.
xsd_file_path – Explicit schema to validate against. Takes precedence over
validate.validate – Validate against the bundled schema matching the document’s own namespace. Raises if no bundled schema covers that version rather than parsing unvalidated — a silent skip would report success while checking nothing. Call
bundled_schema_versions()to see what is covered.
- Returns:
message and original-message identifiers, creation timestamp, group status, and a
payment_statuseslist of per-transaction status and reason codes.- Return type:
The parsed report
- Raises:
DataSourceError – The path is invalid or the XML is malformed.
SchemaValidationError – The document failed validation, or
validatewas requested for an unbundled version.