raphaelm / python-sepaxml

SEPA Direct Debit XML generation in python
MIT License
112 stars 43 forks source link

CBI compatibility #34

Open aster94 opened 3 years ago

aster94 commented 3 years ago

Hello,

I would like to have compatibility with the CBI standard, which is derived from the ISO20022 pain.001.001.03

These are some useful files and links: STIP-ST-001 Credit Transfer CBI v.00.04.00.xls

SEPA Single Euro Payments Area.pdf

https://remote.cedbrianteo.it/PagheWEB/help/infinity/ITA/mergedProjects/Infinity_PagheWeb/intro/intro_tracciati_record_accredito_netti.htm

Needed:

  1. add a new schemas for validation of the standard: https://github.com/raphaelm/python-sepaxml/tree/master/sepaxml/schemas Here there is a schema which could be used to ease the work: https://github.com/linkmesrl/cbi/blob/master/lib/xsd/CBIPaymentRequest.00.04.00.xsd
  2. add tests: https://github.com/raphaelm/python-sepaxml/tree/master/tests
  3. add support (for both SEPA and CBI) for Structured Credit Transfer Transaction Information (tag: 'Strd'), right now only Unstructured (Ustrd) is supported

This is a test xml downloaded from my bank with some parameter hidden for privacy:

<?xml version="1.0" encoding="utf-8"?>
<DEF:CBIBdyPaymentRequest
    xmlns="urn:CBI:xsd:CBIBdyPaymentRequest.00.04.00"
    xmlns:DEF="urn:CBI:xsd:CBIBdyPaymentRequest.00.04.00"
    xmlns:PMRQ="urn:CBI:xsd:CBIPaymentRequest.00.04.00"
    xmlns:SGNT="urn:CBI:xsd:CBISgnInf.001.04">
    <DEF:CBIEnvelPaymentRequest>
        <DEF:CBIPaymentRequest>
            <PMRQ:GrpHdr>
                <PMRQ:MsgId>unique id</PMRQ:MsgId>
                <PMRQ:CreDtTm>2021-04-14T00:00:00</PMRQ:CreDtTm>
                <PMRQ:NbOfTxs>1</PMRQ:NbOfTxs>
                <PMRQ:CtrlSum>36.60</PMRQ:CtrlSum>
                <PMRQ:InitgPty>
                    <PMRQ:Id>
                        <PMRQ:OrgId>
                            <PMRQ:Othr>
                                <PMRQ:Id>id</PMRQ:Id>
                                <PMRQ:Issr>CBI</PMRQ:Issr>
                            </PMRQ:Othr>
                        </PMRQ:OrgId>
                    </PMRQ:Id>
                </PMRQ:InitgPty>
            </PMRQ:GrpHdr>
            <PMRQ:PmtInf>
                <PMRQ:PmtInfId>unique id</PMRQ:PmtInfId>
                <PMRQ:PmtMtd>TRA</PMRQ:PmtMtd>
                <PMRQ:PmtTpInf>
                    <PMRQ:InstrPrty>NORM</PMRQ:InstrPrty>
                    <PMRQ:SvcLvl>
                        <PMRQ:Cd>SEPA</PMRQ:Cd>
                    </PMRQ:SvcLvl>
                </PMRQ:PmtTpInf>
                <PMRQ:ReqdExctnDt>2021-04-13</PMRQ:ReqdExctnDt>
                <PMRQ:Dbtr>
                    <PMRQ:Nm>we</PMRQ:Nm>
                    <PMRQ:PstlAdr>
                        <PMRQ:AdrLine>our address</PMRQ:AdrLine>
                        <PMRQ:AdrLine>another line</PMRQ:AdrLine>
                    </PMRQ:PstlAdr>
                </PMRQ:Dbtr>
                <PMRQ:DbtrAcct>
                    <PMRQ:Id>
                        <PMRQ:IBAN>my iban</PMRQ:IBAN>
                    </PMRQ:Id>
                </PMRQ:DbtrAcct>
                <PMRQ:DbtrAgt>
                    <PMRQ:FinInstnId>
                        <PMRQ:ClrSysMmbId>
                            <PMRQ:MmbId>bank code</PMRQ:MmbId>
                        </PMRQ:ClrSysMmbId>
                    </PMRQ:FinInstnId>
                </PMRQ:DbtrAgt>
                <PMRQ:ChrgBr>SLEV</PMRQ:ChrgBr>
                <PMRQ:CdtTrfTxInf>
                    <PMRQ:PmtId>
                        <PMRQ:InstrId>1</PMRQ:InstrId>
                        <PMRQ:EndToEndId>unique id</PMRQ:EndToEndId>
                    </PMRQ:PmtId>
                    <PMRQ:PmtTpInf>
                        <PMRQ:CtgyPurp>
                            <PMRQ:Cd>SUPP</PMRQ:Cd>
                        </PMRQ:CtgyPurp>
                    </PMRQ:PmtTpInf>
                    <PMRQ:Amt>
                        <PMRQ:InstdAmt Ccy="EUR">36.60</PMRQ:InstdAmt>
                    </PMRQ:Amt>
                    <PMRQ:Cdtr>
                        <PMRQ:Nm>my supplier</PMRQ:Nm>
                        <PMRQ:PstlAdr>
                            <PMRQ:StrtNm>supplier address</PMRQ:StrtNm>
                        </PMRQ:PstlAdr>
                        <PMRQ:Id>
                            <PMRQ:OrgId>
                                <PMRQ:Othr>
                                    <PMRQ:Id>supplier vat number</PMRQ:Id>
                                </PMRQ:Othr>
                            </PMRQ:OrgId>
                        </PMRQ:Id>
                    </PMRQ:Cdtr>
                    <PMRQ:CdtrAcct>
                        <PMRQ:Id>
                            <PMRQ:IBAN>supplier iban</PMRQ:IBAN>
                        </PMRQ:Id>
                    </PMRQ:CdtrAcct>
                    <PMRQ:RmtInf>
                        <PMRQ:Strd>
                            <PMRQ:RfrdDocInf>
                                <PMRQ:Tp>
                                    <PMRQ:CdOrPrtry>
                                        <PMRQ:Cd>CINV</PMRQ:Cd>
                                    </PMRQ:CdOrPrtry>
                                </PMRQ:Tp>
                                <PMRQ:Nb>test string</PMRQ:Nb>
                                <PMRQ:RltdDt>2021-04-26</PMRQ:RltdDt>
                            </PMRQ:RfrdDocInf>
                            <PMRQ:RfrdDocAmt>
                                <PMRQ:CdtNoteAmt Ccy="EUR">36.60</PMRQ:CdtNoteAmt>
                            </PMRQ:RfrdDocAmt>
                        </PMRQ:Strd>
                    </PMRQ:RmtInf>
                </PMRQ:CdtTrfTxInf>
            </PMRQ:PmtInf>
        </DEF:CBIPaymentRequest>
    </DEF:CBIEnvelPaymentRequest>
