Skip to content

Instantly share code, notes, and snippets.

@johnmara-pc14
Created November 3, 2022 11:12
Show Gist options
  • Save johnmara-pc14/a03821408d286cbf55e1e5ad66b83f51 to your computer and use it in GitHub Desktop.
Save johnmara-pc14/a03821408d286cbf55e1e5ad66b83f51 to your computer and use it in GitHub Desktop.
Pacs008FednowMessageAutoReplies
package com.paymentcomponents.swift.mx.fednow;
import gr.datamation.iso20022.fednow.camt.FIToFIPaymentCancellationRequest08Fednow;
import gr.datamation.iso20022.fednow.pacs.FIToFICustomerCreditTransfer08Fednow;
import gr.datamation.iso20022.fednow.pacs.PaymentReturn10Fednow;
import gr.datamation.replies.common.ChargesInformation;
import gr.datamation.replies.common.MsgReplyInfo;
import gr.datamation.replies.common.ReasonInformation;
import gr.datamation.iso20022.fednow.replies.FIToFICustomerCreditTransferFednowAutoReplies;
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 Pacs008FednowMessageAutoReplies {
public static void main(String... args) {
execute();
}
public static void execute() {
paymentReturnAutoReply();
paymentCancellationRequestAutoReply();
}
public static void paymentReturnAutoReply() {
try {
//Initialize the message object
FIToFICustomerCreditTransfer08Fednow fiToFICustomerCreditTransfer = new FIToFICustomerCreditTransfer08Fednow();
//Optionally use an existing message if we do not want to create the object from scratch
fiToFICustomerCreditTransfer.parseXML(validFednowPacs008String);
//Perform validation
ValidationErrorList validationErrorList = fiToFICustomerCreditTransfer.validate();
if (!validationErrorList.isEmpty())
throw new Exception("Invalid pacs.008 message to return");
FIToFICustomerCreditTransferFednowAutoReplies<FIToFICustomerCreditTransfer08Fednow, PaymentReturn10Fednow> pacs008AutoReplies =
new FIToFICustomerCreditTransferFednowAutoReplies<>(fiToFICustomerCreditTransfer);
MsgReplyInfo msgReplyInfo = new MsgReplyInfo();
ReasonInformation reasonInformation = new ReasonInformation();
msgReplyInfo.setRsnInf(reasonInformation);
reasonInformation.setType(ReasonInformation.Type.CD); //mandatory
reasonInformation.setValue("AC01"); //mandatory
reasonInformation.setAddtlInf(Collections.singletonList("Additional info")); //optional
msgReplyInfo.setReplyId("pacs008Reply"); //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
pacs008AutoReplies.setConnectionPartyIdentifier("12345678"); //Optional part of GrpHdr/MsgId default value is "XXXXXXXX"
PaymentReturn10Fednow pacs004 = pacs008AutoReplies.autoReply(new PaymentReturn10Fednow(), 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 paymentCancellationRequestAutoReply() {
try {
//Initialize the message object
FIToFICustomerCreditTransfer08Fednow fiToFICustomerCreditTransfer = new FIToFICustomerCreditTransfer08Fednow();
//Optionally use an existing message if we do not want to create the object from scratch
fiToFICustomerCreditTransfer.parseXML(validFednowPacs008String);
//Perform validation
ValidationErrorList validationErrorList = fiToFICustomerCreditTransfer.validate();
if (!validationErrorList.isEmpty())
throw new Exception("Invalid pacs.008 message to cancel");
FIToFICustomerCreditTransferFednowAutoReplies<FIToFICustomerCreditTransfer08Fednow, FIToFIPaymentCancellationRequest08Fednow> pacs008AutoReplies =
new FIToFICustomerCreditTransferFednowAutoReplies<>(fiToFICustomerCreditTransfer);
MsgReplyInfo msgReplyInfo = new MsgReplyInfo();
ReasonInformation reasonInformation = new ReasonInformation();
msgReplyInfo.setRsnInf(reasonInformation);
reasonInformation.setType(ReasonInformation.Type.CD); //mandatory
reasonInformation.setValue("AGNT"); //mandatory
reasonInformation.setAddtlInf(Collections.singletonList("Additional info")); //optional
msgReplyInfo.setReplyId("pacs008Reply"); //optional
msgReplyInfo.setOrgnlMsgId("1234"); //optional
FIToFIPaymentCancellationRequest08Fednow camt056 = pacs008AutoReplies.autoReply(new FIToFIPaymentCancellationRequest08Fednow(),
Collections.singletonList(msgReplyInfo));
validationErrorList = camt056.validate();
if (validationErrorList.isEmpty()) {
System.out.println("Cancellation Request Message is valid");
System.out.println(camt056.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 validFednowPacs008String = "<Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08\"\n" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xsi:schemaLocation=\"urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08 CustomerCreditTransfer_pacs_008_001_08.xsd\">\n" +
" <FIToFICstmrCdtTrf>\n" +
" <GrpHdr>\n" +
" <MsgId>20230604011104238Sc01Step1MsgId</MsgId>\n" +
" <CreDtTm>2023-06-04T10:55:26-04:00</CreDtTm>\n" +
" <NbOfTxs>1</NbOfTxs>\n" +
" <SttlmInf>\n" +
" <SttlmMtd>CLRG</SttlmMtd>\n" +
" <ClrSys>\n" +
" <Cd>FDN</Cd>\n" +
" </ClrSys>\n" +
" </SttlmInf>\n" +
" </GrpHdr>\n" +
" <CdtTrfTxInf>\n" +
" <PmtId>\n" +
" <InstrId>Scenario01InstrId001</InstrId>\n" +
" <EndToEndId>Scenario01EtoEId001</EndToEndId>\n" +
" <UETR>8a562c67-ca16-48ba-b074-65581be6f011</UETR>\n" +
" </PmtId>\n" +
" <PmtTpInf>\n" +
" <LclInstrm>\n" +
" <Prtry>FDNA</Prtry>\n" +
" </LclInstrm>\n" +
" <CtgyPurp>\n" +
" <Prtry>CONS</Prtry>\n" +
" </CtgyPurp>\n" +
" </PmtTpInf>\n" +
" <IntrBkSttlmAmt Ccy=\"USD\">51.74</IntrBkSttlmAmt>\n" +
" <IntrBkSttlmDt>2023-06-04</IntrBkSttlmDt>\n" +
" <ChrgBr>SLEV</ChrgBr>\n" +
"\n" +
" <InstgAgt>\n" +
" <FinInstnId>\n" +
" <ClrSysMmbId>\n" +
" <ClrSysId>\n" +
" <Cd>USABA</Cd>\n" +
" </ClrSysId>\n" +
" <MmbId>011104238</MmbId>\n" +
" </ClrSysMmbId>\n" +
" </FinInstnId>\n" +
" </InstgAgt>\n" +
" <InstdAgt>\n" +
" <FinInstnId>\n" +
" <ClrSysMmbId>\n" +
" <ClrSysId>\n" +
" <Cd>USABA</Cd>\n" +
" </ClrSysId>\n" +
" <MmbId>021040078</MmbId>\n" +
" </ClrSysMmbId>\n" +
" </FinInstnId>\n" +
" </InstdAgt>\n" +
" <Dbtr>\n" +
" <Nm>Individual A</Nm>\n" +
" <PstlAdr>\n" +
" <StrtNm>Dream Road</StrtNm>\n" +
" <BldgNb>450</BldgNb>\n" +
" <Room>141</Room>\n" +
" <PstCd>60532</PstCd>\n" +
" <TwnNm>Lisle</TwnNm>\n" +
" <CtrySubDvsn>IL</CtrySubDvsn>\n" +
" <Ctry>US</Ctry>\n" +
" </PstlAdr>\n" +
" </Dbtr>\n" +
" <DbtrAcct>\n" +
" <Id>\n" +
" <Othr>\n" +
" <Id>0031234567</Id>\n" +
" </Othr>\n" +
" </Id>\n" +
" </DbtrAcct>\n" +
" <DbtrAgt>\n" +
" <FinInstnId>\n" +
" <ClrSysMmbId>\n" +
" <ClrSysId>\n" +
" <Cd>USABA</Cd>\n" +
" </ClrSysId>\n" +
" <MmbId>011104238</MmbId>\n" +
" </ClrSysMmbId>\n" +
" <Nm>BankA</Nm>\n" +
" </FinInstnId>\n" +
" </DbtrAgt>\n" +
" <CdtrAgt>\n" +
" <FinInstnId>\n" +
" <ClrSysMmbId>\n" +
" <ClrSysId>\n" +
" <Cd>USABA</Cd>\n" +
" </ClrSysId>\n" +
" <MmbId>021040078</MmbId>\n" +
" </ClrSysMmbId>\n" +
" </FinInstnId>\n" +
" </CdtrAgt>\n" +
" <Cdtr>\n" +
" <Nm>Corporation B</Nm>\n" +
" <PstlAdr>\n" +
" <PstBx>6001</PstBx>\n" +
" <PstCd>60197</PstCd>\n" +
" <TwnNm>Carol Stream</TwnNm>\n" +
" <CtrySubDvsn>IL</CtrySubDvsn>\n" +
" <Ctry>US</Ctry>\n" +
" </PstlAdr>\n" +
" </Cdtr>\n" +
" <CdtrAcct>\n" +
" <Id>\n" +
" <Othr>\n" +
" <Id>56478374687</Id>\n" +
" </Othr>\n" +
" </Id>\n" +
" </CdtrAcct>\n" +
" <RmtInf>\n" +
" <Strd>\n" +
" <RfrdDocInf>\n" +
" <Tp>\n" +
" <CdOrPrtry>\n" +
" <Cd>CINV</Cd>\n" +
" </CdOrPrtry>\n" +
" </Tp>\n" +
" <Nb>INV34563</Nb>\n" +
" <RltdDt>2023-06-01</RltdDt>\n" +
" </RfrdDocInf>\n" +
" </Strd>\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