Search in sources :

Example 11 with IOProcessor

use of net.petafuel.styx.core.ioprocessing.IOProcessor in project styx by petafuel.

the class AccountResource method fetchTransactions.

/**
 * This yields the transactions for the specified account. The amount of data varies heavily between banks
 *
 * @param consentId                  consent which has access to the transactions of the specified account
 * @param accountId                  account that containes the requested transactions
 * @param transactionListRequestBean QueryParams bookingStatus, dateFrom and dateTo
 * @return TransactionContainer which holds the transactions/revenues grouped by booking status
 * @throws BankRequestFailedException in case the Request to the Bank failed
 */
@AcceptsPreStepAuth
@GET
@Path("/accounts/{resourceId}/transactions")
public Response fetchTransactions(@NotNull @NotBlank @HeaderParam("consentId") String consentId, @NotNull @NotBlank @PathParam("resourceId") String accountId, @BeanParam @Valid TransactionListRequestBean transactionListRequestBean) throws BankRequestFailedException {
    xs2AFactoryInput.setConsentId(consentId);
    xs2AFactoryInput.setAccountId(accountId);
    xs2AFactoryInput.setBookingStatus(transactionListRequestBean.getBookingStatus());
    xs2AFactoryInput.setDateFrom(transactionListRequestBean.getDateFrom());
    xs2AFactoryInput.setDateTo(transactionListRequestBean.getDateTo());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    AISRequest readTransactionsRequest = new AISRequestFactory().create(getXS2AStandard().getRequestClassProvider().accountTransactionList(), xs2AFactoryInput);
    readTransactionsRequest.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(readTransactionsRequest, xs2AFactoryInput);
    TransactionContainer transactionContainer = getXS2AStandard().getAis().getTransactionsByAccount(readTransactionsRequest);
    LOG.info("Successfully fetched transactions bic={}", getXS2AStandard().getAspsp().getBic());
    TransactionListResponseAdapter transactionListResponseAdapter = new TransactionListResponseAdapter(transactionContainer);
    return Response.status(200).entity(transactionListResponseAdapter).build();
}
Also used : AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) TransactionContainer(net.petafuel.styx.core.xs2a.entities.TransactionContainer) AISRequestFactory(net.petafuel.styx.core.xs2a.factory.AISRequestFactory) IOProcessor(net.petafuel.styx.core.ioprocessing.IOProcessor) TransactionListResponseAdapter(net.petafuel.styx.api.v1.account.control.TransactionListResponseAdapter) AcceptsPreStepAuth(net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) GET(javax.ws.rs.GET)

Example 12 with IOProcessor

use of net.petafuel.styx.core.ioprocessing.IOProcessor in project styx by petafuel.

the class AccountResource method processAccountList.

/**
 * Returns a List of Accounts
 *
 * @param consentId consentId with access to the requested account list
 * @return returns an account list
 * @see AccountListResponseAdapter
 */
@AcceptsPreStepAuth
@GET
@Path("/accounts")
public Response processAccountList(@NotNull @NotBlank @HeaderParam("consentId") String consentId) throws BankRequestFailedException {
    xs2AFactoryInput.setConsentId(consentId);
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    AISRequest accountListRequest = new AISRequestFactory().create(getXS2AStandard().getRequestClassProvider().accountList(), xs2AFactoryInput);
    accountListRequest.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(accountListRequest, xs2AFactoryInput);
    List<AccountDetails> accountList = getXS2AStandard().getAis().getAccountList(accountListRequest);
    accountList.forEach(accountDetails -> accountDetails.setLinks(new AspspUrlMapper(accountDetails.getResourceId()).map(accountDetails.getLinks())));
    LOG.info("Successfully fetched account list for bic={}", getXS2AStandard().getAspsp().getBic());
    return Response.status(200).entity(new AccountListResponseAdapter(accountList)).build();
}
Also used : AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) AccountListResponseAdapter(net.petafuel.styx.api.v1.account.control.AccountListResponseAdapter) AspspUrlMapper(net.petafuel.styx.api.util.AspspUrlMapper) AISRequestFactory(net.petafuel.styx.core.xs2a.factory.AISRequestFactory) IOProcessor(net.petafuel.styx.core.ioprocessing.IOProcessor) AccountDetails(net.petafuel.styx.core.xs2a.entities.AccountDetails) AcceptsPreStepAuth(net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) GET(javax.ws.rs.GET)

Example 13 with IOProcessor

use of net.petafuel.styx.core.ioprocessing.IOProcessor in project styx by petafuel.

the class PaymentInitiationResource method initiatePeriodicPayment.

