Skip to content

Instantly share code, notes, and snippets.

@gantoniadispc14
Created July 27, 2023 10:24
Show Gist options
  • Save gantoniadispc14/961ea60d9bdfc6fdc3328ee798f607e5 to your computer and use it in GitHub Desktop.
Save gantoniadispc14/961ea60d9bdfc6fdc3328ee798f607e5 to your computer and use it in GitHub Desktop.
Pacs003EpcDdAutoReplies
package gr.datamation.iso20022.sepa.epc.dd.pacs;
import gr.datamation.iso20022.sepa.epc.dd.replies.FIToFICustomerDirectDebit08SepaEpcDdAutoReplies;
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;
public class Pacs003EpcDdAutoReplies {
public static void main(String... args) {
execute();
}
public static void execute() {
paymentRejectAutoReply();
paymentReturnAutoReply();
paymentReversalAutoReply();
}
public static void paymentRejectAutoReply() {
try {
//Initialize the message object
FIToFICustomerDirectDebit08SepaEpcDd fIToFICustomerDirectDebit = new FIToFICustomerDirectDebit08SepaEpcDd();
//Optionally use an existing message if we do not want to create the object from scratch
fIToFICustomerDirectDebit.parseXML(validEpcDdPacs003String);
//Perform validation
ValidationErrorList validationErrorList = fIToFICustomerDirectDebit.validate();
if (!validationErrorList.isEmpty())
throw new Exception("Invalid pacs.003 message to return");
FIToFICustomerDirectDebit08SepaEpcDdAutoReplies<FIToFICustomerDirectDebit08SepaEpcDd, FIToFIPaymentStatusReport10SepaEpcDd> fIToFICustomerDirectDebitActions =
new FIToFICustomerDirectDebit08SepaEpcDdAutoReplies<>(fIToFICustomerDirectDebit);
MsgReplyInfo msgReplyInfo = new MsgReplyInfo();
ReasonInformation reasonInformation = new ReasonInformation();
reasonInformation.setType(ReasonInformation.Type.CD); //mandatory
reasonInformation.setValue("AM05"); //mandatory
reasonInformation.setAddtlInf(Collections.singletonList("Additional info")); //optional
msgReplyInfo.setRsnInf(reasonInformation);
msgReplyInfo.setReplyId("pacs003Reply"); //optional
msgReplyInfo.setOrgnlMsgId("1234"); //optional
msgReplyInfo.setIntrBkSttlmDt(LocalDate.now()); //optional, if empty, current date will be used
ChargesInformation chargesInformation = new ChargesInformation();
chargesInformation.setAmount(new BigDecimal("2.00"));
chargesInformation.setAgentBic("AAAAGB2L"); //optional
msgReplyInfo.setChargesInformation(Collections.singletonList(chargesInformation)); //optional
msgReplyInfo.setChargeBearer("SLEV"); //optional
FIToFIPaymentStatusReport10SepaEpcDd pacs002 = fIToFICustomerDirectDebitActions.autoReply(new FIToFIPaymentStatusReport10SepaEpcDd(), Collections.singletonList(msgReplyInfo));
validationErrorList = pacs002.validate();
if (validationErrorList.isEmpty()) {
System.out.println("Return Message is valid");
System.out.println(pacs002.convertToXML()); //Get the generated xml
} else {
handleValidationError(validationErrorList);
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
}
}
public static void paymentReturnAutoReply() {
try {
//Initialize the message object
FIToFICustomerDirectDebit08SepaEpcDd fIToFICustomerDirectDebit = new FIToFICustomerDirectDebit08SepaEpcDd();
//Optionally use an existing message if we do not want to create the object from scratch
fIToFICustomerDirectDebit.parseXML(validEpcDdPacs003String);
//Perform validation
ValidationErrorList validationErrorList = fIToFICustomerDirectDebit.validate();
if (!validationErrorList.isEmpty())
throw new Exception("Invalid pacs.003 message to return");
FIToFICustomerDirectDebit08SepaEpcDdAutoReplies<FIToFICustomerDirectDebit08SepaEpcDd, PaymentReturn09SepaEpcDd> fIToFICustomerDirectDebitActions =
new FIToFICustomerDirectDebit08SepaEpcDdAutoReplies<>(fIToFICustomerDirectDebit);
MsgReplyInfo msgReplyInfo = new MsgReplyInfo();
ReasonInformation reasonInformation = new ReasonInformation();
reasonInformation.setType(ReasonInformation.Type.CD); //mandatory
reasonInformation.setValue("AM05"); //mandatory
reasonInformation.setAddtlInf(Collections.singletonList("Additional info")); //optional
msgReplyInfo.setRsnInf(reasonInformation);
msgReplyInfo.setReplyId("pacs003Reply"); //optional
msgReplyInfo.setOrgnlMsgId("1234"); //optional
msgReplyInfo.setIntrBkSttlmDt(LocalDate.now()); //optional, if empty, current date will be used
ChargesInformation chargesInformation = new ChargesInformation();
chargesInformation.setAmount(new BigDecimal("2.00"));
chargesInformation.setAgentBic("AAAAGB2L"); //optional
msgReplyInfo.setChargesInformation(Collections.singletonList(chargesInformation)); //optional
msgReplyInfo.setChargeBearer("SLEV"); //optional
PaymentReturn09SepaEpcDd pacs004 = fIToFICustomerDirectDebitActions.autoReply(new PaymentReturn09SepaEpcDd(), Collections.singletonList(msgReplyInfo));
validationErrorList = pacs004.validate();
if (validationErrorList.isEmpty()) {
System.out.println("Return Message is valid");
System.out.println(pacs004.convertToXML()); //Get the generated xml
} else {
handleValidationError(validationErrorList);
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
}
}
public static void paymentReversalAutoReply() {
try {
//Initialize the message object
FIToFICustomerDirectDebit08SepaEpcDd fIToFICustomerDirectDebit = new FIToFICustomerDirectDebit08SepaEpcDd();
//Optionally use an existing message if we do not want to create the object from scratch
fIToFICustomerDirectDebit.parseXML(validEpcDdPacs003String);
//Perform validation
ValidationErrorList validationErrorList = fIToFICustomerDirectDebit.validate();
if (!validationErrorList.isEmpty())
throw new Exception("Invalid pacs.003 message to return");
FIToFICustomerDirectDebit08SepaEpcDdAutoReplies<FIToFICustomerDirectDebit08SepaEpcDd, FIToFIPaymentReversal09SepaEpcDd> fIToFICustomerDirectDebitActions =
new FIToFICustomerDirectDebit08SepaEpcDdAutoReplies<>(fIToFICustomerDirectDebit);
MsgReplyInfo msgReplyInfo = new MsgReplyInfo();
ReasonInformation reasonInformation = new ReasonInformation();
reasonInformation.setType(ReasonInformation.Type.CD); //mandatory
reasonInformation.setValue("AM05"); //mandatory
reasonInformation.setAddtlInf(Collections.singletonList("Additional info")); //optional
msgReplyInfo.setRsnInf(reasonInformation);
msgReplyInfo.setReplyId("pacs003Reply"); //optional
msgReplyInfo.setOrgnlMsgId("1234"); //optional
msgReplyInfo.setIntrBkSttlmDt(LocalDate.now()); //optional, if empty, current date will be used
ChargesInformation chargesInformation = new ChargesInformation();
chargesInformation.setAmount(new BigDecimal("2.00"));
chargesInformation.setAgentBic("AAAAGB2L"); //optional
msgReplyInfo.setChargesInformation(Collections.singletonList(chargesInformation)); //optional
msgReplyInfo.setChargeBearer("SLEV"); //optional
FIToFIPaymentReversal09SepaEpcDd pacs007 = fIToFICustomerDirectDebitActions.autoReply(new FIToFIPaymentReversal09SepaEpcDd(), Collections.singletonList(msgReplyInfo));
validationErrorList = pacs007.validate();
if (validationErrorList.isEmpty()) {
System.out.println("Return Message is valid");
System.out.println(pacs007.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 validEpcDdPacs003String = "<Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pacs.003.001.08\">\n" +
" <FIToFICstmrDrctDbt>\n" +
" <GrpHdr>\n" +
" <MsgId>string</MsgId>\n" +
" <CreDtTm>2008-09-29T04:49:45</CreDtTm>\n" +
" <NbOfTxs>1</NbOfTxs>\n" +
" <TtlIntrBkSttlmAmt Ccy=\"EUR\">1500.00</TtlIntrBkSttlmAmt>\n" +
" <IntrBkSttlmDt>2004-02-14</IntrBkSttlmDt>\n" +
" <SttlmInf>\n" +
" <SttlmMtd>INDA</SttlmMtd>\n" +
" <SttlmAcct>\n" +
" <Id>\n" +
" <IBAN>GR5501400101234567890123456</IBAN>\n" +
" </Id>\n" +
" </SttlmAcct>\n" +
" </SttlmInf>\n" +
" <PmtTpInf>\n" +
" <SvcLvl>\n" +
" <Cd>SEPA</Cd>\n" +
" </SvcLvl>\n" +
" <LclInstrm>\n" +
" <Cd>CORE</Cd>\n" +
" </LclInstrm>\n" +
" <SeqTp>FNAL</SeqTp>\n" +
" <CtgyPurp>\n" +
" <Cd>stri</Cd>\n" +
" </CtgyPurp>\n" +
" </PmtTpInf>\n" +
" <InstgAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>CCCCIE2D</BICFI>\n" +
" </FinInstnId>\n" +
" </InstgAgt>\n" +
" <InstdAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>BBBBIE2D</BICFI>\n" +
" </FinInstnId>\n" +
" </InstdAgt>\n" +
" </GrpHdr>\n" +
" <DrctDbtTxInf>\n" +
" <PmtId>\n" +
" <InstrId>string</InstrId>\n" +
" <EndToEndId>string</EndToEndId>\n" +
" <TxId>string</TxId>\n" +
" </PmtId>\n" +
" <IntrBkSttlmAmt Ccy=\"EUR\">1000.00</IntrBkSttlmAmt>\n" +
" <ChrgBr>SLEV</ChrgBr>\n" +
" <ReqdColltnDt>2002-06-24+03:00</ReqdColltnDt>\n" +
" <DrctDbtTx>\n" +
" <MndtRltdInf>\n" +
" <MndtId>string</MndtId>\n" +
" <DtOfSgntr>2016-02-20+02:00</DtOfSgntr>\n" +
" <ElctrncSgntr>string</ElctrncSgntr>\n" +
" </MndtRltdInf>\n" +
" <CdtrSchmeId>\n" +
" <Id>\n" +
" <PrvtId>\n" +
" <Othr>\n" +
" <Id>string</Id>\n" +
" <SchmeNm>\n" +
" <Prtry>SEPA</Prtry>\n" +
" </SchmeNm>\n" +
" </Othr>\n" +
" </PrvtId>\n" +
" </Id>\n" +
" </CdtrSchmeId>\n" +
" </DrctDbtTx>\n" +
" <Cdtr>\n" +
" <Nm>string</Nm>\n" +
" <PstlAdr>\n" +
" <Ctry>GR</Ctry>\n" +
" <AdrLine>string</AdrLine>\n" +
" </PstlAdr>\n" +
" </Cdtr>\n" +
" <CdtrAcct>\n" +
" <Id>\n" +
" <IBAN>GR5501400101234567890123456</IBAN>\n" +
" </Id>\n" +
" </CdtrAcct>\n" +
" <CdtrAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>TESTBICA</BICFI>\n" +
" </FinInstnId>\n" +
" </CdtrAgt>\n" +
" <Dbtr>\n" +
" <Nm>string</Nm>\n" +
" <PstlAdr>\n" +
" <TwnNm>string</TwnNm>\n" +
" <Ctry>GR</Ctry>\n" +
" </PstlAdr>\n" +
" </Dbtr>\n" +
" <DbtrAcct>\n" +
" <Id>\n" +
" <IBAN>GR5501400101234567890123456</IBAN>\n" +
" </Id>\n" +
" </DbtrAcct>\n" +
" <DbtrAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>TESTBICA</BICFI>\n" +
" </FinInstnId>\n" +
" </DbtrAgt>\n" +
" <Purp>\n" +
" <Cd>stri</Cd>\n" +
" </Purp>\n" +
" <RmtInf>\n" +
" <Strd>\n" +
" <CdtrRefInf>\n" +
" <Tp>\n" +
" <CdOrPrtry>\n" +
" <Cd>SCOR</Cd>\n" +
" </CdOrPrtry>\n" +
" <Issr>string</Issr>\n" +
" </Tp>\n" +
" <Ref>string</Ref>\n" +
" </CdtrRefInf>\n" +
" </Strd>\n" +
" </RmtInf>\n" +
" </DrctDbtTxInf>\n" +
" <DrctDbtTxInf>\n" +
" <PmtId>\n" +
" <InstrId>string</InstrId>\n" +
" <EndToEndId>string</EndToEndId>\n" +
" <TxId>string</TxId>\n" +
" </PmtId>\n" +
" <IntrBkSttlmAmt Ccy=\"EUR\">500.00</IntrBkSttlmAmt>\n" +
" <ChrgBr>SLEV</ChrgBr>\n" +
" <ReqdColltnDt>2002-06-24+03:00</ReqdColltnDt>\n" +
" <DrctDbtTx>\n" +
" <MndtRltdInf>\n" +
" <MndtId>string</MndtId>\n" +
" <DtOfSgntr>2016-02-20+02:00</DtOfSgntr>\n" +
" <ElctrncSgntr>string</ElctrncSgntr>\n" +
" </MndtRltdInf>\n" +
" <CdtrSchmeId>\n" +
" <Id>\n" +
" <PrvtId>\n" +
" <Othr>\n" +
" <Id>string</Id>\n" +
" <SchmeNm>\n" +
" <Prtry>SEPA</Prtry>\n" +
" </SchmeNm>\n" +
" </Othr>\n" +
" </PrvtId>\n" +
" </Id>\n" +
" </CdtrSchmeId>\n" +
" </DrctDbtTx>\n" +
" <Cdtr>\n" +
" <Nm>string</Nm>\n" +
" <PstlAdr>\n" +
" <Ctry>GR</Ctry>\n" +
" <AdrLine>string</AdrLine>\n" +
" </PstlAdr>\n" +
" </Cdtr>\n" +
" <CdtrAcct>\n" +
" <Id>\n" +
" <IBAN>GR5501400101234567890123456</IBAN>\n" +
" </Id>\n" +
" </CdtrAcct>\n" +
" <CdtrAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>TESTBICA</BICFI>\n" +
" </FinInstnId>\n" +
" </CdtrAgt>\n" +
" <Dbtr>\n" +
" <Nm>string</Nm>\n" +
" <PstlAdr>\n" +
" <TwnNm>string</TwnNm>\n" +
" <Ctry>GR</Ctry>\n" +
" </PstlAdr>\n" +
" </Dbtr>\n" +
" <DbtrAcct>\n" +
" <Id>\n" +
" <IBAN>GR5501400101234567890123456</IBAN>\n" +
" </Id>\n" +
" </DbtrAcct>\n" +
" <DbtrAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>TESTBICA</BICFI>\n" +
" </FinInstnId>\n" +
" </DbtrAgt>\n" +
" <Purp>\n" +
" <Cd>stri</Cd>\n" +
" </Purp>\n" +
" <RmtInf>\n" +
" <Strd>\n" +
" <CdtrRefInf>\n" +
" <Tp>\n" +
" <CdOrPrtry>\n" +
" <Cd>SCOR</Cd>\n" +
" </CdOrPrtry>\n" +
" <Issr>string</Issr>\n" +
" </Tp>\n" +
" <Ref>string</Ref>\n" +
" </CdtrRefInf>\n" +
" </Strd>\n" +
" </RmtInf>\n" +
" </DrctDbtTxInf>\n" +
" </FIToFICstmrDrctDbt>\n" +
"</Document>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment