Last active
November 3, 2022 11:08
-
-
Save johnmara-pc14/664a90fcff8d6a998d348b39b4a896b3 to your computer and use it in GitHub Desktop.
Pacs008Target2MessageAutoReplies
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
package com.paymentcomponents.swift.mx.target2; | |
import gr.datamation.replies.common.ChargesInformation; | |
import gr.datamation.replies.common.MsgReplyInfo; | |
import gr.datamation.replies.common.ReasonInformation; | |
import gr.datamation.iso20022.target2.camt.FIToFIPaymentCancellationRequest08Rtgs; | |
import gr.datamation.iso20022.target2.pacs.FIToFICustomerCreditTransfer08Rtgs; | |
import gr.datamation.iso20022.target2.pacs.PaymentReturn09Rtgs; | |
import gr.datamation.iso20022.target2.replies.FIToFICustomerCreditTransferRtgsAutoReplies; | |
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 Pacs008Target2MessageAutoReplies { | |
public static void main(String... args) { | |
execute(); | |
} | |
public static void execute() { | |
paymentReturnAutoReply(); | |
paymentCancellationRequestAutoReply(); | |
} | |
public static void paymentReturnAutoReply() { | |
try { | |
//Initialize the message object | |
FIToFICustomerCreditTransfer08Rtgs fiToFICustomerCreditTransfer = new FIToFICustomerCreditTransfer08Rtgs(); | |
//Optionally use an existing message if we do not want to create the object from scratch | |
fiToFICustomerCreditTransfer.parseXML(validRtgsPacs008String); | |
//Perform validation | |
ValidationErrorList validationErrorList = fiToFICustomerCreditTransfer.validate(); | |
if (!validationErrorList.isEmpty()) | |
throw new Exception("Invalid pacs.008 message to return"); | |
FIToFICustomerCreditTransferRtgsAutoReplies<FIToFICustomerCreditTransfer08Rtgs, PaymentReturn09Rtgs> pacs008AutoReplies = | |
new FIToFICustomerCreditTransferRtgsAutoReplies<>(fiToFICustomerCreditTransfer); | |
MsgReplyInfo msgReplyInfo = new MsgReplyInfo(); | |
ReasonInformation reasonInformation = new ReasonInformation(); | |
msgReplyInfo.setRsnInf(reasonInformation); | |
reasonInformation.setType(ReasonInformation.Type.CD); //mandatory, or ReasonInformation.Type.PRTRY for proprietary | |
reasonInformation.setValue("AC01"); //mandatory | |
reasonInformation.setAddtlInf(Collections.singletonList("Additional info")); //optional | |
msgReplyInfo.setReplyId("pacs008Reply"); //optional | |
msgReplyInfo.setOrgnlMsgId("1234"); //mandatory in RTGS | |
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 | |
PaymentReturn09Rtgs pacs004 = pacs008AutoReplies.autoReply(new PaymentReturn09Rtgs(), 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 | |
FIToFICustomerCreditTransfer08Rtgs fiToFICustomerCreditTransfer = new FIToFICustomerCreditTransfer08Rtgs(); | |
//Optionally use an existing message if we do not want to create the object from scratch | |
fiToFICustomerCreditTransfer.parseXML(validRtgsPacs008String); | |
//Perform validation | |
ValidationErrorList validationErrorList = fiToFICustomerCreditTransfer.validate(); | |
if (!validationErrorList.isEmpty()) | |
throw new Exception("Invalid pacs.008 message to cancel"); | |
FIToFICustomerCreditTransferRtgsAutoReplies<FIToFICustomerCreditTransfer08Rtgs, FIToFIPaymentCancellationRequest08Rtgs> pacs008AutoReplies = | |
new FIToFICustomerCreditTransferRtgsAutoReplies<>(fiToFICustomerCreditTransfer); | |
MsgReplyInfo msgReplyInfo = new MsgReplyInfo(); | |
ReasonInformation reasonInformation = new ReasonInformation(); | |
msgReplyInfo.setRsnInf(reasonInformation); | |
reasonInformation.setType(ReasonInformation.Type.CD); //mandatory, or ReasonInformation.Type.PRTRY for proprietary | |
reasonInformation.setValue("AGNT"); //mandatory | |
reasonInformation.setAddtlInf(Collections.singletonList("Additional info")); //optional | |
msgReplyInfo.setReplyId("pacs008Reply"); //optional | |
msgReplyInfo.setOrgnlMsgId("1234"); //mandatory in RTGS | |
FIToFIPaymentCancellationRequest08Rtgs camt056 = pacs008AutoReplies.autoReply(new FIToFIPaymentCancellationRequest08Rtgs(), | |
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 validRtgsPacs008String = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + | |
"<Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08\">\n" + | |
" <FIToFICstmrCdtTrf>\n" + | |
" <GrpHdr>\n" + | |
" <MsgId>NONREF</MsgId>\n" + | |
" <CreDtTm>2019-10-07T09:30:00+00:00</CreDtTm>\n" + | |
" <NbOfTxs>1</NbOfTxs>\n" + | |
" <SttlmInf>\n" + | |
" <SttlmMtd>CLRG</SttlmMtd>\n" + | |
" <ClrSys>\n" + | |
" <Cd>TGT</Cd>\n" + | |
" </ClrSys>\n" + | |
" </SttlmInf>\n" + | |
" </GrpHdr>\n" + | |
" <CdtTrfTxInf>\n" + | |
" <PmtId>\n" + | |
" <InstrId>Inp008b020-InsId</InstrId>\n" + | |
" <EndToEndId>Inp008b020-E2EId</EndToEndId>\n" + | |
" <UETR>e008b020-59c5-41e9-be4c-d45102fc201e</UETR>\n" + | |
" </PmtId>\n" + | |
" <IntrBkSttlmAmt Ccy=\"EUR\">18000</IntrBkSttlmAmt>\n" + | |
" <IntrBkSttlmDt>2019-10-27</IntrBkSttlmDt>\n" + | |
" <ChrgBr>DEBT</ChrgBr>\n" + | |
" <InstgAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BICFI>PBBBDEFFXXX</BICFI>\n" + | |
" </FinInstnId>\n" + | |
" </InstgAgt>\n" + | |
" <InstdAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BICFI>PBAADEFFAC2</BICFI>\n" + | |
" </FinInstnId>\n" + | |
" </InstdAgt>\n" + | |
" <UltmtDbtr>\n" + | |
" <Nm>Ultimate debtor name</Nm>\n" + | |
" <Id>\n" + | |
" <OrgId>\n" + | |
" <AnyBIC>ULTMDBTRBIC</AnyBIC>\n" + | |
" </OrgId>\n" + | |
" </Id>\n" + | |
" </UltmtDbtr>\n" + | |
" <Dbtr>\n" + | |
" <Nm>Debtor name</Nm>\n" + | |
" <Id>\n" + | |
" <OrgId>\n" + | |
" <AnyBIC>DEBTORXXBIC</AnyBIC>\n" + | |
" </OrgId>\n" + | |
" </Id>\n" + | |
" </Dbtr>\n" + | |
" <DbtrAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BICFI>DEBTORXXAGT</BICFI>\n" + | |
" </FinInstnId>\n" + | |
" </DbtrAgt>\n" + | |
" <CdtrAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BICFI>CREDITORAGT</BICFI>\n" + | |
" </FinInstnId>\n" + | |
" </CdtrAgt>\n" + | |
" <Cdtr>\n" + | |
" <Nm>Creditor name</Nm>\n" + | |
" <Id>\n" + | |
" <OrgId>\n" + | |
" <AnyBIC>CREDITORBIC</AnyBIC>\n" + | |
" </OrgId>\n" + | |
" </Id>\n" + | |
" </Cdtr>\n" + | |
" <UltmtCdtr>\n" + | |
" <Nm>Ultimate creditor name</Nm>\n" + | |
" <Id>\n" + | |
" <OrgId>\n" + | |
" <AnyBIC>ULTMCDTRBIC</AnyBIC>\n" + | |
" </OrgId>\n" + | |
" </Id>\n" + | |
" </UltmtCdtr>\n" + | |
" </CdtTrfTxInf>\n" + | |
" </FIToFICstmrCdtTrf>\n" + | |
"</Document>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment