public static function checkAuthorization(PagSeguroCredentials $credentials, $notificationCode) { LogPagSeguro::info("PagSeguroNotificationService.CheckAuthorization(notificationCode={$notificationCode}) - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildAuthorizationNotificationUrl($connectionData, $notificationCode), $connectionData->getServiceTimeout(), $connectionData->getCharset()); $authorization = PagSeguroAuthorizationParser::readAuthorization($connection->getResponse()); self::$logService = "CheckAuthorization"; return self::searchReturn($connection, $authorization, $notificationCode); } catch (PagSeguroServiceException $err) { throw $err; } catch (Exception $err) { LogPagSeguro::error("Exception: " . $err->getMessage()); throw $err; } }
/** * @param PagSeguroHttpConnection $connection * @param string $authorizationCode * @return bool|mixed|string * @throws PagSeguroServiceException */ private function searchReturn($connection, $code) { $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $authorization = PagSeguroAuthorizationParser::readAuthorization($connection->getResponse()); LogPagSeguro::info(sprintf("PagSeguroAuthorizationSearchService.%s(code={$code}) - end ", self::$logService) . $authorization->toString()); break; case 'BAD_REQUEST': $errors = PagSeguroAuthorizationParser::readErrors($connection->getResponse()); $err = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error(sprintf("PagSeguroAuthorizationSearchService.%s(code={$code}) - error ", self::$logService) . $err->getOneLineMessage()); throw $err; break; default: $err = new PagSeguroServiceException($httpStatus); LogPagSeguro::error(sprintf("PagSeguroAuthorizationSearchService.%s(code={$code}) - error ", self::$logService) . $err->getOneLineMessage()); throw $err; break; } return isset($authorization) ? $authorization : false; }
/** * @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; }