Search in sources :

Example 1 with AISRequestFactory

use of net.petafuel.styx.core.xs2a.factory.AISRequestFactory in project styx by petafuel.

the class CreateConsentResource method createConsent.

/**
 * Creates a consent Resource on the target aspsp xs2a interface
 *
 * @param postConsentRequest must contain recurringIndicator and the AccountAccess
 * @return returns SCA related data for the consent authorisation
 * @throws BankRequestFailedException in case something goes wrong while communicating to the ASPSP interface
 */
@RequiresMandatoryHeader
@AcceptsPreStepAuth
@POST
@Path("/consents")
public Response createConsent(@Valid @NotNull POSTConsentRequest postConsentRequest) throws BankRequestFailedException {
    Consent requestConsent = new Consent();
    requestConsent.setCombinedServiceIndicator(false);
    requestConsent.setRecurringIndicator(postConsentRequest.isRecurringIndicator());
    requestConsent.setFrequencyPerDay(4);
    requestConsent.setAccess(postConsentRequest.getAccess());
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setConsent(requestConsent);
    xs2AFactoryInput.setPsu(getPsu());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    AISRequest xs2ARequest = new AISRequestFactory().create(getXS2AStandard().getRequestClassProvider().consentCreation(), xs2AFactoryInput);
    xs2ARequest.getHeaders().putAll(getAdditionalHeaders());
    xs2ARequest.setTppRedirectPreferred(getRedirectPreferred());
    ioProcessor.modifyRequest(xs2ARequest, xs2AFactoryInput);
    Consent consent = getXS2AStandard().getCs().createConsent(xs2ARequest);
    POSTConsentResponse postConsentResponse = new POSTConsentResponse();
    postConsentResponse.setConsentId(consent.getId());
    postConsentResponse.setAspspScaApproach(consent.getSca().getApproach());
    postConsentResponse.setPsuMessage(consent.getPsuMessage());
    postConsentResponse.setLinks(consent.getLinks());
    SCAApproach approach = SCAHandler.decision(consent);
    if (approach instanceof OAuth2) {
        postConsentResponse.getLinks().getScaOAuth().setUrl(((OAuth2) approach).getAuthoriseLink());
    }
    AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(consent.getId(), null);
    postConsentResponse.setLinks(aspspUrlMapper.map(postConsentResponse.getLinks()));
    LOG.info("Created new AIS consent for bic={}", getXS2AStandard().getAspsp().getBic());
    return Response.status(Response.Status.CREATED).entity(postConsentResponse).build();
}
Also used : OAuth2(net.petafuel.styx.core.xs2a.sca.OAuth2) Consent(net.petafuel.styx.core.xs2a.entities.Consent) AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) SCAApproach(net.petafuel.styx.core.xs2a.sca.SCAApproach) AspspUrlMapper(net.petafuel.styx.api.util.AspspUrlMapper) AISRequestFactory(net.petafuel.styx.core.xs2a.factory.AISRequestFactory) POSTConsentResponse(net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse) 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) RequiresMandatoryHeader(net.petafuel.styx.api.filter.input.boundary.RequiresMandatoryHeader) POST(javax.ws.rs.POST)

Example 2 with AISRequestFactory

use of net.petafuel.styx.core.xs2a.factory.AISRequestFactory in project styx by petafuel.

the class GetConsentResource method getConsentStatus.

/**
 * Returns the consent status
 *
 * @param consentId of the target consent
 * @return a GetConsentStatusResponse object
 * @throws BankRequestFailedException if something went wrong between the core service and the aspsp
 */
@AcceptsPreStepAuth
@GET
@Path("/consents/{consentId}/status")
public Response getConsentStatus(@NotEmpty @NotBlank @PathParam("consentId") String consentId) throws BankRequestFailedException {
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setConsentId(consentId);
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    AISRequest request = new AISRequestFactory().create(getXS2AStandard().getRequestClassProvider().consentStatus(), xs2AFactoryInput);
    request.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(request, xs2AFactoryInput);
    ConsentStatus state = getXS2AStandard().getCs().getStatus(request);
    GetConsentStatusResponse response = new GetConsentStatusResponse(state);
    LOG.info("Successfully fetched consent status entity for bic={}, consentId={}", getXS2AStandard().getAspsp().getBic(), consentId);
    return Response.status(ResponseConstant.OK).entity(response).build();
}
Also used : AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) ConsentStatus(net.petafuel.styx.core.xs2a.entities.ConsentStatus) GetConsentStatusResponse(net.petafuel.styx.api.v1.consent.entity.GetConsentStatusResponse) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) AISRequestFactory(net.petafuel.styx.core.xs2a.factory.AISRequestFactory) 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) GET(javax.ws.rs.GET)

