Last active
January 22, 2021 10:06
-
-
Save apolichronopoulos/74db3c490cd30dcdd884af5a10373dce to your computer and use it in GitHub Desktop.
Part of https://github.com/Payment-Components/demo-sepa#more-features-are-included-in-the-paid-version-like
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gr.datamation.sepa.core.messages.eba.pacs.FIToFICustomerCreditTransfer; | |
import java.util.List; | |
public class SepaTestResolveTransactionPacs008 { | |
public static void main(String... args) { | |
execute(); | |
} | |
public static void execute() { | |
//You have to initiate the messageObject object using the suitable constructor. | |
//In order to parse and validate a pacs.008 you need to use FIToFICustomerCreditTransfer | |
//FIToFICustomerCreditTransfer > matches the xml element <FIToFICstmrCdtTrf> | |
FIToFICustomerCreditTransfer messageObject = new FIToFICustomerCreditTransfer(); | |
try { | |
//Use parseAndValidateString() to fill the messageObject the content of the messageObject and validate it | |
//validation fills the messageObject variable errors object with any issue found during validation | |
messageObject.parseAndValidateString(validPacs008String); | |
if (messageObject.hasValidationErrors()) { | |
messageObject.printValidationErrors(); | |
} else { | |
System.out.println(messageObject.toString()); | |
} | |
/* | |
In addition to the getElement methods, the `resolveTransaction()` or `resolveTransactions()` methods can be used to greatly simplify the parsing of messages. | |
The following uses a FIToFICustomerCreditTransfer (`pacs.008.001.02`) message as an example. These methods return vectors of vectors of LeafInfo objects. | |
LeafInfo objects have 3 fields: fieldPath, fieldCd, value | |
*/ | |
System.out.println("--------------------------------------------"); | |
List<List<String[]>> transactions = messageObject.resolveTransactions(); | |
for (List<String[]> transaction : transactions) { | |
for (String[] leaf : transaction) { | |
System.out.println("Path: " + leaf[0] + " | Field: " + leaf[1] + " | Value: " + leaf[2]); | |
System.out.println("--------------------------------------------"); | |
} | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
System.err.println("Message cannot be parsed"); | |
} | |
} | |
private static final String validPacs008String = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + | |
"<Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02\">\n" + | |
" <FIToFICstmrCdtTrf>\n" + | |
" <GrpHdr>\n" + | |
" <MsgId>PSCXMILBGRAA20101115114110891</MsgId>\n" + | |
" <CreDtTm>2013-11-07T11:41:10</CreDtTm>\n" + | |
" <NbOfTxs>1</NbOfTxs>\n" + | |
" <TtlIntrBkSttlmAmt Ccy=\"EUR\">20.00</TtlIntrBkSttlmAmt>\n" + | |
" <IntrBkSttlmDt>2013-11-07</IntrBkSttlmDt>\n" + | |
" <SttlmInf>\n" + | |
" <SttlmMtd>CLRG</SttlmMtd>\n" + | |
" <ClrSys>\n" + | |
" <Prtry>ST2</Prtry>\n" + | |
" </ClrSys>\n" + | |
" </SttlmInf>\n" + | |
" <InstdAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BIC>BCYPCY2N</BIC>\n" + | |
" </FinInstnId>\n" + | |
" </InstdAgt>\n" + | |
" </GrpHdr>\n" + | |
" <CdtTrfTxInf>\n" + | |
" <PmtId>\n" + | |
" <InstrId>DEUTDE0920000891</InstrId>\n" + | |
" <EndToEndId>NOTPROVIDED</EndToEndId>\n" + | |
" <TxId>DEUTDEFF011OS10222891</TxId>\n" + | |
" </PmtId>\n" + | |
" <PmtTpInf>\n" + | |
" <SvcLvl>\n" + | |
" <Cd>SEPA</Cd>\n" + | |
" </SvcLvl>\n" + | |
" </PmtTpInf>\n" + | |
" <IntrBkSttlmAmt Ccy=\"EUR\">20.00</IntrBkSttlmAmt>\n" + | |
" <ChrgBr>SLEV</ChrgBr>\n" + | |
" <InstgAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BIC>DEUTDEFFXXX</BIC>\n" + | |
" </FinInstnId>\n" + | |
" </InstgAgt>\n" + | |
" <Dbtr>\n" + | |
" <Nm>Debtor name</Nm>\n" + | |
" <PstlAdr>\n" + | |
" <Ctry>DE</Ctry>\n" + | |
" <AdrLine>Indirizzo 1 Dbtr</AdrLine>\n" + | |
" <AdrLine>Indirizzo 2 Dbtr</AdrLine>\n" + | |
" </PstlAdr>\n" + | |
" <Id>\n" + | |
" <OrgId>\n" + | |
" <Othr>\n" + | |
" <Id>PT50078101120112001285102</Id>\n" + | |
" <SchmeNm>\n" + | |
" <Cd>BANK</Cd>\n" + | |
" </SchmeNm>\n" + | |
" </Othr>\n" + | |
" </OrgId>\n" + | |
" </Id>\n" + | |
" </Dbtr>\n" + | |
" <DbtrAcct>\n" + | |
" <Id>\n" + | |
" <IBAN>DE73340302860352858328</IBAN>\n" + | |
" </Id>\n" + | |
" </DbtrAcct>\n" + | |
" <DbtrAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BIC>DEUTDEFFXXX</BIC>\n" + | |
" </FinInstnId>\n" + | |
" </DbtrAgt>\n" + | |
" <CdtrAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BIC>BCYPCY2N</BIC>\n" + | |
" </FinInstnId>\n" + | |
" </CdtrAgt>\n" + | |
" <Cdtr>\n" + | |
" <Nm>CREDITOR NAME</Nm>\n" + | |
" <PstlAdr>\n" + | |
" <Ctry>GR</Ctry>\n" + | |
" <AdrLine>ADDRESS 1@#$/\\</AdrLine>\n" + | |
" <AdrLine>ATHENS</AdrLine>\n" + | |
" </PstlAdr>\n" + | |
" <Id>\n" + | |
" <OrgId>\n" + | |
" <Othr>\n" + | |
" <Id>PT60078101120112001285102</Id>\n" + | |
" <SchmeNm>\n" + | |
" <Cd>BANK</Cd>\n" + | |
" </SchmeNm>\n" + | |
" </Othr>\n" + | |
" </OrgId>\n" + | |
" </Id>\n" + | |
" </Cdtr>\n" + | |
" <CdtrAcct>\n" + | |
" <Id>\n" + | |
" <IBAN>GR2703801380000000000089777</IBAN>\n" + | |
" </Id>\n" + | |
" </CdtrAcct>\n" + | |
" <RmtInf>\n" + | |
" <Ustrd>Rem. Info</Ustrd>\n" + | |
" </RmtInf>\n" + | |
" </CdtTrfTxInf>\n" + | |
" </FIToFICstmrCdtTrf>\n" + | |
"</Document>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment