class PisCommonPaymentServiceInternal implements PisCommonPaymentService {

    @Override
    @Transactional
    public CmsResponse<TransactionStatus> getPisCommonPaymentStatusById(String paymentId) {
        Optional<TransactionStatus> statusOptional = pisCommonPaymentDataRepository.findByPaymentId(paymentId)
                                                         .map(pisCommonPaymentConfirmationExpirationService::checkAndUpdateOnConfirmationExpiration)
                                                         .map(PisCommonPaymentData::getTransactionStatus);

        if (statusOptional.isPresent()) {
            return CmsResponse.<TransactionStatus>builder()
                       .payload(statusOptional.get())
                       .build();
        }

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

}