Search in sources :

Example 1 with EntryTransaction2

use of net.petafuel.styx.core.xs2a.utils.sepa.camt052.EntryTransaction2 in project styx by petafuel.

the class Camt052Converter method convertTransaction.

private void convertTransaction(AccountReport accountReport, ReportEntry2 originalPayment) {
    List<EntryDetails1> entryDetails = originalPayment.getNtryDtls();
    if (entryDetails != null && !entryDetails.isEmpty()) {
        List<EntryTransaction2> transactionDetails = entryDetails.get(0).getTxDtls();
        if (transactionDetails.isEmpty()) {
            LOG.info("Transaction has no IBAN/BIC, sender/receiver information");
            return;
        }
        if (transactionDetails.size() > 1) {
            LOG.error("Input contains more than one NtryDtls/TxDtls, only FIRST processed!");
        }
        // this will be the new transaction element in JSON array
        Transaction transaction = new Transaction();
        // from here, extract data from XML and map to JSON object
        // status
        EntryStatus2Code camtBookingStatus = originalPayment.getSts();
        if (camtBookingStatus.equals(EntryStatus2Code.BOOK) || camtBookingStatus.equals(EntryStatus2Code.INFO)) {
            accountReport.getBooked().add(transaction);
        } else {
            accountReport.getPending().add(transaction);
        }
        // bookingDate if present
        Optional.ofNullable(originalPayment.getBookgDt()).map(DateAndDateTimeChoice::getDt).map(XMLGregorianCalendar::toGregorianCalendar).map(GregorianCalendar::getTime).ifPresent(transaction::setBookingDate);
        // valueDate if present
        Optional.ofNullable(originalPayment.getValDt()).map(DateAndDateTimeChoice::getDt).map(XMLGregorianCalendar::toGregorianCalendar).map(GregorianCalendar::getTime).ifPresent(transaction::setValueDate);
        // creditDebit
        // amount
        // currency
        transaction.setTransactionAmount(new Amount());
        if (originalPayment.getCdtDbtInd().equals(CreditDebitCode.DBIT)) {
            BigDecimal amount = originalPayment.getAmt().getValue().negate();
            transaction.getTransactionAmount().setAmount(amount.toString());
            transaction.getTransactionAmount().setCurrency(Currency.valueOf(originalPayment.getAmt().getCcy()));
        }
        EntryTransaction2 firstTransactionDetails = transactionDetails.get(0);
        // debtor account
        TransactionParty2 transactionParty = firstTransactionDetails.getRltdPties();
        transaction.setDebtorAccount(new AccountReference(transactionParty.getDbtrAcct().getId().getIBAN(), AccountReference.Type.IBAN));
        // optionally set debtor name
        Optional.ofNullable(transactionParty.getDbtr()).map(PartyIdentification32::getNm).ifPresent(transaction::setDebtorName);
        // set debtor agent if present
        Optional.ofNullable(firstTransactionDetails.getRltdAgts()).map(TransactionAgents2::getDbtrAgt).map(BranchAndFinancialInstitutionIdentification4::getFinInstnId).map(FinancialInstitutionIdentification7::getBIC).ifPresent(transaction::setDebtorAgent);
        // creditor account
        transaction.setCreditorAccount(new AccountReference(firstTransactionDetails.getRltdPties().getCdtrAcct().getId().getIBAN(), AccountReference.Type.IBAN));
        // set creditor name if present
        Optional.ofNullable(transactionParty.getCdtr()).map(PartyIdentification32::getNm).ifPresent(transaction::setCreditorName);
        // set creditor agent if present
        Optional.ofNullable(firstTransactionDetails.getRltdAgts()).map(TransactionAgents2::getCdtrAgt).map(BranchAndFinancialInstitutionIdentification4::getFinInstnId).map(FinancialInstitutionIdentification7::getBIC).ifPresent(transaction::setCreditorAgent);
        // reference
        transaction.setRemittanceInformationUnstructured(String.join("\n", firstTransactionDetails.getRmtInf().getUstrd()));
        // set e2e reference if present
        Optional.ofNullable(firstTransactionDetails.getRefs()).map(TransactionReferences2::getEndToEndId).ifPresent(transaction::setEndToEndId);
        // set additional information
        transaction.setAdditionalInformation(originalPayment.getAddtlNtryInf());
    }
}
Also used : BranchAndFinancialInstitutionIdentification4(net.petafuel.styx.core.xs2a.utils.sepa.camt052.BranchAndFinancialInstitutionIdentification4) Amount(net.petafuel.styx.core.xs2a.entities.Amount) BigDecimal(java.math.BigDecimal) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) EntryDetails1(net.petafuel.styx.core.xs2a.utils.sepa.camt052.EntryDetails1) Transaction(net.petafuel.styx.core.xs2a.entities.Transaction) EntryStatus2Code(net.petafuel.styx.core.xs2a.utils.sepa.camt052.EntryStatus2Code) AccountReference(net.petafuel.styx.core.xs2a.entities.AccountReference) TransactionParty2(net.petafuel.styx.core.xs2a.utils.sepa.camt052.TransactionParty2) EntryTransaction2(net.petafuel.styx.core.xs2a.utils.sepa.camt052.EntryTransaction2)

Aggregations

BigDecimal (java.math.BigDecimal)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 AccountReference (net.petafuel.styx.core.xs2a.entities.AccountReference)1 Amount (net.petafuel.styx.core.xs2a.entities.Amount)1 Transaction (net.petafuel.styx.core.xs2a.entities.Transaction)1 BranchAndFinancialInstitutionIdentification4 (net.petafuel.styx.core.xs2a.utils.sepa.camt052.BranchAndFinancialInstitutionIdentification4)1 EntryDetails1 (net.petafuel.styx.core.xs2a.utils.sepa.camt052.EntryDetails1)1 EntryStatus2Code (net.petafuel.styx.core.xs2a.utils.sepa.camt052.EntryStatus2Code)1 EntryTransaction2 (net.petafuel.styx.core.xs2a.utils.sepa.camt052.EntryTransaction2)1 TransactionParty2 (net.petafuel.styx.core.xs2a.utils.sepa.camt052.TransactionParty2)1