Example 3 with AISRequestFactory

use of net.petafuel.styx.core.xs2a.factory.AISRequestFactory in project styx by petafuel.

the class GetConsentResource method fetchConsent.

/**
 * Returns the consent object with the corresponding accounts
 *
 * @param consentId of the target consent
 * @return a GetConsentResponse object
 * @throws BankRequestFailedException if something went wrong between the core service and the aspsp
 */
@AcceptsPreStepAuth
@GET
@Path("/consents/{consentId}")
public Response fetchConsent(@NotEmpty @NotBlank @PathParam("consentId") String consentId) throws BankRequestFailedException {
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setConsentId(consentId);
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    AISRequest request = new AISRequestFactory().create(getXS2AStandard().getRequestClassProvider().consentRetrieval(), xs2AFactoryInput);
    request.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(request, xs2AFactoryInput);
    Consent consent = getXS2AStandard().getCs().getConsent(request);
    GetConsentResponse response = new GetConsentResponse(consent);
    LOG.info("Successfully fetched consent entity for bic={}, consentId={}", getXS2AStandard().getAspsp().getBic(), consentId);
    return Response.status(ResponseConstant.OK).entity(response).build();
}
Also used : GetConsentResponse(net.petafuel.styx.api.v1.consent.entity.GetConsentResponse) Consent(net.petafuel.styx.core.xs2a.entities.Consent) AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) AISRequestFactory(net.petafuel.styx.core.xs2a.factory.AISRequestFactory) 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) GET(javax.ws.rs.GET)

Example 4 with AISRequestFactory

use of net.petafuel.styx.core.xs2a.factory.AISRequestFactory in project styx by petafuel.

the class AccountResource method fetchBalances.

/**
 * Fetch a list of balances(mandatory) with an optional linked account
 *
 * @param accountId the xs2a account id
 * @param consentId a consent with status VALID
 * @return returns a list of balances, optionally a linked account
 */
@AcceptsPreStepAuth
@GET
@Path("/accounts/{resourceId}/balances")
public Response fetchBalances(@NotNull @NotBlank @HeaderParam("consentId") String consentId, @NotNull @NotBlank @PathParam("resourceId") String accountId) throws BankRequestFailedException {
    xs2AFactoryInput.setConsentId(consentId);
    xs2AFactoryInput.setAccountId(accountId);
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    AISRequest readBalancesRequest = new AISRequestFactory().create(getXS2AStandard().getRequestClassProvider().accountBalances(), xs2AFactoryInput);
    readBalancesRequest.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(readBalancesRequest, xs2AFactoryInput);
    BalanceContainer balances = getXS2AStandard().getAis().getBalancesByAccount(readBalancesRequest);
    LOG.info("Successfully fetched balances bic={}", getXS2AStandard().getAspsp().getBic());
    return Response.status(200).entity(balances).build();
}
Also used : AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) AISRequestFactory(net.petafuel.styx.core.xs2a.factory.AISRequestFactory) BalanceContainer(net.petafuel.styx.core.xs2a.entities.BalanceContainer) 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) GET(javax.ws.rs.GET)

Example 5 with AISRequestFactory

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

Aggregations

AISRequest (net.petafuel.styx.core.xs2a.contracts.AISRequest)12 AISRequestFactory (net.petafuel.styx.core.xs2a.factory.AISRequestFactory)12 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)8 ApplicationPath (javax.ws.rs.ApplicationPath)7 Path (javax.ws.rs.Path)7 AcceptsPreStepAuth (net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth)7 IOProcessor (net.petafuel.styx.core.ioprocessing.IOProcessor)7 GET (javax.ws.rs.GET)6 XS2AStandard (net.petafuel.styx.core.banklookup.XS2AStandard)5 SAD (net.petafuel.styx.core.banklookup.sad.SAD)5 Order (org.junit.jupiter.api.Order)5 Test (org.junit.jupiter.api.Test)5 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)5 AccountDetails (net.petafuel.styx.core.xs2a.entities.AccountDetails)4 AspspUrlMapper (net.petafuel.styx.api.util.AspspUrlMapper)3 BalanceContainer (net.petafuel.styx.core.xs2a.entities.BalanceContainer)2 Consent (net.petafuel.styx.core.xs2a.entities.Consent)2 TransactionContainer (net.petafuel.styx.core.xs2a.entities.TransactionContainer)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1