/** * @param PagSeguroHttpConnection $connection * @param string $code * @return bool|mixed|string * @throws PagSeguroServiceException */ private function searchReturn($connection, $code) { $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $transaction = PagSeguroPreApprovalParser::readPreApproval($connection->getResponse()); LogPagSeguro::info(sprintf("PagSeguroNotificationService.%s(notificationCode={$code}) - end ", self::$logService) . $transaction->toString() . ")"); break; case 'BAD_REQUEST': $errors = PagSeguroServiceParser::readErrors($connection->getResponse()); $err = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::info(sprintf("PagSeguroNotificationService.%s(notificationCode={$code}) - error ", self::$logService) . $err->getOneLineMessage()); throw $err; break; default: $err = new PagSeguroServiceException($httpStatus); LogPagSeguro::info(sprintf("PagSeguroNotificationService.%s(notificationCode={$code}) - error ", self::$logService) . $err->getOneLineMessage()); throw $err; break; } return isset($transaction) ? $transaction : null; }
/** * @param $connection * @param null $code * @return null|PagSeguroParserData * @throws PagSeguroServiceException */ private function getResult($connection, $code = null) { $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); $response = $connection->getResponse(); switch ($httpStatus->getType()) { case 'OK': switch (self::$service) { case "FindByCode": $result = PagSeguroPreApprovalParser::readPreApproval($response); break; case "FindByNotification": $result = PagSeguroPreApprovalParser::readPreApproval($response); break; case "FindByDayInterval": $result = PagSeguroPreApprovalParser::readSearchResult($response); break; case "FindByDateInterval": $result = PagSeguroPreApprovalParser::readSearchResult($response); break; case "FindByReference": $result = PagSeguroPreApprovalParser::readSearchResult($response); break; } //Logging if (is_null($code) && self::$service == "PreApprovalRequest") { $log['text'] = sprintf("PagSeguroPreApprovalService.%s(" . $response->toString() . ") - end ", self::$service); LogPagSeguro::info($log['text'] . ")"); } else { $log['text'] = sprintf("PagSeguroPreApprovalService.%s({$code}) - end ", self::$service); LogPagSeguro::info($log['text']); } break; case 'BAD_REQUEST': $errors = PagSeguroServiceParser::readErrors($response); $errors = new PagSeguroServiceException($httpStatus, $errors); //Logging $log['text'] = sprintf("PagSeguroPreApprovalService.%s({$code}) - error ", self::$service); LogPagSeguro::error($log['text'] . $errors->getOneLineMessage()); //Exception throw $errors; break; default: $errors = new PagSeguroServiceException($httpStatus); //Logging $log['text'] = sprintf("PagSeguroPreApprovalService.%s({$code}) - error ", self::$service); LogPagSeguro::error($log['text'] . $errors->getOneLineMessage()); //Exception throw $errors; break; } return isset($result) ? $result : null; }
/** * @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; }