/** * @param PagSeguroHttpConnection $connection * @param PagSeguroAuthorizationRequest $authorizationRequest * @param PagSeguroConnectionData $connectionData * @param null $onlyAuthorizationCode * @return bool|mixed|string * @throws PagSeguroServiceException */ private static function authorizationReturn(PagSeguroHttpConnection $connection, PagSeguroAuthorizationRequest $authorizationRequest, PagSeguroConnectionData $connectionData, $onlyAuthorizationCode = null) { $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $authorization = PagSeguroAuthorizationParser::readSuccessXml($connection->getResponse()); if ($onlyAuthorizationCode) { $authorizationReturn = $authorization->getCode(); } else { $authorizationReturn = self::buildAuthorizationApprovalUrl($connectionData, $authorization->getCode()); } LogPagSeguro::info("PagSeguroAuthorizationService.Register(" . $authorizationRequest->toString() . ") - end {1}" . $authorization->getCode()); break; case 'BAD_REQUEST': $errors = PagSeguroPaymentParser::readErrors($connection->getResponse()); $err = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error("PagSeguroAuthorizationService.Register(" . $authorizationRequest->toString() . ") - error " . $err->getOneLineMessage()); throw $err; break; default: $err = new PagSeguroServiceException($httpStatus); LogPagSeguro::error("PagSeguroAuthorizationService.Register(" . $authorizationRequest->toString() . ") - error " . $err->getOneLineMessage()); throw $err; break; } return isset($authorizationReturn) ? $authorizationReturn : false; }
/** * @param PagSeguroHttpConnection $connection * @return bool|mixed|string * @throws PagSeguroServiceException */ private function searchAuthorizationsReturn($connection) { $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $authorization = PagSeguroAuthorizationParser::readSearchResult($connection->getResponse()); LogPagSeguro::info("PagSeguroAuthorizationSearchService.searchAuthorizations() - end " . $authorization->toString()); break; case 'BAD_REQUEST': $errors = PagSeguroAuthorizationParser::readErrors($connection->getResponse()); $err = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error("PagSeguroAuthorizationSearchService.searchAuthorizations() - error " . $err->getOneLineMessage()); throw $err; break; default: $err = new PagSeguroServiceException($httpStatus); LogPagSeguro::error("PagSeguroAuthorizationSearchService.searchAuthorizations() - error " . $err->getOneLineMessage()); throw $err; break; } return isset($authorization) ? $authorization : false; }
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 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; }