Last active
January 22, 2021 10:06
-
-
Save apolichronopoulos/27892018e62f36344044987daa299bc0 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.common.MsgReplyInfo; | |
import gr.datamation.sepa.core.messages.common.ReasonCode; | |
import gr.datamation.sepa.core.messages.eba.pacs.FIToFICustomerCreditTransfer; | |
import gr.datamation.sepa.core.messages.eba.pacs.PaymentReturn; | |
import java.util.Calendar; | |
import java.util.Date; | |
import java.util.Vector; | |
public class SepaTestPacs008AutoReplyPacs004 { | |
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 pacs008message = 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 | |
pacs008message.parseAndValidateString(validPacs008String); | |
if (pacs008message.hasValidationErrors()) { | |
pacs008message.printValidationErrors(); | |
} else { | |
System.out.println(pacs008message.toString()); | |
} | |
System.out.println("-----------------------------\n"); | |
//Initialize a payment return (pacs.004) and set basic information | |
PaymentReturn pacs004message = new PaymentReturn(); | |
//message id is commonly auto-generated by each system | |
pacs004message.setElement("/GrpHdr/MsgId", "OURMESSAGEID"); | |
//The settlement date for our return | |
pacs004message.setElement("/GrpHdr/IntrBkSttlmDt", Calendar.getInstance()); | |
//Select settlement method (in most cases this is set to CLRG...) | |
pacs004message.setElement("/GrpHdr/SttlmInf/SttlmMtd", "CLRG"); | |
//and Clearing system is set to ST2 | |
pacs004message.setElement("/GrpHdr/SttlmInf/ClrSys/Prtry", "ST2"); | |
//Construct the message reply information | |
//Here we are returning a message with reason code AC01 and with no charges | |
//Charges have effect only for reason code FOCR (acceptance of Request for Recall) | |
Vector<MsgReplyInfo> msgReplyInfo = new Vector<MsgReplyInfo>(); | |
ReasonCode rc = new ReasonCode(ReasonCode.CD, "AC01", null, null); | |
//The message reply info has the transaction Id of the payment we want to return, the reason code info, a return Id we generate, | |
//an instruction id and the settlement date of the payment that we return | |
MsgReplyInfo mri = new MsgReplyInfo("TXID", rc, MsgReplyInfo.MSGID_BASED, "RETURNID", "", new Date()); | |
msgReplyInfo.add(mri); | |
pacs004message = (PaymentReturn) pacs008message.autoReply(pacs004message, msgReplyInfo); | |
if (pacs004message.hasValidationErrors()) { | |
pacs004message.printValidationErrors(); | |
} else { | |
System.out.println(pacs004message.toString()); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
System.err.println(e.getMessage()); | |
} | |
} | |
private static final String validPacs008String = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + | |
"<Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02\">\n" + | |
" <FIToFICstmrCdtTrf>\n" + | |
" <GrpHdr>\n" + | |
" <MsgId>MESSAGEID</MsgId>\n" + | |
" <CreDtTm>2021-01-21T12:56:04</CreDtTm>\n" + | |
" <NbOfTxs>1</NbOfTxs>\n" + | |
" <TtlIntrBkSttlmAmt Ccy=\"EUR\">20</TtlIntrBkSttlmAmt>\n" + | |
" <IntrBkSttlmDt>2021-01-21</IntrBkSttlmDt>\n" + | |
" <SttlmInf>\n" + | |
" <SttlmMtd>CLRG</SttlmMtd>\n" + | |
" <ClrSys>\n" + | |
" <Prtry>ST2</Prtry>\n" + | |
" </ClrSys>\n" + | |
" </SttlmInf>\n" + | |
" <InstdAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BIC>MILBGRAA</BIC>\n" + | |
" </FinInstnId>\n" + | |
" </InstdAgt>\n" + | |
" </GrpHdr>\n" + | |
" <CdtTrfTxInf>\n" + | |
" <PmtId>\n" + | |
" <InstrId>INSTRUCTIONID</InstrId>\n" + | |
" <EndToEndId>NOTPROVIDED</EndToEndId>\n" + | |
" <TxId>TXID</TxId>\n" + | |
" </PmtId>\n" + | |
" <PmtTpInf>\n" + | |
" <SvcLvl>\n" + | |
" <Cd>SEPA</Cd>\n" + | |
" </SvcLvl>\n" + | |
" </PmtTpInf>\n" + | |
" <IntrBkSttlmAmt Ccy=\"EUR\">20</IntrBkSttlmAmt>\n" + | |
" <ChrgBr>SLEV</ChrgBr>\n" + | |
" <Dbtr>\n" + | |
" <Nm>DEBTOR NAME</Nm>\n" + | |
" <Id>\n" + | |
" <OrgId>\n" + | |
" <BICOrBEI>AAAADEFFXXX</BICOrBEI>\n" + | |
" </OrgId>\n" + | |
" </Id>\n" + | |
" </Dbtr>\n" + | |
" <DbtrAcct>\n" + | |
" <Id>\n" + | |
" <IBAN>DE36500400000586060600</IBAN>\n" + | |
" </Id>\n" + | |
" </DbtrAcct>\n" + | |
" <DbtrAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BIC>COBADEFFXXX</BIC>\n" + | |
" </FinInstnId>\n" + | |
" </DbtrAgt>\n" + | |
" <CdtrAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BIC>CYDBCY2N</BIC>\n" + | |
" </FinInstnId>\n" + | |
" </CdtrAgt>\n" + | |
" <Cdtr>\n" + | |
" <Nm>CREDITOR NAME</Nm>\n" + | |
" <Id>\n" + | |
" <OrgId>\n" + | |
" <BICOrBEI>CYDBCY2NXXX</BICOrBEI>\n" + | |
" </OrgId>\n" + | |
" </Id>\n" + | |
" </Cdtr>\n" + | |
" <CdtrAcct>\n" + | |
" <Id>\n" + | |
" <IBAN>CY21003000700000007011014888</IBAN>\n" + | |
" </Id>\n" + | |
" </CdtrAcct>\n" + | |
" </CdtTrfTxInf>\n" + | |
" </FIToFICstmrCdtTrf>\n" + | |
"</Document>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment