class PisCommonPaymentServiceInternal implements PisCommonPaymentService {

    @Override
    @Transactional
    public CmsResponse<PisCommonPaymentResponse> getCommonPaymentById(String paymentId) {
        Optional<PisCommonPaymentData> paymentOptional = pisCommonPaymentDataRepository.findByPaymentId(paymentId);
        if (paymentOptional.isPresent()) {
            List<AuthorisationEntity> authorisations =
                authorisationRepository.findAllByParentExternalIdAndTypeIn(paymentId, EnumSet.of(AuthorisationType.PIS_CREATION, AuthorisationType.PIS_CANCELLATION));
            Optional<PisCommonPaymentResponse> responseOptional = paymentOptional
                                                                      .map(pisCommonPaymentConfirmationExpirationService::checkAndUpdateOnConfirmationExpiration)
                                                                      .flatMap(p -> pisCommonPaymentMapper.mapToPisCommonPaymentResponse(p, authorisations));


            if (responseOptional.isPresent()) {
                PisCommonPaymentResponse pisCommonPaymentResponse = responseOptional.get();
                transferCorePaymentToCommonPayment(pisCommonPaymentResponse, paymentOptional.get());
                return CmsResponse.<PisCommonPaymentResponse>builder()
                           .payload(pisCommonPaymentResponse)
                           .build();
            }
        }

        log.info("Payment ID: [{}]. Get common payment by ID failed, because payment was not found by the ID",
                 paymentId);
        return CmsResponse.<PisCommonPaymentResponse>builder()
                   .error(LOGICAL_ERROR)
                   .build();
    }

}