/**
  * @param PagSeguroConnectionData $connection
  * @param $code
  * @return null|PagSeguroAuthorization|PagSeguroParserData|PagSeguroTransaction
  * @throws PagSeguroServiceException
  */
 private static function getResult($connection, $code)
 {
     $httpStatus = new PagSeguroHttpStatus($connection->getStatus());
     $response = $connection->getResponse();
     switch ($httpStatus->getType()) {
         case 'OK':
             switch (self::$service) {
                 case "CheckPreApproval":
                     $response = PagSeguroPreApprovalParser::readPreApproval($response);
                     break;
                 case "CheckAuthorization":
                     $response = PagSeguroAuthorizationParser::readAuthorization($response);
                     break;
                 case "CheckTransaction":
                     $response = PagSeguroTransactionParser::readTransaction($response);
                     break;
             }
             //Logging
             $log['text'] = sprintf("PagSeguroNotificationService.%s(notificationCode={$code}) - end ", self::$service);
             $log['action'] = $response->toString();
             LogPagSeguro::info($log['text'] . $log['action'] . ")");
             break;
         case 'BAD_REQUEST':
             $errors = PagSeguroServiceParser::readErrors($connection->getResponse());
             $errors = new PagSeguroServiceException($httpStatus, $errors);
             //Logging
             $log['text'] = sprintf("PagSeguroNotificationService.%s(notificationCode={$code}) - error ", self::$service);
             LogPagSeguro::error($log['text'] . $errors->getOneLineMessage());
             //Exception
             throw $errors;
             break;
         default:
             $errors = new PagSeguroServiceException($httpStatus);
             //Logging
             $log['text'] = sprintf("PagSeguroNotificationService.%s(notificationCode={$code}) - error ", self::$service);
             LogPagSeguro::info($log['text'] . $errors->getOneLineMessage());
             //Exception
             throw $errors;
             break;
     }
     return isset($response) ? $response : null;
 }