/** * @param PagSeguroCredentials $credentials * @param $pageNumber * @param $maxPageResults * @param $initialDate * @param null $finalDate * @return null|PagSeguroParserData * @throws Exception * @throws PagSeguroServiceException */ public static function searchByReference(PagSeguroCredentials $credentials, $pageNumber, $maxPageResults, $initialDate, $finalDate = null, $reference) { //Logging $log['text'] = "PagSeguroPreApprovalService.FindByReference(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ", reference=" . $reference . "begin"; LogPagSeguro::info($log['text']); self::$connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); $params = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate, $reference); try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildFindByReferenceUrl(self::$connectionData, $params), self::$connectionData->getServiceTimeout(), self::$connectionData->getCharset()); self::$service = "FindByReference"; return self::getResult($connection); } catch (PagSeguroServiceException $err) { //Logging LogPagSeguro::error("PagSeguroServiceException: " . $err->getMessage()); //Exception throw $err; } catch (Exception $err) { //Logging LogPagSeguro::error("Exception: " . $err->getMessage()); //Exception throw $err; } }
/** * Search transactions abandoned associated with this set of credentials within a date range * * @param PagSeguroCredentials $credentials * @param String $initialDate * @param String $finalDate * @param integer $pageNumber * @param integer $maxPageResults * @return PagSeguroTransactionSearchResult a object of PagSeguroTransactionSearchResult class * @see PagSeguroTransactionSearchResult * @throws PagSeguroServiceException * @throws Exception */ public static function searchAbandoned(PagSeguroCredentials $credentials, $pageNumber, $maxPageResults, $initialDate, $finalDate = null) { LogPagSeguro::info("PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); $searchParams = array('initialDate' => PagSeguroHelper::formatDate($initialDate), 'pageNumber' => $pageNumber, 'maxPageResults' => $maxPageResults); $searchParams['finalDate'] = $finalDate ? PagSeguroHelper::formatDate($finalDate) : null; try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildSearchUrlAbandoned($connectionData, $searchParams), $connectionData->getServiceTimeout(), $connectionData->getCharset()); $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $searchResult = PagSeguroTransactionParser::readSearchResult($connection->getResponse()); LogPagSeguro::info("PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $searchResult->toString()); break; case 'BAD_REQUEST': $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); $e = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error("PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $e->getOneLineMessage()); throw $e; break; default: $e = new PagSeguroServiceException($httpStatus); LogPagSeguro::error("PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $e->getOneLineMessage()); throw $e; break; } return isset($searchResult) ? $searchResult : false; } catch (PagSeguroServiceException $e) { throw $e; } catch (Exception $e) { LogPagSeguro::error("Exception: " . $e->getMessage()); throw $e; } }
private function searchResult($connection, $initialDate = null, $finalDate = null) { $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $searchResult = PagSeguroTransactionParser::readSearchResult($connection->getResponse()); LogPagSeguro::info(sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $searchResult->toString()); break; case 'BAD_REQUEST': $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); $err = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error(sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage()); throw $err; break; default: $err = new PagSeguroServiceException($httpStatus); LogPagSeguro::error(sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage()); throw $err; break; } return isset($searchResult) ? $searchResult : false; }