Search in sources :

Example 1 with Transaction

use of net.petafuel.styx.core.xs2a.entities.Transaction 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)

Example 2 with Transaction

use of net.petafuel.styx.core.xs2a.entities.Transaction in project styx by petafuel.

the class ConsorsAISTest method testTransactionDetails.

@Test
@Order(5)
public void testTransactionDetails() throws BankRequestFailedException, BankLookupFailedException, BankNotFoundException {
    XS2AStandard standard = (new SAD()).getBankByBIC(BIC, true);
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setAccountId(ACCOUNT_ID);
    xs2AFactoryInput.setTransactionId(TRANSACTION_ID);
    xs2AFactoryInput.setConsentId(CONSENT);
    AISRequest aisRequest = new AISRequestFactory().create(standard.getRequestClassProvider().accountTransactionDetails(), xs2AFactoryInput);
    Transaction result = standard.getAis().getTransaction(aisRequest);
    Assertions.assertNotNull(result);
    Assertions.assertNotNull(result.getDebtorAccount());
}
Also used : XS2AStandard(net.petafuel.styx.core.banklookup.XS2AStandard) Transaction(net.petafuel.styx.core.xs2a.entities.Transaction) AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) SAD(net.petafuel.styx.core.banklookup.sad.SAD) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) AISRequestFactory(net.petafuel.styx.core.xs2a.factory.AISRequestFactory) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Aggregations

Transaction (net.petafuel.styx.core.xs2a.entities.Transaction)2 BigDecimal (java.math.BigDecimal)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 XS2AStandard (net.petafuel.styx.core.banklookup.XS2AStandard)1 SAD (net.petafuel.styx.core.banklookup.sad.SAD)1 AISRequest (net.petafuel.styx.core.xs2a.contracts.AISRequest)1 AccountReference (net.petafuel.styx.core.xs2a.entities.AccountReference)1 Amount (net.petafuel.styx.core.xs2a.entities.Amount)1 AISRequestFactory (net.petafuel.styx.core.xs2a.factory.AISRequestFactory)1 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)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 Order (org.junit.jupiter.api.Order)1 Test (org.junit.jupiter.api.Test)1 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)1