Search in sources :

Example 6 with SCARequest

use of net.petafuel.styx.core.xs2a.contracts.SCARequest in project styx by petafuel.

the class PaymentAuthorisationResource method startPaymentAuthorisation.

/**
 * If the ASPSP has not implicitly created an authorisation resource, this Endpoint can create an authorisation resource
 *
 * @param paymentTypeBean      payment-service and payment-product
 * @param paymentId            id of the payment an authorisation should be started for
 * @param authorisationRequest the request resource might contain an empty body or PSUData authentication
 * @return returns an SCA container with further information on the Authorisation
 * @throws BankRequestFailedException in case the communication between styx and aspsp was not successful
 */
@AcceptsPreStepAuth
@POST
@Path("/{paymentService}/{paymentProduct}/{paymentId}/authorisations")
public Response startPaymentAuthorisation(@BeanParam PaymentTypeBean paymentTypeBean, @NotEmpty @NotBlank @PathParam("paymentId") String paymentId, @Valid @NotNull AuthorisationRequest authorisationRequest) throws BankRequestFailedException {
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setPaymentService(paymentTypeBean.getPaymentService());
    xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
    xs2AFactoryInput.setPsu(getPsu());
    xs2AFactoryInput.setPaymentId(paymentId);
    xs2AFactoryInput.setPsuData(authorisationRequest.getPsuData());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    SCARequest xs2AAuthorisationRequest = new SCARequestFactory().create(getXS2AStandard().getRequestClassProvider().scaStart(), xs2AFactoryInput);
    if (getRedirectPreferred() != null) {
        xs2AAuthorisationRequest.setTppRedirectPreferred(getRedirectPreferred());
    }
    xs2AAuthorisationRequest.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(xs2AAuthorisationRequest, xs2AFactoryInput);
    SCA paymentSCA = getXS2AStandard().getPis().startAuthorisation(xs2AAuthorisationRequest);
    AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(paymentTypeBean.getPaymentService(), paymentTypeBean.getPaymentProduct(), paymentId, paymentSCA.getAuthorisationId());
    paymentSCA.setLinks(aspspUrlMapper.map(paymentSCA.getLinks()));
    LOG.info("Payment Authorisation started for paymentId={} scaStatus={} scaApproach={}", paymentId, paymentSCA.getScaStatus(), paymentSCA.getApproach());
    return Response.status(ResponseConstant.OK).entity(paymentSCA).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) POST(javax.ws.rs.POST)

Example 7 with SCARequest

use of net.petafuel.styx.core.xs2a.contracts.SCARequest in project styx by petafuel.

the class PaymentAuthorisationResource method updatePaymentAuthorisation.

/**
 * 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 paymentTypeBean
 * @param paymentId
 * @param authorisationId
 * @param authorisationRequest
 * @return
 * @throws BankRequestFailedException
 */
@AcceptsPreStepAuth
@PUT
@Path("/{paymentService}/{paymentProduct}/{paymentId}/authorisations/{authorisationId}")
public Response updatePaymentAuthorisation(@BeanParam PaymentTypeBean paymentTypeBean, @NotEmpty @NotBlank @PathParam("paymentId") String paymentId, @NotEmpty @NotBlank @PathParam("authorisationId") String authorisationId, @Valid AuthorisationRequest authorisationRequest) throws BankRequestFailedException {
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setPaymentService(paymentTypeBean.getPaymentService());
    xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
    xs2AFactoryInput.setPaymentId(paymentId);
    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 paymentSCA;
    SCARequest xs2AAuthorisationRequest;
    if (authorisationRequest.getPsuData() != null) {
        xs2AAuthorisationRequest = new SCARequestFactory().create(getXS2AStandard().getRequestClassProvider().scaUpdateAuthentication(), xs2AFactoryInput);
        xs2AAuthorisationRequest.getHeaders().putAll(getAdditionalHeaders());
        ioProcessor.modifyRequest(xs2AAuthorisationRequest, xs2AFactoryInput);
        paymentSCA = getXS2AStandard().getPis().updatePSUAuthentication(xs2AAuthorisationRequest);
    } else if (authorisationRequest.getAuthenticationMethodId() != null) {
        xs2AAuthorisationRequest = new SCARequestFactory().create(getXS2AStandard().getRequestClassProvider().scaUpdateAuthenticationMethod(), xs2AFactoryInput);
        xs2AAuthorisationRequest.getHeaders().putAll(getAdditionalHeaders());
        ioProcessor.modifyRequest(xs2AAuthorisationRequest, xs2AFactoryInput);
        paymentSCA = getXS2AStandard().getPis().selectAuthenticationMethod(xs2AAuthorisationRequest);
    } else if (authorisationRequest.getScaAuthenticationData() != null) {
        xs2AAuthorisationRequest = new SCARequestFactory().create(getXS2AStandard().getRequestClassProvider().scaAuthoriseTransaction(), xs2AFactoryInput);
        xs2AAuthorisationRequest.getHeaders().putAll(getAdditionalHeaders());
        ioProcessor.modifyRequest(xs2AAuthorisationRequest, xs2AFactoryInput);
        paymentSCA = getXS2AStandard().getPis().authoriseTransaction(xs2AAuthorisationRequest);
    } else {
        xs2AAuthorisationRequest = new SCARequestFactory().create(getXS2AStandard().getRequestClassProvider().scaUpdateIdentification(), xs2AFactoryInput);
        xs2AAuthorisationRequest.getHeaders().putAll(getAdditionalHeaders());
        ioProcessor.modifyRequest(xs2AAuthorisationRequest, xs2AFactoryInput);
        paymentSCA = getXS2AStandard().getPis().updatePSUIdentification(xs2AAuthorisationRequest);
    }
    AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(paymentTypeBean.getPaymentService(), paymentTypeBean.getPaymentProduct(), paymentId, authorisationId);
    paymentSCA.setLinks(aspspUrlMapper.map(paymentSCA.getLinks()));
    LOG.info("Payment Authorisation updated for paymentId={} authorisationId={} scaStatus={} scaApproach={}", paymentId, authorisationId, paymentSCA.getScaStatus(), paymentSCA.getApproach());
    return Response.status(ResponseConstant.OK).entity(paymentSCA).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) PUT(javax.ws.rs.PUT)

