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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations