Search in sources :

Example 1 with AccountReference

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

the class PeriodicPaymentMultipartBodySerializer method xmlDeserialize.

public static PeriodicPayment xmlDeserialize(Document sepaDocument, PeriodicPayment periodicPayment) throws ParseException {
    if (periodicPayment.getDebtorAccount() == null) {
        periodicPayment.setDebtorAccount(new AccountReference());
    }
    AccountReference debtorAccount = periodicPayment.getDebtorAccount();
    periodicPayment.setDebtorName(sepaDocument.getCctInitiation().getPmtInfos().get(0).getDebitor().getName());
    debtorAccount.setIban(sepaDocument.getCctInitiation().getPmtInfos().get(0).getDebtorAccountIBAN());
    debtorAccount.setCurrency(Currency.EUR);
    String creditorAccountName = sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector().get(0).getCreditorName();
    String creditorAccountIdentifier = sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector().get(0).getCreditorIBAN();
    String creditorAgent = sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector().get(0).getCreditorAgent();
    if (periodicPayment.getCreditorAccount() == null) {
        periodicPayment.setCreditorAccount(new AccountReference());
    }
    AccountReference creditorAccount = periodicPayment.getCreditorAccount();
    periodicPayment.setCreditorName(creditorAccountName);
    creditorAccount.setIban(creditorAccountIdentifier);
    creditorAccount.setCurrency(Currency.EUR);
    periodicPayment.setCreditorAgent(creditorAgent);
    String amount = Double.toString(sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector().get(0).getAmount());
    String remittanceInformationUnstructured = sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector().get(0).getVwz();
    String endToEndIdentification = sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector().get(0).getEndToEndID();
    Date requestExecutionDate = new SimpleDateFormat(XS2AJsonKeys.DATE_FORMAT.value()).parse(sepaDocument.getCctInitiation().getPmtInfos().get(0).getRequestedExecutionDate());
    periodicPayment.setInstructedAmount(new Amount(amount));
    periodicPayment.setRemittanceInformationUnstructured(remittanceInformationUnstructured);
    periodicPayment.setEndToEndIdentification(endToEndIdentification);
    periodicPayment.setRequestedExecutionDate(requestExecutionDate);
    return periodicPayment;
}
Also used : Amount(net.petafuel.styx.core.xs2a.entities.Amount) AccountReference(net.petafuel.styx.core.xs2a.entities.AccountReference) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with AccountReference

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

the class PaymentSerializer method xmlDeserialize.

public static InitializablePayment xmlDeserialize(Document sepaDocument, PaymentService paymentService) throws ParseException {
    ArrayList<SinglePayment> payments = new ArrayList<>();
    AccountReference debtorAccount = new AccountReference();
    debtorAccount.setName(sepaDocument.getCctInitiation().getPmtInfos().get(0).getDebtorName());
    debtorAccount.setIban(sepaDocument.getCctInitiation().getPmtInfos().get(0).getDebtorAccountIBAN());
    debtorAccount.setCurrency(Currency.EUR);
    Date requestedExecutionDate = new SimpleDateFormat(XS2AJsonKeys.DATE_FORMAT.value()).parse(sepaDocument.getCctInitiation().getPmtInfos().get(0).getRequestedExecutionDate());
    for (CreditTransferTransactionInformation ctti : sepaDocument.getCctInitiation().getPmtInfos().get(0).getCreditTransferTransactionInformationVector()) {
        String creditorAccountName = ctti.getCreditorName();
        String creditorAccountIdentifier = ctti.getCreditorIBAN();
        AccountReference creditorAccount = new AccountReference(creditorAccountIdentifier, AccountReference.Type.IBAN);
        creditorAccount.setName(creditorAccountName);
        creditorAccount.setCurrency(Currency.EUR);
        String amount = Double.toString(ctti.getAmount());
        String remittanceInformationUnstructured = ctti.getVwz();
        String endToEndIdentification = ctti.getEndToEndID();
        SinglePayment payment = new SinglePayment();
        payment.setInstructedAmount(new Amount(amount, Currency.EUR));
        payment.setCreditorAccount(creditorAccount);
        payment.setDebtorAccount(debtorAccount);
        payment.setRemittanceInformationUnstructured(remittanceInformationUnstructured);
        payment.setEndToEndIdentification(endToEndIdentification);
        payment.setRequestedExecutionDate(requestedExecutionDate);
        payments.add(payment);
    }
    if (paymentService.equals(PaymentService.BULK_PAYMENTS)) {
        BulkPayment bulkPayment = new BulkPayment();
        bulkPayment.setPayments(payments);
        bulkPayment.setDebtorAccount(debtorAccount);
        bulkPayment.setRequestedExecutionDate(requestedExecutionDate);
        return bulkPayment;
    }
    return payments.get(0);
}
Also used : Amount(net.petafuel.styx.core.xs2a.entities.Amount) ArrayList(java.util.ArrayList) CreditTransferTransactionInformation(net.petafuel.jsepa.model.CreditTransferTransactionInformation) AccountReference(net.petafuel.styx.core.xs2a.entities.AccountReference) BulkPayment(net.petafuel.styx.core.xs2a.entities.BulkPayment) SinglePayment(net.petafuel.styx.core.xs2a.entities.SinglePayment) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with AccountReference

use of net.petafuel.styx.core.xs2a.entities.AccountReference 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 4 with AccountReference

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

the class PersistentConsentIntegrationTest method setup.

