Skip to content

Instantly share code, notes, and snippets.

@gantoniadispc14
Created September 1, 2023 10:10
Show Gist options
  • Save gantoniadispc14/6b9c63d2ddb0ee7b74b4d03408d8ff98 to your computer and use it in GitHub Desktop.
Save gantoniadispc14/6b9c63d2ddb0ee7b74b4d03408d8ff98 to your computer and use it in GitHub Desktop.
Camt056EpcInstAutoReplies
package gr.datamation.iso20022.sepa.epc.inst.replies;
import gr.datamation.iso20022.sepa.epc.inst.camt.FIToFIPaymentCancellationRequest08RecallSepaEpcInst;
import gr.datamation.iso20022.sepa.epc.inst.pacs.FIToFIPaymentStatusRequest03RecallSepaEpcInst;
import gr.datamation.replies.common.ChargesInformation;
import gr.datamation.replies.common.MsgReplyInfo;
import gr.datamation.replies.common.ReasonInformation;
import gr.datamation.validation.error.ValidationError;
import gr.datamation.validation.error.ValidationErrorList;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Collections;
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
public class Camt056EpcInstAutoReplies {
public static void main(String... args) {
execute();
}
public static void execute() {
fiToFIPaymentStatusRequestAutoReply();
}
public static void fiToFIPaymentStatusRequestAutoReply() {
try {
//Initialize the message object
FIToFIPaymentCancellationRequest08RecallSepaEpcInst cancellationRequest08Recall = new FIToFIPaymentCancellationRequest08RecallSepaEpcInst();
//Optionally, use an existing message if we do not want to create the object from scratch
cancellationRequest08Recall.parseXML(validSepcEpcInstCamt056String);
//Perform validation
ValidationErrorList validationErrorList = cancellationRequest08Recall.validate();
if (!validationErrorList.isEmpty())
throw new Exception("Invalid camt.056 message to return");
FIToFIPaymentCancellationRequestEpcInstAutoReplies<FIToFIPaymentCancellationRequest08RecallSepaEpcInst, FIToFIPaymentStatusRequest03RecallSepaEpcInst> camt056actions =
new FIToFIPaymentCancellationRequestEpcInstAutoReplies<>(cancellationRequest08Recall);
ReasonInformation rsnInf = new ReasonInformation(ReasonInformation.Type.CD, "FOCR", Collections.singletonList("ATR053/ADDRESS 1"));
MsgReplyInfo msgReplyInfo = new MsgReplyInfo();
msgReplyInfo.setRsnInf(rsnInf);
msgReplyInfo.setReplyId("1234");
msgReplyInfo.setOrgnlMsgId("20210928");
msgReplyInfo.setIntrBkSttlmDt(LocalDate.parse("2021-09-28", ISO_LOCAL_DATE));
msgReplyInfo.getChargesInformation().add(new ChargesInformation(BigDecimal.ONE, null));
FIToFIPaymentStatusRequest03RecallSepaEpcInst fiToFIPaymentStatusRequest03Recall = camt056actions.autoReply(new FIToFIPaymentStatusRequest03RecallSepaEpcInst(), Collections.singletonList(msgReplyInfo));
validationErrorList = fiToFIPaymentStatusRequest03Recall.validate();
if (validationErrorList.isEmpty()) {
System.out.println("Return Message is valid");
System.out.println(fiToFIPaymentStatusRequest03Recall.convertToXML()); //Get the generated xml
} else {
handleValidationError(validationErrorList);
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
}
}
private static void handleValidationError(ValidationErrorList validationErrorList) {
System.err.println("Message is invalid, and the errors are the following:");
for (ValidationError error : validationErrorList) {
System.err.println(error.toString());
System.err.println(
"Error Code: " + error.getErrorCode() + "\n" +
"Error Description: " + error.getDescription() + "\n" +
"Line number in error inside the tag: " + error.getLine() + "\n"
);
}
}
private static final String validSepcEpcInstCamt056String = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:camt.056.001.08\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:iso:std:iso:20022:tech:xsd:camt.056.001.08 ReturnRequest_camt_056_001_08.xsd\">\n" +
" <FIToFIPmtCxlReq>\n" +
" <Assgnmt>\n" +
" <Id>str1234</Id>\n" +
" <Assgnr>\n" +
" <Agt>\n" +
" <FinInstnId>\n" +
" <BICFI>DEUTDEFFXXX</BICFI>\n" +
" </FinInstnId>\n" +
" </Agt>\n" +
" </Assgnr>\n" +
" <Assgne>\n" +
" <Agt>\n" +
" <FinInstnId>\n" +
" <BICFI>DEUTDEFFXXX</BICFI>\n" +
" </FinInstnId>\n" +
" </Agt>\n" +
" </Assgne>\n" +
" <CreDtTm>2012-12-13T12:12:12</CreDtTm>\n" +
" </Assgnmt>\n" +
" <CtrlData>\n" +
" <NbOfTxs>1</NbOfTxs>\n" +
" </CtrlData>\n" +
" <Undrlyg>\n" +
" <TxInf>\n" +
" <CxlId>str1234</CxlId>\n" +
" <OrgnlGrpInf>\n" +
" <OrgnlMsgId>str1234</OrgnlMsgId>\n" +
" <OrgnlMsgNmId>pacs.008.001.08</OrgnlMsgNmId>\n" +
" </OrgnlGrpInf>\n" +
" <OrgnlInstrId>str1234</OrgnlInstrId>\n" +
" <OrgnlEndToEndId>str1234</OrgnlEndToEndId>\n" +
" <OrgnlTxId>str1234</OrgnlTxId>\n" +
" <OrgnlIntrBkSttlmAmt Ccy=\"DKK\">23.00</OrgnlIntrBkSttlmAmt>\n" +
" <OrgnlIntrBkSttlmDt>2012-12-13</OrgnlIntrBkSttlmDt>\n" +
" <CxlRsnInf>\n" +
" <Orgtr>\n" +
" <Nm>str1234</Nm>\n" +
" </Orgtr>\n" +
" <Rsn>\n" +
" <Cd>DUPL</Cd>\n" +
" </Rsn>\n" +
" </CxlRsnInf>\n" +
" <OrgnlTxRef>\n" +
" <SttlmInf>\n" +
" <SttlmMtd>CLRG</SttlmMtd>\n" +
" <ClrSys>\n" +
" <Cd>B27</Cd>\n" +
" </ClrSys>\n" +
" </SttlmInf>\n" +
" <PmtTpInf>\n" +
" <SvcLvl>\n" +
" <Cd>SEPA</Cd>\n" +
" </SvcLvl>\n" +
" <LclInstrm>\n" +
" <Cd>CPP</Cd>\n" +
" </LclInstrm>\n" +
" <CtgyPurp>\n" +
" <Cd>BONU</Cd>\n" +
" </CtgyPurp>\n" +
" </PmtTpInf>\n" +
" <RmtInf>\n" +
" <Ustrd>str1234</Ustrd>\n" +
" <Strd>\n" +
" <CdtrRefInf>\n" +
" <Tp>\n" +
" <CdOrPrtry>\n" +
" <Cd>SCOR</Cd>\n" +
" </CdOrPrtry>\n" +
" <Issr>str1234</Issr>\n" +
" </Tp>\n" +
" <Ref>str1234</Ref>\n" +
" </CdtrRefInf>\n" +
" </Strd>\n" +
" </RmtInf>\n" +
" <UltmtDbtr>\n" +
" <Pty>\n" +
" <Nm>str1234</Nm>\n" +
" <Id>\n" +
" <OrgId>\n" +
" <AnyBIC>ABABUS23</AnyBIC>\n" +
" <Othr>\n" +
" <Id>str1234</Id>\n" +
" <SchmeNm>\n" +
" <Cd>BANK</Cd>\n" +
" </SchmeNm>\n" +
" </Othr>\n" +
" </OrgId>\n" +
" </Id>\n" +
" </Pty>\n" +
" </UltmtDbtr>\n" +
" <Dbtr>\n" +
" <Pty>\n" +
" <Nm>str1234</Nm>\n" +
" <PstlAdr>\n" +
" <Ctry>GR</Ctry>\n" +
" <AdrLine>str1234</AdrLine>\n" +
" </PstlAdr>\n" +
" <Id>\n" +
" <OrgId>\n" +
" <AnyBIC>ABABUS23</AnyBIC>\n" +
" <Othr>\n" +
" <Id>str1234</Id>\n" +
" <SchmeNm>\n" +
" <Cd>BANK</Cd>\n" +
" </SchmeNm>\n" +
" </Othr>\n" +
" </OrgId>\n" +
" </Id>\n" +
" </Pty>\n" +
" </Dbtr>\n" +
" <DbtrAcct>\n" +
" <Id>\n" +
" <IBAN>CY21003000700000007011014888</IBAN>\n" +
" </Id>\n" +
" </DbtrAcct>\n" +
" <DbtrAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>ABABUS23</BICFI>\n" +
" </FinInstnId>\n" +
" </DbtrAgt>\n" +
" <CdtrAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>ABABUS23</BICFI>\n" +
" </FinInstnId>\n" +
" </CdtrAgt>\n" +
" <Cdtr>\n" +
" <Pty>\n" +
" <Nm>str1234</Nm>\n" +
" <PstlAdr>\n" +
" <Ctry>GR</Ctry>\n" +
" <AdrLine>str1234</AdrLine>\n" +
" </PstlAdr>\n" +
" <Id>\n" +
" <OrgId>\n" +
" <AnyBIC>ABABUS23</AnyBIC>\n" +
" <Othr>\n" +
" <Id>str1234</Id>\n" +
" <SchmeNm>\n" +
" <Cd>BANK</Cd>\n" +
" </SchmeNm>\n" +
" </Othr>\n" +
" </OrgId>\n" +
" </Id>\n" +
" </Pty>\n" +
" </Cdtr>\n" +
" <CdtrAcct>\n" +
" <Id>\n" +
" <IBAN>CY21003000700000007011014888</IBAN>\n" +
" </Id>\n" +
" </CdtrAcct>\n" +
" <UltmtCdtr>\n" +
" <Pty>\n" +
" <Nm>str1234</Nm>\n" +
" <Id>\n" +
" <OrgId>\n" +
" <AnyBIC>ABABUS23</AnyBIC>\n" +
" <Othr>\n" +
" <Id>str1234</Id>\n" +
" <SchmeNm>\n" +
" <Cd>BANK</Cd>\n" +
" </SchmeNm>\n" +
" </Othr>\n" +
" </OrgId>\n" +
" </Id>\n" +
" </Pty>\n" +
" </UltmtCdtr>\n" +
" </OrgnlTxRef>\n" +
" </TxInf>\n" +
" </Undrlyg>\n" +
" </FIToFIPmtCxlReq>\n" +
"</Document>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment