Search in sources :

Example 1 with Amount

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

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

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

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

Example 5 with Amount

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

the class SparkassePISIntegrationTest method test_INIT_SCTSinglePayment_SCA_OAUTH.

@Category(IntegrationTest.class)
@ParameterizedTest
@ArgumentsSource(SparkassePSUProvider.class)
void test_INIT_SCTSinglePayment_SCA_OAUTH(String psuBic, String psuId, String creditorIban, String debtorIban) {
    Assume.assumeNotNull(PIS_TOKEN);
    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(psuId);
    singlePayment.setRemittanceInformationUnstructured("Styx PIS Test unixstamp: " + new Date().getTime());
    SinglePaymentInitiation singlePaymentInitiation = new SinglePaymentInitiation();
    singlePaymentInitiation.setPayments(Collections.singletonList(singlePayment));
    given().contentType(ContentType.JSON).header("token", PIS_TOKEN).header("psu-id", psuId).header("psu-bic", psuBic).header("redirectPreferred", "true").body(singlePaymentInitiation).post("/v1/payments/sepa-credit-transfers").then().assertThat().header("content-type", Matchers.containsString("application/json")).statusCode(201).body("transactionStatus", Matchers.is(TransactionStatus.RCVD.name())).body("paymentId", Matchers.notNullValue()).body("links.scaOAuth.href", Matchers.notNullValue());
}
Also used : SinglePaymentInitiation(net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation) Amount(net.petafuel.styx.core.xs2a.entities.Amount) AccountReference(net.petafuel.styx.core.xs2a.entities.AccountReference) SinglePayment(net.petafuel.styx.core.xs2a.entities.SinglePayment) Date(java.util.Date) Category(org.junit.experimental.categories.Category) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Aggregations

AccountReference (net.petafuel.styx.core.xs2a.entities.AccountReference)6 Amount (net.petafuel.styx.core.xs2a.entities.Amount)6 Date (java.util.Date)4 SinglePayment (net.petafuel.styx.core.xs2a.entities.SinglePayment)4 SinglePaymentInitiation (net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation)3 Category (org.junit.experimental.categories.Category)3 SimpleDateFormat (java.text.SimpleDateFormat)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 Invocation (javax.ws.rs.client.Invocation)1 Response (javax.ws.rs.core.Response)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 CreditTransferTransactionInformation (net.petafuel.jsepa.model.CreditTransferTransactionInformation)1 IntegrationTest (net.petafuel.styx.api.IntegrationTest)1 StyxRESTTest (net.petafuel.styx.api.StyxRESTTest)1