@BeforeAll
public void setup() {
    AccountReference IngoZebadich = new AccountReference("DE48500105171271124579", AccountReference.Type.IBAN);
    AccountReference MiaDochegal = new AccountReference("4253614013", AccountReference.Type.BBAN);
    AccountReference KlaraFall = new AccountReference("AAAPL1234C", AccountReference.Type.PAN);
    AccountReference JohannesBeer = new AccountReference("460323255272", AccountReference.Type.MSISDN);
    consent = new Consent();
    consent.setId(String.valueOf(UUID.randomUUID()));
    consent.setState(ConsentStatus.RECEIVED);
    consent.getAccess().setTransactions(Arrays.asList(KlaraFall, JohannesBeer));
    consent.getAccess().setBalances(Arrays.asList(IngoZebadich, MiaDochegal));
    consent.setRecurringIndicator(false);
    consent.setFrequencyPerDay(4);
    consent.getSca().setApproach(SCA.Approach.REDIRECT);
    consent.setCombinedServiceIndicator(false);
    PSU psu = new PSU("PSU-ID-33241");
    psu.setIdType("PSU-ID-TYPE-33241");
    psu.setIp("127.0.0.1");
    psu.setPort(9999);
    psu.setCorporateIdType("PSU-CO-ID-TYPE-33242");
    psu.setCorporateId("PSU-CO-ID-33242");
    psu.setGeoLocation("48.3938:11.7331");
    psu.setUserAgent("VIMpay 1.2.3");
    consent.setPsu(psu);
    consent.setxRequestId(UUID.randomUUID());
}
Also used : PSU(net.petafuel.styx.core.xs2a.entities.PSU) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) Consent(net.petafuel.styx.core.xs2a.entities.Consent) AccountReference(net.petafuel.styx.core.xs2a.entities.AccountReference) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with AccountReference

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

the class UniCreditPISIntegrationTest method createPayment.

@Test
@Category(IntegrationTest.class)
public void createPayment() {
    for (Map<String, String> testEntry : testData) {
        String bic = testEntry.get("bic");
        String debtorIban = testEntry.get("debtorIban");
        String creditorIban = testEntry.get("creditorIban");
        Invocation.Builder invocationBuilder = target("/v1/payments/sepa-credit-transfers").request();
        invocationBuilder.header("token", pisAccessToken);
        invocationBuilder.header("PSU-ID", "bgdemo");
        invocationBuilder.header("PSU-BIC", bic);
        invocationBuilder.header("PSU-ID-Type", "ALL");
        invocationBuilder.header("redirectPreferred", true);
        SinglePayment singlePayment = new SinglePayment();
        singlePayment.setDebtorAccount(new AccountReference(debtorIban, AccountReference.Type.IBAN));
        singlePayment.setCreditorAccount(new AccountReference(creditorIban, AccountReference.Type.IBAN));
        singlePayment.setInstructedAmount(new Amount("0.01"));
        singlePayment.setCreditorName("Test Creditor Name");
        singlePayment.setRemittanceInformationUnstructured("Styx PIS Test mit Umlaut ÄöÜ");
        SinglePaymentInitiation singlePaymentInitiation = new SinglePaymentInitiation();
        singlePaymentInitiation.setPayments(Collections.singletonList(singlePayment));
        Invocation invocation = invocationBuilder.buildPost(Entity.entity(singlePaymentInitiation, MediaType.APPLICATION_JSON));
        Response response = invocation.invoke(Response.class);
        Assertions.assertEquals(201, response.getStatus());
        try {
            Jsonb jsonb = JsonbBuilder.create();
            PaymentResponse paymentResponse = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), PaymentResponse.class);
            String singlePaymentId = paymentResponse.getPaymentId();
            Assertions.assertNotNull(singlePaymentId);
            testEntry.put("paymentId", singlePaymentId);
        } catch (IOException e) {
            Assertions.fail("exception while parsing response");
        }
    }
}
Also used : SinglePaymentInitiation(net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation) Invocation(javax.ws.rs.client.Invocation) InputStream(java.io.InputStream) Amount(net.petafuel.styx.core.xs2a.entities.Amount) IOException(java.io.IOException) SinglePayment(net.petafuel.styx.core.xs2a.entities.SinglePayment) PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) Response(javax.ws.rs.core.Response) Jsonb(javax.json.bind.Jsonb) AccountReference(net.petafuel.styx.core.xs2a.entities.AccountReference) Category(org.junit.experimental.categories.Category) StyxRESTTest(net.petafuel.styx.api.StyxRESTTest) IntegrationTest(net.petafuel.styx.api.IntegrationTest) Test(org.junit.Test)

Aggregations

AccountReference (net.petafuel.styx.core.xs2a.entities.AccountReference)8 Amount (net.petafuel.styx.core.xs2a.entities.Amount)6 SinglePayment (net.petafuel.styx.core.xs2a.entities.SinglePayment)5 Date (java.util.Date)4 SinglePaymentInitiation (net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation)3 Category (org.junit.experimental.categories.Category)3 SimpleDateFormat (java.text.SimpleDateFormat)2 PaymentResponse (net.petafuel.styx.api.v1.payment.entity.PaymentResponse)2 BulkPayment (net.petafuel.styx.core.xs2a.entities.BulkPayment)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Jsonb (javax.json.bind.Jsonb)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Invocation (javax.ws.rs.client.Invocation)1 Response (javax.ws.rs.core.Response)1