/**
 * Initiate a reoccurring payment
 *
 * @param paymentTypeBean     contains which payment product is used
 * @param periodicPaymentBody 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("/periodic-payments/{paymentProduct}")
@RequiresMandatoryHeader
@AcceptsPreStepAuth
public Response initiatePeriodicPayment(@BeanParam PaymentTypeBean paymentTypeBean, @Valid PeriodicPaymentInitiation periodicPaymentBody) throws BankRequestFailedException {
    Optional<SinglePayment> singlePayment = periodicPaymentBody.getPayments().stream().findFirst();
    if (!singlePayment.isPresent()) {
        throw new StyxException(new ResponseEntity("No valid payment object was found", ResponseConstant.BAD_REQUEST, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
    }
    SinglePayment payment = singlePayment.get();
    PeriodicPayment periodicPayment = new PeriodicPayment();
    periodicPayment.setCreditorAccount(payment.getCreditorAccount());
    periodicPayment.setCreditorName(payment.getCreditorName());
    periodicPayment.setDebtorAccount(payment.getDebtorAccount());
    periodicPayment.setEndToEndIdentification(payment.getEndToEndIdentification());
    periodicPayment.setInstructedAmount(payment.getInstructedAmount());
    periodicPayment.setRemittanceInformationUnstructured(payment.getRemittanceInformationUnstructured());
    periodicPayment.setDayOfExecution(String.valueOf(periodicPaymentBody.getDayOfExecution()));
    periodicPayment.setExecutionRule(periodicPaymentBody.getExecutionRule());
    periodicPayment.setStartDate(Date.from(periodicPaymentBody.getStartDate().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
    periodicPayment.setFrequency(periodicPaymentBody.getFrequency().name());
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setPayment(periodicPayment);
    xs2AFactoryInput.setPsu(getPsu());
    xs2AFactoryInput.setPaymentService(PaymentService.PERIODIC_PAYMENTS);
    xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    PISRequest periodicPaymentInitiation = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentInitiation(), xs2AFactoryInput);
    periodicPaymentInitiation.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(periodicPaymentInitiation, xs2AFactoryInput);
    periodicPaymentInitiation.setTppRedirectPreferred(getRedirectPreferred());
    periodicPaymentInitiation.setXrequestId(ThreadContext.get(RequestUUIDAdapter.REQUEST_UUID));
    InitiatedPayment initiatedPayment = getXS2AStandard().getPis().initiatePayment(periodicPaymentInitiation);
    PaymentResponse paymentResponse = new PaymentResponse(initiatedPayment);
    SCAApproach approach = SCAHandler.decision(initiatedPayment);
    if (approach instanceof OAuth2) {
        paymentResponse.getLinks().getScaOAuth().setUrl(((OAuth2) approach).getAuthoriseLink());
    }
    LOG.info("Initiate periodic payment bic={} aspsp_name={} aspsp_id={}", getXS2AStandard().getAspsp().getBic(), getXS2AStandard().getAspsp().getName(), getXS2AStandard().getAspsp().getId());
    AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(PaymentService.PERIODIC_PAYMENTS, paymentTypeBean.getPaymentProduct(), paymentResponse.getPaymentId(), null);
    paymentResponse.setLinks(aspspUrlMapper.map(paymentResponse.getLinks()));
    PersistentPayment.create(periodicPaymentInitiation.getXrequestId(), paymentResponse.getPaymentId(), (String) getContainerRequestContext().getProperty(AbstractTokenFilter.class.getName()), getXS2AStandard().getAspsp().getBic(), paymentResponse.getTransactionStatus(), PaymentService.PERIODIC_PAYMENTS, paymentTypeBean.getPaymentProduct());
    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) PeriodicPayment(net.petafuel.styx.core.xs2a.entities.PeriodicPayment) 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 14 with IOProcessor

use of net.petafuel.styx.core.ioprocessing.IOProcessor in project styx by petafuel.

the class PaymentInitiationResource method initiateBulkPayment.

/**
 * Initiate multiple payments as bulk
 *
 * @param paymentTypeBean contains which payment product is used
 * @param bulkPaymentBody 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("/bulk-payments/{paymentProduct}")
@RequiresMandatoryHeader
@AcceptsPreStepAuth
public Response initiateBulkPayment(@BeanParam PaymentTypeBean paymentTypeBean, @Valid BulkPaymentInitiation bulkPaymentBody) throws BankRequestFailedException {
    // Debtors should all be the same within the payments, we take one of them
    Optional<SinglePayment> singlePayment = bulkPaymentBody.getPayments().stream().findAny();
    if (!singlePayment.isPresent()) {
        throw new StyxException(new ResponseEntity("No valid payment object was found within the bulk payments array", ResponseConstant.BAD_REQUEST, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
    }
    AccountReference debtor = bulkPaymentBody.getDebtorAccount();
    BulkPayment bulkPayment = new BulkPayment();
    bulkPayment.setBatchBookingPreferred(bulkPaymentBody.getBatchBookingPreferred());
    bulkPayment.setDebtorAccount(debtor);
    bulkPayment.setPayments(bulkPaymentBody.getPayments());
    bulkPayment.setRequestedExecutionDate(bulkPaymentBody.getRequestedExecutionDate());
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setPayment(bulkPayment);
    xs2AFactoryInput.setPsu(getPsu());
    xs2AFactoryInput.setPaymentService(PaymentService.BULK_PAYMENTS);
    xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    PISRequest bulkpaymentInitiationRequest = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentInitiation(), xs2AFactoryInput);
    bulkpaymentInitiationRequest.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(bulkpaymentInitiationRequest, xs2AFactoryInput);
    bulkpaymentInitiationRequest.setTppRedirectPreferred(getRedirectPreferred());
    bulkpaymentInitiationRequest.setXrequestId(ThreadContext.get(RequestUUIDAdapter.REQUEST_UUID));
    InitiatedPayment initiatedPayment = getXS2AStandard().getPis().initiatePayment(bulkpaymentInitiationRequest);
    PaymentResponse paymentResponse = new PaymentResponse(initiatedPayment);
    SCAApproach approach = SCAHandler.decision(initiatedPayment);
    if (approach instanceof OAuth2) {
        paymentResponse.getLinks().getScaOAuth().setUrl(((OAuth2) approach).getAuthoriseLink());
    }
    LOG.info("Initiate bulk payment bic={} aspsp_name={} aspsp_id={} paymentId={}", getXS2AStandard().getAspsp().getBic(), getXS2AStandard().getAspsp().getName(), getXS2AStandard().getAspsp().getId(), paymentResponse.getPaymentId());
    AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(PaymentService.BULK_PAYMENTS, paymentTypeBean.getPaymentProduct(), paymentResponse.getPaymentId(), null);
    paymentResponse.setLinks(aspspUrlMapper.map(paymentResponse.getLinks()));
    PersistentPayment.create(bulkpaymentInitiationRequest.getXrequestId(), paymentResponse.getPaymentId(), (String) getContainerRequestContext().getProperty(AbstractTokenFilter.class.getName()), getXS2AStandard().getAspsp().getBic(), paymentResponse.getTransactionStatus(), PaymentService.BULK_PAYMENTS, paymentTypeBean.getPaymentProduct());
    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) BulkPayment(net.petafuel.styx.core.xs2a.entities.BulkPayment) 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) AccountReference(net.petafuel.styx.core.xs2a.entities.AccountReference) 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 15 with IOProcessor

use of net.petafuel.styx.core.ioprocessing.IOProcessor in project styx by petafuel.

the class ConsentAuthorisationResource method updateConsentAuthorisation.

/**
 * This endpoint covers 4 use cases
 * Empty authorisationRequest -> PSU Identification, the PSU-* Headers are transmitted to the aspsp
 * PSUData -> PSU Authentication, login the PSU with pin/password on the ASPSP interface
 * authenticationMethodId -> SCAMethod Selection, if there are multiple SCAMethods for the PSU to choose from
 * scaAuthenticationData -> if the PSU has received a TAN for the SCA process we can forward it to the ASPSP
 *
 * @param consentId
 * @param authorisationId
 * @param authorisationRequest
 * @return
 * @throws BankRequestFailedException
 */
