Search in sources :

Example 16 with AcceptsPreStepAuth

use of net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth in project styx by petafuel.

the class AccountResource method getAccountDetails.

/**
 * Returns AccountDetails for a single account
 *
 * @param accountId the xs2a account id
 * @return returns an account object
 * @see AccountDetails
 */
@AcceptsPreStepAuth
@GET
@Path("/accounts/{resourceId}")
public Response getAccountDetails(@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 accountDetailsRequest = new AISRequestFactory().create(getXS2AStandard().getRequestClassProvider().accountDetails(), xs2AFactoryInput);
    accountDetailsRequest.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(accountDetailsRequest, xs2AFactoryInput);
    AccountDetails account = getXS2AStandard().getAis().getAccount(accountDetailsRequest);
    account.setLinks(new AspspUrlMapper(account.getResourceId()).map(account.getLinks()));
    LOG.info("Successfully fetched account details bic={}", getXS2AStandard().getAspsp().getBic());
    return Response.status(200).entity(new AccountDetailResponse(account)).build();
}
Also used : AccountDetailResponse(net.petafuel.styx.api.v1.account.entity.AccountDetailResponse) AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) 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 17 with AcceptsPreStepAuth

use of net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth 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 18 with AcceptsPreStepAuth

use of net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth 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 19 with AcceptsPreStepAuth

use of net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth in project styx by petafuel.

the class PaymentStatusResource method getSinglePaymentStatus.

/**
 * Returns the status of a payment
 *
 * @param paymentTypeBean payment-service and payment-product
 * @param paymentId       id of the target payment
 * @return a PaymentStatus object
 * @throws BankRequestFailedException if something went wrong between the core service and the aspsp
 */
@AcceptsPreStepAuth
@GET
@Path("/{paymentService}/{paymentProduct}/{paymentId}/status")
public Response getSinglePaymentStatus(@BeanParam PaymentTypeBean paymentTypeBean, @PathParam("paymentId") @NotEmpty @NotBlank String paymentId) throws BankRequestFailedException {
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setPaymentService(paymentTypeBean.getPaymentService());
    xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
    xs2AFactoryInput.setPaymentId(paymentId);
    xs2AFactoryInput.setPsu(getPsu());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    PISRequest readPaymentStatusRequest = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentStatus(), xs2AFactoryInput);
    readPaymentStatusRequest.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(readPaymentStatusRequest, xs2AFactoryInput);
    PaymentStatus status = getXS2AStandard().getPis().getPaymentStatus(readPaymentStatusRequest);
    if (PersistentPayment.getByPaymentId(paymentId) == null) {
        PersistentPayment.create(ThreadContext.get("requestUUID"), paymentId, (String) getContainerRequestContext().getProperty(AbstractTokenFilter.class.getName()), getXS2AStandard().getAspsp().getBic(), status.getTransactionStatus(), paymentTypeBean.getPaymentService(), paymentTypeBean.getPaymentProduct());
    } else {
        PersistentPayment.updateStatusByPaymentId(paymentId, status.getTransactionStatus());
    }
    LOG.info("Successfully read the payment status entity for bic={}, paymentId={}", getXS2AStandard().getAspsp().getBic(), paymentId);
    return Response.status(200).entity(status).build();
}
Also used : 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) IOProcessor(net.petafuel.styx.core.ioprocessing.IOProcessor) PaymentStatus(net.petafuel.styx.core.xs2a.entities.PaymentStatus) 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