Search in sources :

Example 1 with IOProcessor

use of net.petafuel.styx.core.ioprocessing.IOProcessor 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 2 with IOProcessor

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

the class ConsentAuthorisationResource method startConsentAuthorisation.

/**
 * Starts a consent authorisation
 *
 * @param consentId of the target consent
 * @return a GetConsentResponse object
 * @throws BankRequestFailedException if something went wrong between the core service and the aspsp
 */
@AcceptsPreStepAuth
@POST
@RequiresPSU
@Path("/consents/{consentId}/authorisations")
public Response startConsentAuthorisation(@NotEmpty @NotBlank @PathParam("consentId") String consentId, @Valid AuthorisationRequest authorisationRequest) throws BankRequestFailedException {
    consentId = Sanitizer.replaceEscSeq(consentId);
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setConsentId(consentId);
    xs2AFactoryInput.setPsuData(authorisationRequest.getPsuData());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    SCARequest xs2AAuthorisationRequest = new SCARequestFactory().create(getXS2AStandard().getRequestClassProvider().scaStart(), xs2AFactoryInput);
    xs2AAuthorisationRequest.getHeaders().putAll(getAdditionalHeaders());
    if (getRedirectPreferred() != null) {
        xs2AAuthorisationRequest.setTppRedirectPreferred(getRedirectPreferred());
    }
    ioProcessor.modifyRequest(xs2AAuthorisationRequest, xs2AFactoryInput);
    SCA consentSCA = getXS2AStandard().getCs().startAuthorisation(xs2AAuthorisationRequest);
    AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(consentId, consentSCA.getAuthorisationId());
    consentSCA.setLinks(aspspUrlMapper.map(consentSCA.getLinks()));
    LOG.info("Consent Authorisation started for consentId={} scaStatus={} scaApproach={}", consentId, consentSCA.getScaStatus(), consentSCA.getApproach());
    return Response.status(ResponseConstant.CREATED).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) RequiresPSU(net.petafuel.styx.api.filter.input.boundary.RequiresPSU) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) POST(javax.ws.rs.POST)

Example 3 with IOProcessor

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

the class ConsentAuthorisationResource method getScaStatus.

@AcceptsPreStepAuth
@GET
@Path("/consents/{consentId}/authorisations/{authorisationId}")
public Response getScaStatus(@NotEmpty @NotBlank @PathParam("consentId") String consentId, @NotEmpty @NotBlank @PathParam("authorisationId") String authorisationId) throws BankRequestFailedException {
    consentId = Sanitizer.replaceEscSeq(consentId);
    authorisationId = Sanitizer.replaceEscSeq(authorisationId);
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setConsentId(consentId);
    xs2AFactoryInput.setAuthorisationId(authorisationId);
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    SCARequest getAuthorisationStatusRequest = new SCARequestFactory().create(getXS2AStandard().getRequestClassProvider().scaStatus(), xs2AFactoryInput);
    getAuthorisationStatusRequest.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(getAuthorisationStatusRequest, xs2AFactoryInput);
    SCA.Status authorisationStatus = getXS2AStandard().getCs().getSCAStatus(getAuthorisationStatusRequest);
    AuthorisationStatusResponse response = new AuthorisationStatusResponse();
    response.setScaStatus(authorisationStatus.getValue());
    LOG.info("Consent Authorisation Status requested for consentId={} authorisationId={} scaStatus={}", consentId, authorisationId, authorisationStatus.getValue());
    return Response.status(ResponseConstant.OK).entity(response).build();
}
Also used : SCA(net.petafuel.styx.core.xs2a.entities.SCA) SCARequest(net.petafuel.styx.core.xs2a.contracts.SCARequest) AuthorisationStatusResponse(net.petafuel.styx.api.v1.payment.entity.AuthorisationStatusResponse) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) 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) GET(javax.ws.rs.GET)

Example 4 with IOProcessor

use of net.petafuel.styx.core.ioprocessing.IOProcessor 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 5 with IOProcessor

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

the class FetchPaymentResource method fetchPayment.

/**
 * Returns an previously initiated payment in its raw form, as json or xml pain001.003
 *
 * @param paymentTypeBean contains which payment product is used
 * @param paymentId       id of the payment that should be retrieved from the aspsp
 * @return 200 if successful
 * @throws BankRequestFailedException in case the communication between styx and aspsp was not successful
 */
@AcceptsPreStepAuth
@GET
@Path("/{paymentService}/{paymentProduct}/{paymentId}")
public Response fetchPayment(@BeanParam PaymentTypeBean paymentTypeBean, @NotEmpty @NotBlank @PathParam("paymentId") String paymentId) throws BankRequestFailedException {
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setPaymentService(paymentTypeBean.getPaymentService());
    xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
    xs2AFactoryInput.setPsu(getPsu());
    xs2AFactoryInput.setPaymentId(paymentId);
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    PISRequest aspspRequest = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentRetrieval(), xs2AFactoryInput);
    aspspRequest.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(aspspRequest, xs2AFactoryInput);
    InitializablePayment fetchedPayment = getXS2AStandard().getPis().getPayment(aspspRequest);
    LOG.info("Successfully fetched payment entity for bic={}, paymentId={}", getXS2AStandard().getAspsp().getBic(), paymentId);
    return Response.status(ResponseConstant.OK).entity(fetchedPayment).build();
}
Also used : PISRequest(net.petafuel.styx.core.xs2a.contracts.PISRequest) PISRequestFactory(net.petafuel.styx.core.xs2a.factory.PISRequestFactory) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) IOProcessor(net.petafuel.styx.core.ioprocessing.IOProcessor) InitializablePayment(net.petafuel.styx.core.xs2a.entities.InitializablePayment) AcceptsPreStepAuth(net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

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