@AcceptsPreStepAuth
@PUT
@Path("/consents/{consentId}/authorisations/{authorisationId}")
public Response updateConsentAuthorisation(@NotEmpty @NotBlank @PathParam("consentId") String consentId, @NotEmpty @NotBlank @PathParam("authorisationId") String authorisationId, @Valid AuthorisationRequest authorisationRequest) throws BankRequestFailedException {
    consentId = Sanitizer.replaceEscSeq(consentId);
    authorisationId = Sanitizer.replaceEscSeq(authorisationId);
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setConsentId(consentId);
    xs2AFactoryInput.setPsu(getPsu());
    xs2AFactoryInput.setAuthorisationId(authorisationId);
    xs2AFactoryInput.setPsuData(authorisationRequest.getPsuData());
    xs2AFactoryInput.setAuthorisationMethodId(authorisationRequest.getAuthenticationMethodId());
    xs2AFactoryInput.setScaAuthenticationData(authorisationRequest.getScaAuthenticationData());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    SCA consentSCA;
    SCARequest xs2AAuthorisationRequest;
    if (authorisationRequest.getPsuData() != null) {
        xs2AAuthorisationRequest = new SCARequestFactory().create(getXS2AStandard().getRequestClassProvider().scaUpdateAuthentication(), xs2AFactoryInput);
        xs2AAuthorisationRequest.getHeaders().putAll(getAdditionalHeaders());
        ioProcessor.modifyRequest(xs2AAuthorisationRequest, xs2AFactoryInput);
        consentSCA = getXS2AStandard().getCs().updatePSUAuthentication(xs2AAuthorisationRequest);
    } else if (authorisationRequest.getAuthenticationMethodId() != null) {
        xs2AAuthorisationRequest = new SCARequestFactory().create(getXS2AStandard().getRequestClassProvider().scaUpdateAuthenticationMethod(), xs2AFactoryInput);
        xs2AAuthorisationRequest.getHeaders().putAll(getAdditionalHeaders());
        ioProcessor.modifyRequest(xs2AAuthorisationRequest, xs2AFactoryInput);
        consentSCA = getXS2AStandard().getCs().selectAuthenticationMethod(xs2AAuthorisationRequest);
    } else if (authorisationRequest.getScaAuthenticationData() != null) {
        xs2AAuthorisationRequest = new SCARequestFactory().create(getXS2AStandard().getRequestClassProvider().scaAuthoriseTransaction(), xs2AFactoryInput);
        xs2AAuthorisationRequest.getHeaders().putAll(getAdditionalHeaders());
        ioProcessor.modifyRequest(xs2AAuthorisationRequest, xs2AFactoryInput);
        consentSCA = getXS2AStandard().getCs().authoriseTransaction(xs2AAuthorisationRequest);
    } else {
        xs2AAuthorisationRequest = new SCARequestFactory().create(getXS2AStandard().getRequestClassProvider().scaUpdateIdentification(), xs2AFactoryInput);
        xs2AAuthorisationRequest.getHeaders().putAll(getAdditionalHeaders());
        ioProcessor.modifyRequest(xs2AAuthorisationRequest, xs2AFactoryInput);
        consentSCA = getXS2AStandard().getCs().updatePSUIdentification(xs2AAuthorisationRequest);
    }
    AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(consentId, authorisationId);
    consentSCA.setLinks(aspspUrlMapper.map(consentSCA.getLinks()));
    LOG.info("Consent Authorisation updated for consentId={} authorisationId={} scaStatus={} scaApproach={}", consentId, authorisationId, consentSCA.getScaStatus(), consentSCA.getApproach());
    return Response.status(ResponseConstant.OK).entity(consentSCA).build();
}
Also used : SCA(net.petafuel.styx.core.xs2a.entities.SCA) SCARequest(net.petafuel.styx.core.xs2a.contracts.SCARequest) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) AspspUrlMapper(net.petafuel.styx.api.util.AspspUrlMapper) SCARequestFactory(net.petafuel.styx.core.xs2a.factory.SCARequestFactory) IOProcessor(net.petafuel.styx.core.ioprocessing.IOProcessor) AcceptsPreStepAuth(net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) PUT(javax.ws.rs.PUT)