Example 8 with SCARequest

use of net.petafuel.styx.core.xs2a.contracts.SCARequest in project styx by petafuel.

the class SCARequestFactory method create.

@Override
public SCARequest create(Class<? extends SCARequest> providedRequest, XS2AFactoryInput factoryInput) {
    try {
        SCARequest scaRequest;
        if (factoryInput.getConsentId() == null && factoryInput.getConsent() == null) {
            Constructor<? extends SCARequest> constructor = providedRequest.getConstructor(PaymentService.class, PaymentProduct.class, String.class);
            scaRequest = constructor.newInstance(factoryInput.getPaymentService(), factoryInput.getPaymentProduct(), factoryInput.getPaymentId());
        } else {
            Constructor<? extends SCARequest> constructor = providedRequest.getConstructor(String.class);
            scaRequest = constructor.newInstance(factoryInput.getConsentId());
        }
        scaRequest.setAuthorisationId(factoryInput.getAuthorisationId());
        scaRequest.setScaAuthenticationData(factoryInput.getScaAuthenticationData());
        scaRequest.setAuthorisationMethodId(factoryInput.getAuthorisationMethodId());
        scaRequest.setPsuData(factoryInput.getPsuData());
        scaRequest.setPsu(factoryInput.getPsu());
        return scaRequest;
    } catch (NoSuchMethodException e) {
        throw new XS2AFactoryException(MessageFormat.format("No viable constructor found for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (IllegalAccessException e) {
        throw new XS2AFactoryException(MessageFormat.format("Unable to access constructor for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (InstantiationException e) {
        throw new XS2AFactoryException(MessageFormat.format("Request class is abstract, no viable constructor found for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (InvocationTargetException e) {
        throw new XS2AFactoryException(MessageFormat.format("Request constructor threw an exception for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (IllegalArgumentException e) {
        throw new XS2AFactoryException(MessageFormat.format("The constructor signature was invalid for this Factory for request={0} error={1}", providedRequest, e.getMessage()), e);
    }
}
Also used : XS2AFactoryException(net.petafuel.styx.core.xs2a.exceptions.XS2AFactoryException) SCARequest(net.petafuel.styx.core.xs2a.contracts.SCARequest) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

SCARequest (net.petafuel.styx.core.xs2a.contracts.SCARequest)8 Path (javax.ws.rs.Path)7 AcceptsPreStepAuth (net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth)7 IOProcessor (net.petafuel.styx.core.ioprocessing.IOProcessor)7 SCARequestFactory (net.petafuel.styx.core.xs2a.factory.SCARequestFactory)7 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)7 SCA (net.petafuel.styx.core.xs2a.entities.SCA)6 AspspUrlMapper (net.petafuel.styx.api.util.AspspUrlMapper)4 ApplicationPath (javax.ws.rs.ApplicationPath)3 GET (javax.ws.rs.GET)3 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 AuthorisationStatusResponse (net.petafuel.styx.api.v1.payment.entity.AuthorisationStatusResponse)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 RequiresPSU (net.petafuel.styx.api.filter.input.boundary.RequiresPSU)1 AuthorisationIdsResponse (net.petafuel.styx.api.v1.payment.entity.AuthorisationIdsResponse)1 XS2AFactoryException (net.petafuel.styx.core.xs2a.exceptions.XS2AFactoryException)1