use of net.petafuel.styx.api.v1.consent.entity.POSTConsentRequest 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();
}
use of net.petafuel.styx.api.v1.consent.entity.POSTConsentRequest in project styx by petafuel.
the class ConsentResourcesTest method createConsentEndpoint.
Response createConsentEndpoint() {
Invocation.Builder invocationBuilder = getInvocationBuilder(String.format(POST_CONSENT, consentId));
POSTConsentRequest request = new POSTConsentRequest();
request.setAccess(new AccountAccess());
request.getAccess().setAccounts(new ArrayList<>());
request.getAccess().getAccounts().add(getAccountReference());
request.getAccess().setBalances(new ArrayList<>());
request.getAccess().getBalances().add(getAccountReference());
request.getAccess().setTransactions(new ArrayList<>());
request.getAccess().getTransactions().add(getAccountReference());
request.setRecurringIndicator(true);
Invocation invocation = invocationBuilder.buildPost(Entity.entity(request, MediaType.APPLICATION_JSON));
return invocation.invoke(Response.class);
}
Aggregations