Aggregations

Path (javax.ws.rs.Path)19 AcceptsPreStepAuth (net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth)19 IOProcessor (net.petafuel.styx.core.ioprocessing.IOProcessor)19 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)15 GET (javax.ws.rs.GET)11 ApplicationPath (javax.ws.rs.ApplicationPath)10 AspspUrlMapper (net.petafuel.styx.api.util.AspspUrlMapper)10 AISRequest (net.petafuel.styx.core.xs2a.contracts.AISRequest)7 SCARequest (net.petafuel.styx.core.xs2a.contracts.SCARequest)7 AISRequestFactory (net.petafuel.styx.core.xs2a.factory.AISRequestFactory)7 SCARequestFactory (net.petafuel.styx.core.xs2a.factory.SCARequestFactory)7 POST (javax.ws.rs.POST)6 SCA (net.petafuel.styx.core.xs2a.entities.SCA)6 PISRequest (net.petafuel.styx.core.xs2a.contracts.PISRequest)5 PISRequestFactory (net.petafuel.styx.core.xs2a.factory.PISRequestFactory)5 AbstractTokenFilter (net.petafuel.styx.api.filter.authentication.control.AbstractTokenFilter)4 RequiresMandatoryHeader (net.petafuel.styx.api.filter.input.boundary.RequiresMandatoryHeader)4 OAuth2 (net.petafuel.styx.core.xs2a.sca.OAuth2)4 SCAApproach (net.petafuel.styx.core.xs2a.sca.SCAApproach)4 ResponseEntity (net.petafuel.styx.api.exception.ResponseEntity)3