class CmsPsuConfirmationOfFundsController implements CmsPsuConfirmationOfFundsApi {

    @Override
    public ResponseEntity getAuthorisationByAuthorisationId(String authorisationId, String instanceId) {
        try {
            return cmsPsuConfirmationOfFundsService.getAuthorisationByAuthorisationId(authorisationId, instanceId)
                       .map(authorisation -> new ResponseEntity<>(authorisation, HttpStatus.OK))
                       .orElseGet(() -> new ResponseEntity<>(HttpStatus.BAD_REQUEST));
        } catch (AuthorisationIsExpiredException e) {
            log.debug("Authorisation ID [{}], Instance ID: [{}]. Get authorisation by authorisation ID request timeout (authorisation is expired): NOK redirect url [{}]", authorisationId, instanceId, e.getNokRedirectUri());
            return new ResponseEntity<>(new CmsConfirmationOfFundsResponse(e.getNokRedirectUri()), HttpStatus.REQUEST_TIMEOUT);
        }
    }

}