Search in sources :

Example 1 with SinglePayment

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

the class PaymentXMLSerializer method serialize.

public PAIN00100303Document serialize(String messageId, BulkPayment bulkPayment) {
    // Necessary variables for creating a PAIN00100303Document
    Date creationTime = new Date();
    double controlSum = 0d;
    String paymentMethod = "TRF";
    String chargeBearer = "SLEV";
    // Setting values for each instance
    groupHeader.setMessageId(messageId.substring(0, Math.min(messageId.length(), 35)));
    groupHeader.setCreationTime(creationTimeFormat.format(creationTime));
    groupHeader.setNoOfTransactions(bulkPayment.getPayments().size());
    groupHeader.setInitiatingPartyName(NOT_PROVIDED);
    ArrayList<CreditTransferTransactionInformation> list = new ArrayList<>();
    for (SinglePayment payment : bulkPayment.getPayments()) {
        CreditTransferTransactionInformation cdtTrfTxInf = new CreditTransferTransactionInformation();
        controlSum += Double.parseDouble(payment.getInstructedAmount().getAmount());
        cdtTrfTxInf.setEndToEndID(payment.getEndToEndIdentification() != null ? payment.getEndToEndIdentification() : UUID.randomUUID().toString());
        cdtTrfTxInf.setAmount(Double.parseDouble(payment.getInstructedAmount().getAmount()));
        cdtTrfTxInf.setCreditorName(payment.getCreditorName());
        cdtTrfTxInf.setCreditorIBAN(payment.getCreditorAccount().getIban());
        cdtTrfTxInf.setVwz(payment.getRemittanceInformationUnstructured());
        cdtTrfTxInf.setCreditorAgent(payment.getCreditorName());
        list.add(cdtTrfTxInf);
    }
    groupHeader.setControlSum(controlSum);
    pii.setPmtInfId(NOT_PROVIDED);
    pii.setPaymentMethod(paymentMethod);
    pii.setNoTxns(bulkPayment.getPayments().size());
    pii.setCtrlSum(controlSum);
    pii.setDebtorName(NOT_PROVIDED);
    pii.setDebtorAccountIBAN(bulkPayment.getDebtorAccount().getIban());
    pii.setChargeBearer(chargeBearer);
    pii.setBatchBooking(bulkPayment.getBatchBookingPreferred());
    pii.setCreditTransferTransactionInformationVector(list);
    if (bulkPayment.getRequestedExecutionDate() == null) {
        pii.setRequestedExecutionDate(requestedExecutionDateFormat.format(creationTime));
    } else {
        pii.setRequestedExecutionDate(requestedExecutionDateFormat.format(bulkPayment.getRequestedExecutionDate()));
    }
    pmtInfos.add(pii);
    ccInitation.setGrpHeader(groupHeader);
    ccInitation.setPmtInfos(pmtInfos);
    document.setCctInitiation(ccInitation);
    return document;
}
Also used : ArrayList(java.util.ArrayList) CreditTransferTransactionInformation(net.petafuel.jsepa.model.CreditTransferTransactionInformation) SinglePayment(net.petafuel.styx.core.xs2a.entities.SinglePayment) Date(java.util.Date)

Example 2 with SinglePayment

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

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

the class PaymentInitiationResource method initiateSinglePayment.

/**
 * Initiate single or future dated payments
 *
 * @param paymentTypeBean   contains which payment product is used
 * @param singlePaymentBody contains the request body as parsed json
 * @return 201 if successful
 * @throws BankRequestFailedException in case the communication between styx and aspsp was not successful
 */