</DEF:CBIBdyPaymentRequest>

This issue is pubblished on bountysource I am able to run tests to check if generated xml file are correctly accepted by my bank

MarcelWaldvogel commented 3 years ago

There definitely would need to be a schema for validation. And some trickery in the XML handling, such that the output will have the prefix, but the API remains mostly unchanged.

You probably want a config option to select the CBI behavior.

aster94 commented 3 years ago

I would like to give a bounty for this issue (actually it is the first time I do this), but before I would like to have the permission from the repo author @raphaelm Manwhile if someone if willing to grab it you can contact me with email (visible on my profile)

raphaelm commented 3 years ago

I'm not really a fan of this library expanding in scope, as it is already hard to maintain due to the different schemas involved. I wouldn't oppose a PR with good tests and a schema, though.

aster94 commented 3 years ago

Understandable Raphael, I really don't understand why my country (Italy) had to make their own standard when there was an european standard available... Meanwhile I updated the first post with some documentation

aster94 commented 3 years ago

I opened the bounty and edited the first post, I also asked support for the Structured Credit Transfer Transaction Information, which is supported by both classic SEPA and CBI, my desire is that the whole library would benefit from this bounty

@raphaelm please feel free to propose any change on the issue, both in private or here

aster94 commented 3 years ago

Bounty raised to 100$