@POST
@Path("/payments/{paymentProduct}")
@RequiresMandatoryHeader
@AcceptsPreStepAuth
public Response initiateSinglePayment(@BeanParam PaymentTypeBean paymentTypeBean, @Valid SinglePaymentInitiation singlePaymentBody) throws BankRequestFailedException {
    Optional<SinglePayment> singlePayment = singlePaymentBody.getPayments().stream().findFirst();
    if (!singlePayment.isPresent()) {
        throw new StyxException(new ResponseEntity("No valid single payment object was found within the payments array", ResponseConstant.BAD_REQUEST, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
    }
    SinglePayment payment = singlePayment.get();
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setPayment(payment);
    xs2AFactoryInput.setPsu(getPsu());
    xs2AFactoryInput.setPaymentService(PaymentService.PAYMENTS);
    xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    PISRequest paymentInitiationRequest = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentInitiation(), xs2AFactoryInput);
    paymentInitiationRequest.getHeaders().putAll(getAdditionalHeaders());
    paymentInitiationRequest.setTppRedirectPreferred(getRedirectPreferred());
    paymentInitiationRequest.setXrequestId(ThreadContext.get(RequestUUIDAdapter.REQUEST_UUID));
    ioProcessor.modifyRequest(paymentInitiationRequest, xs2AFactoryInput);
    InitiatedPayment initiatedPayment = getXS2AStandard().getPis().initiatePayment(paymentInitiationRequest);
    PersistentPayment.create(paymentInitiationRequest.getXrequestId(), initiatedPayment.getPaymentId(), (String) getContainerRequestContext().getProperty(AbstractTokenFilter.class.getName()), getXS2AStandard().getAspsp().getBic(), initiatedPayment.getStatus(), PaymentService.PAYMENTS, paymentTypeBean.getPaymentProduct());
    if (containerRequestContext.getProperty(PreAuthAccessFilter.class.getName()) != null) {
        initiatedPayment.setxRequestId(UUID.fromString(containerRequestContext.getHeaderString(PreAuthAccessFilter.PRE_AUTH_ID)));
    }
    xs2AFactoryInput.setPaymentId(initiatedPayment.getPaymentId());
    ioProcessor.modifyResponse(initiatedPayment, xs2AFactoryInput);
    PaymentResponse paymentResponse = new PaymentResponse(initiatedPayment);
    SCAApproach approach = SCAHandler.decision(initiatedPayment);
    if (approach instanceof OAuth2) {
        paymentResponse.getLinks().getScaOAuth().setUrl(((OAuth2) approach).getAuthoriseLink());
    }
    LOG.info("Initiate single payment bic={} aspsp_name={} aspsp_id={} paymentId={} xrequestid={}", getXS2AStandard().getAspsp().getBic(), getXS2AStandard().getAspsp().getName(), getXS2AStandard().getAspsp().getId(), paymentResponse.getPaymentId(), paymentInitiationRequest.getXrequestId());
    AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(PaymentService.PAYMENTS, paymentTypeBean.getPaymentProduct(), paymentResponse.getPaymentId(), null);
    paymentResponse.setLinks(aspspUrlMapper.map(paymentResponse.getLinks()));
    return Response.status(ResponseConstant.CREATED).entity(paymentResponse).build();
}
Also used : OAuth2(net.petafuel.styx.core.xs2a.sca.OAuth2) SCAApproach(net.petafuel.styx.core.xs2a.sca.SCAApproach) AspspUrlMapper(net.petafuel.styx.api.util.AspspUrlMapper) SinglePayment(net.petafuel.styx.core.xs2a.entities.SinglePayment) StyxException(net.petafuel.styx.api.exception.StyxException) PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) ResponseEntity(net.petafuel.styx.api.exception.ResponseEntity) PISRequest(net.petafuel.styx.core.xs2a.contracts.PISRequest) PISRequestFactory(net.petafuel.styx.core.xs2a.factory.PISRequestFactory) AbstractTokenFilter(net.petafuel.styx.api.filter.authentication.control.AbstractTokenFilter) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) InitiatedPayment(net.petafuel.styx.core.xs2a.entities.InitiatedPayment) IOProcessor(net.petafuel.styx.core.ioprocessing.IOProcessor) Path(javax.ws.rs.Path) AcceptsPreStepAuth(net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth) RequiresMandatoryHeader(net.petafuel.styx.api.filter.input.boundary.RequiresMandatoryHeader) POST(javax.ws.rs.POST)

Example 4 with SinglePayment

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

the class UniCreditPISIntegrationTest method getSinglePayment.

@Test
@Category(IntegrationTest.class)
public void getSinglePayment() throws IOException {
    for (Map<String, String> testEntry : testData) {
        String singlePaymentId = testEntry.get("paymentId");
        String bic = testEntry.get("bic");
        Invocation invocation = target("/v1/payments/sepa-credit-transfers/" + singlePaymentId).request().header("token", pisAccessToken).header("PSU-ID", "bgdemo").header("PSU-BIC", bic).buildGet();
        Response response = invocation.invoke(Response.class);
        Assertions.assertEquals(200, response.getStatus());
        Jsonb jsonb = JsonbBuilder.create();
        SinglePayment payment = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), SinglePayment.class);
        Assertions.assertNotNull(payment.getCreditorAccount().getCurrency());
        Assertions.assertNotNull(payment.getCreditorAccount().getIban());
        Assertions.assertNotNull(payment.getCreditorName());
        Assertions.assertNotNull(payment.getDebtorAccount().getCurrency());
        Assertions.assertNotNull(payment.getDebtorAccount().getIban());
        Assertions.assertNotNull(payment.getInstructedAmount().getAmount());
        Assertions.assertNotNull(payment.getInstructedAmount().getCurrency());
        Assertions.assertNotNull(payment.getRemittanceInformationUnstructured());
        Assertions.assertEquals("Styx PIS Test mit Umlaut ÄöÜ", payment.getRemittanceInformationUnstructured());
    }
}
Also used : PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) Response(javax.ws.rs.core.Response) Jsonb(javax.json.bind.Jsonb) Invocation(javax.ws.rs.client.Invocation) InputStream(java.io.InputStream) SinglePayment(net.petafuel.styx.core.xs2a.entities.SinglePayment) 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 SinglePayment

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

SinglePayment (net.petafuel.styx.core.xs2a.entities.SinglePayment)9 PaymentResponse (net.petafuel.styx.api.v1.payment.entity.PaymentResponse)5 AccountReference (net.petafuel.styx.core.xs2a.entities.AccountReference)5 Date (java.util.Date)4 Amount (net.petafuel.styx.core.xs2a.entities.Amount)4 Category (org.junit.experimental.categories.Category)4 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 ResponseEntity (net.petafuel.styx.api.exception.ResponseEntity)3 StyxException (net.petafuel.styx.api.exception.StyxException)3 AcceptsPreStepAuth (net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth)3 AbstractTokenFilter (net.petafuel.styx.api.filter.authentication.control.AbstractTokenFilter)3 RequiresMandatoryHeader (net.petafuel.styx.api.filter.input.boundary.RequiresMandatoryHeader)3 AspspUrlMapper (net.petafuel.styx.api.util.AspspUrlMapper)3 SinglePaymentInitiation (net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation)3 IOProcessor (net.petafuel.styx.core.ioprocessing.IOProcessor)3 PISRequest (net.petafuel.styx.core.xs2a.contracts.PISRequest)3 InitiatedPayment (net.petafuel.styx.core.xs2a.entities.InitiatedPayment)3 PISRequestFactory (net.petafuel.styx.core.xs2a.factory.PISRequestFactory)3 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)3