/**
  * Returns a transaction from a notification code
  * 
  * @param PagSeguroCredentials $credentials
  * @param String $notificationCode
  * @throws PagSeguroServiceException
  * @throws Exception
  * @return a transaction
  * @see PagSeguroTransaction
  */
 public static function checkTransaction(PagSeguroCredentials $credentials, $notificationCode)
 {
     LogPagSeguro::info("PagSeguroNotificationService.CheckTransaction(notificationCode={$notificationCode}) - begin");
     $connectionData = new PagSeguroConnectionData($credentials, self::serviceName);
     try {
         $connection = new PagSeguroHttpConnection();
         $connection->get(self::buildTransactionNotificationUrl($connectionData, $notificationCode), $connectionData->getServiceTimeout(), $connectionData->getCharset());
         $httpStatus = new PagSeguroHttpStatus($connection->getStatus());
         switch ($httpStatus->getType()) {
             case 'OK':
                 // parses the transaction
                 $transaction = PagSeguroTransactionParser::readTransaction($connection->getResponse());
                 LogPagSeguro::info("PagSeguroNotificationService.CheckTransaction(notificationCode={$notificationCode}) - end " . $transaction->toString() . ")");
                 break;
             case 'BAD_REQUEST':
                 $errors = PagSeguroTransactionParser::readErrors($connection->getResponse());
                 $e = new PagSeguroServiceException($httpStatus, $errors);
                 LogPagSeguro::info("PagSeguroNotificationService.CheckTransaction(notificationCode={$notificationCode}) - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
             default:
                 $e = new PagSeguroServiceException($httpStatus);
                 LogPagSeguro::info("PagSeguroNotificationService.CheckTransaction(notificationCode={$notificationCode}) - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
         }
         return isset($transaction) ? $transaction : null;
     } catch (PagSeguroServiceException $e) {
         throw $e;
     } catch (Exception $e) {
         LogPagSeguro::error("Exception: " . $e->getMessage());
         throw $e;
     }
 }
 /**
  * @param PagSeguroCredentials $credentials
  * @param $transactionCode
  * @throws Exception
  * @throws PagSeguroServiceException
  */
 public static function createRequest(PagSeguroCredentials $credentials, $transactionCode)
 {
     LogPagSeguro::info("PagSeguroCancelService.Register(" . $transactionCode . ") - begin");
     $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME);
     try {
         $connection = new PagSeguroHttpConnection();
         $connection->post(self::buildCancelURL($connectionData, $transactionCode), array(), $connectionData->getServiceTimeout(), $connectionData->getCharset());
         $httpStatus = new PagSeguroHttpStatus($connection->getStatus());
         switch ($httpStatus->getType()) {
             case 'OK':
                 $result = PagSeguroCancelParser::readSuccessXml($connection->getResponse());
                 LogPagSeguro::info("PagSeguroCancelService.createRequest(" . $result . ") - end ");
                 break;
             case 'BAD_REQUEST':
                 $errors = PagSeguroCancelParser::readErrors($connection->getResponse());
                 $err = new PagSeguroServiceException($httpStatus, $errors);
                 LogPagSeguro::error("PagSeguroCancelService.createRequest() - error " . $err->getOneLineMessage());
                 throw $err;
                 break;
             default:
                 $err = new PagSeguroServiceException($httpStatus);
                 LogPagSeguro::error("PagSeguroCancelService.createRequest() - error " . $err->getOneLineMessage());
                 throw $err;
                 break;
         }
         return isset($result) ? $result : false;
     } catch (PagSeguroServiceException $err) {
         throw $err;
     } catch (Exception $err) {
         LogPagSeguro::error("Exception: " . $err->getMessage());
         throw $err;
     }
 }
 public static function getSession($credentials)
 {
     $connectionData = new PagSeguroConnectionData($credentials, 'sessionService');
     $url = self::buildSessionURL($connectionData) . "?" . $connectionData->getCredentialsUrlQuery();
     try {
         $connection = new PagSeguroHttpConnection();
         $connection->post($url, array(), $connectionData->getServiceTimeout(), $connectionData->getCharset());
         $httpStatus = new PagSeguroHttpStatus($connection->getStatus());
         switch ($httpStatus->getType()) {
             case 'OK':
                 $session = PagSeguroSessionParser::readResult($connection->getResponse());
                 return $session->getId();
                 LogPagSeguro::info("PagSeguroSessionService.getSession()(" . $session->toString() . ") - end {1}");
                 break;
             case 'BAD_REQUEST':
                 $errors = PagSeguroSessionParser::readErrors($connection->getStatus());
                 $e = new PagSeguroServiceException($httpStatus, $errors);
                 LogPagSeguro::error("PagSeguroSessionService.getSession() - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
             default:
                 $e = new PagSeguroServiceException($httpStatus);
                 LogPagSeguro::error("PagSeguroSessionService.getSession() - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
         }
     } catch (PagSeguroServiceException $e) {
         throw $e;
     } catch (Exception $e) {
         LogPagSeguro::error("Exception: " . $e->getMessage());
         throw $e;
     }
 }
 public static function createCheckoutRequest(Credentials $credentials, PaymentRequest $paymentRequest)
 {
     LogPagSeguro::info("PaymentService.Register(" . $paymentRequest->toString() . ") - begin");
     $connectionData = new PagSeguroConnectionData($credentials, self::serviceName);
     try {
         $connection = new HttpConnection();
         $connection->post(self::buildCheckoutRequestUrl($connectionData), PaymentParser::getData($paymentRequest), $connectionData->getServiceTimeout(), $connectionData->getCharset());
         $httpStatus = new HttpStatus($connection->getStatus());
         switch ($httpStatus->getType()) {
             case 'OK':
                 $PaymentParserData = PaymentParser::readSuccessXml($connection->getResponse());
                 $paymentUrl = self::buildCheckoutUrl($connectionData, $PaymentParserData->getCode());
                 LogPagSeguro::info("PaymentService.Register(" . $paymentRequest->toString() . ") - end {1}" . $PaymentParserData->getCode());
                 break;
             case 'BAD_REQUEST':
                 $errors = PaymentParser::readErrors($connection->getResponse());
                 $e = new PagSeguroServiceException($httpStatus, $errors);
                 LogPagSeguro::error("PaymentService.Register(" . $paymentRequest->toString() . ") - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
             default:
                 $e = new PagSeguroServiceException($httpStatus);
                 LogPagSeguro::error("PaymentService.Register(" . $paymentRequest->toString() . ") - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
         }
         return isset($paymentUrl) ? $paymentUrl : false;
     } catch (PagSeguroServiceException $e) {
         throw $e;
     } catch (Exception $e) {
         LogPagSeguro::error("Exception: " . $e->getMessage());
         throw $e;
     }
 }
 private function __construct()
 {
     self::$path = dirname(__FILE__);
     PagSeguroAutoloader::init();
     self::$resources = PagSeguroResources::init();
     self::$config = PagSeguroConfig::init();
     self::$log = LogPagSeguro::init();
 }
 private static function printLog($strType = null)
 {
     $count = 4;
     echo "<h2>Receive notifications</h2>";
     if ($strType) {
         echo "<h4>notifcationType: {$strType}</h4>";
     }
     echo "<p>Last <strong>{$count}</strong> items in <strong>log file:</strong></p><hr>";
     echo LogPagSeguro::getHtml($count);
 }
 private function __construct()
 {
     self::$path = dirname(__FILE__);
     if (function_exists('spl_autoload_register')) {
         require_once "loader" . DIRECTORY_SEPARATOR . "PagSeguroAutoLoader.class.php";
         PagSeguroAutoloader::init();
     } else {
         require_once "loader" . DIRECTORY_SEPARATOR . "PagSeguroAutoLoader.php";
     }
     self::$resources = PagSeguroResources::init();
     self::$config = PagSeguroConfig::init();
     self::$log = LogPagSeguro::init();
 }
 /**
  * Creates the log file
  * @throws Exception
  * @return boolean
  */
 public static function createFile()
 {
     if (!self::$active) {
         return false;
     }
     $defaultPath = PagSeguroLibrary::getPath();
     $defaultName = 'PagSeguro.log';
     self::$fileLocation = $defaultPath . DIRECTORY_SEPARATOR . $defaultName;
     if ($f = @fopen(self::$fileLocation, "a")) {
         fclose($f);
     } else {
         throw new Exception("Can't create log file. Permission denied. File location: " . self::$fileLocation);
     }
 }
 public function __construct()
 {
     if (self::verifyDependencies()) {
         if (self::$library == null) {
             self::$path = dirname(__FILE__);
             PagSeguroAutoloader::init();
             self::$resources = PagSeguroResources::init();
             self::$config = PagSeguroConfig::init();
             self::$log = LogPagSeguro::init();
             self::$library = $this;
         }
     }
     return self::$library;
 }
Example #10
0
 /**
  * Creates the log file
  * @throws Exception
  * @return boolean
  */
 public static function createFile()
 {
     if (!self::$active) {
         return false;
     }
     $defaultPath = PagSeguroLibrary::getPath();
     $defaultName = 'PagSeguro.log';
     self::$fileLocation = $defaultPath . DIRECTORY_SEPARATOR . $defaultName;
     try {
         $f = fopen(self::$fileLocation, "a");
         fclose($f);
     } catch (Exception $e) {
         echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " . self::$fileLocation;
     }
 }
 public static function getRetorno($code, $type)
 {
     $this->ci->log_message('error', $code . '|' . $type);
     if ($code && $type) {
         $notificationType = new PagSeguroNotificationType($type);
         $strType = $notificationType->getTypeFromValue();
         switch ($strType) {
             case 'TRANSACTION':
                 return self::transactionNotification($code);
                 break;
             default:
                 LogPagSeguro::error("Unknown notification type [" . $notificationType->getValue() . "]");
                 show_error('PagSeguroLibrary: Unknown notification type [' . $notificationType->getValue() . ']');
                 break;
         }
     } else {
         LogPagSeguro::error("Invalid notification parameters.");
         show_error('PagSeguroLibrary: Invalid notification parameters.');
     }
 }
Example #12
0
 public static function createFile($logFile = false)
 {
     if (!self::$active) {
         return false;
     }
     $defaultPath = PagSeguroLibrary::getPath();
     $defaultName = 'PagSeguro.log';
     self::$fileLocation = $logFile ? $logFile : $defaultPath . DIRECTORY_SEPARATOR . $defaultName;
     try {
         $f = fopen(self::$fileLocation, "a");
         if (!$f) {
             throw new Exception('Unable to open the input file');
         }
         fclose($f);
         return true;
     } catch (Exception $e) {
         echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " . self::$fileLocation;
         return false;
     }
 }
Example #13
0
 public static function main()
 {
     $code = self::verifyData($_POST['notificationCode']);
     $type = self::verifyData($_POST['notificationtype']);
     if ($code && $type) {
         $notificationType = new NotificationType($type);
         $strType = $notificationType->getTypeFromValue();
         switch ($strType) {
             case 'TRANSACTION':
                 self::TransactionNotification($code);
                 break;
             default:
                 LogPagSeguro::error("Tipo de notificação não reconhecido [" . $notificationType->getValue() . "]");
         }
         self::saveLog($strType);
     } else {
         LogPagSeguro::error("Os parâmetros de notificação (notificationCode e notificationType) não foram recebidos.");
         self::saveLog();
     }
 }
 public static function createFile()
 {
     if (!self::$active) {
         return false;
     }
     $defaultPath = PagSeguroLibrary::getPath();
     $defaultName = 'PagSeguro' . mt_rand() . '.log';
     self::$fileLocation = $defaultPath . DIRECTORY_SEPARATOR . $defaultName;
     Configuration::updateValue('PAGSEGURO_LOG_FILELOCATION', "/modules/pagseguro/features/PagSeguroLibrary/" . $defaultName);
     try {
         $f = fopen(self::$fileLocation, "a");
         if (!$f) {
             throw new Exception('Unable to open the input file');
         }
         fclose($f);
         return true;
     } catch (Exception $e) {
         echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " . self::$fileLocation;
         return false;
     }
 }
 public static function getInstallments($credentials, $session, $amount, $cardBrand)
 {
     $connectionData = new PagSeguroConnectionData($credentials, 'installmentService');
     $url = self::buildInstallmentURL($connectionData) . "?sessionId=" . $session . "&amount=" . $amount . "&creditCardBrand=" . $cardBrand;
     LogPagSeguro::info("PagSeguroInstallmentService.getInstallments(" . $amount . "," . $cardBrand . ") - begin");
     try {
         $connection = new PagSeguroHttpConnection();
         $connection->get($url, $connectionData->getServiceTimeout(), $connectionData->getCharset());
         $httpStatus = new PagSeguroHttpStatus($connection->getStatus());
         switch ($httpStatus->getType()) {
             case 'OK':
                 $installments = PagSeguroInstallmentParser::readInstallments($connection->getResponse());
                 if (is_array($installments)) {
                     LogPagSeguro::info("PagSeguroInstallmentService.getInstallments() - end {1}");
                 } else {
                     LogPagSeguro::info("PagSeguroInstallmentService.getInstallments() - error" . $installments->message);
                     throw new Exception($installments->message);
                 }
                 break;
             case 'BAD_REQUEST':
                 $errors = PagSeguroInstallmentParser::readErrors($connection->getResponse());
                 $e = new PagSeguroServiceException($httpStatus, $errors);
                 LogPagSeguro::error("PagSeguroInstallmentService.getInstallments() - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
             default:
                 $e = new PagSeguroServiceException($httpStatus);
                 LogPagSeguro::error("PagSeguroInstallmentService.getInstallments() - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
         }
         return isset($installments) ? $installments : false;
     } catch (PagSeguroServiceException $e) {
         throw $e;
     } catch (Exception $e) {
         LogPagSeguro::error("Exception: " . $e->getMessage());
         throw $e;
     }
 }
 /**
  * @param $connection
  * @return null|PagSeguroParserData
  * @throws PagSeguroServiceException
  */
 private function getResult($connection)
 {
     $httpStatus = new PagSeguroHttpStatus($connection->getStatus());
     switch ($httpStatus->getType()) {
         case 'OK':
             $cancel = PagSeguroCancelParser::readSuccessXml($connection->getResponse());
             LogPagSeguro::info("PagSeguroCancelService.createRequest(" . $cancel . ") - end ");
             break;
         case 'BAD_REQUEST':
             $errors = PagSeguroCancelParser::readErrors($connection->getResponse());
             $err = new PagSeguroServiceException($httpStatus, $errors);
             LogPagSeguro::error("PagSeguroCancelService.createRequest() - error " . $err->getOneLineMessage());
             throw $err;
             break;
         default:
             $err = new PagSeguroServiceException($httpStatus);
             LogPagSeguro::error("PagSeguroCancelService.createRequest() - error " . $err->getOneLineMessage());
             throw $err;
             break;
     }
     return isset($cancel) ? $cancel : false;
 }
 private function createLog()
 {
     /*** Retrieving configurated default charset */
     PagSeguroConfig::setApplicationCharset(Configuration::get('PAGSEGURO_CHARSET'));
     /*** Retrieving configurated default log info */
     if (Configuration::get('PAGSEGURO_LOG_ACTIVE')) {
         PagSeguroConfig::activeLog(_PS_ROOT_DIR_ . Configuration::get('PAGSEGURO_LOG_FILELOCATION'));
     }
     LogPagSeguro::info("PagSeguroAbandoned.Search( 'Pesquisa de transações abandonadas realizada em " . date("d/m/Y H:i") . ".')");
 }
Example #18
0
 public static function activeLog($fileName = null)
 {
     self::setData('log', 'active', true);
     self::setData('log', 'fileLocation', $fileName ? $fileName : '');
     LogPagSeguro::reLoad();
 }
 public function createLog($type, $dados)
 {
     /*** Retrieving configurated default charset */
     PagSeguroConfig::setApplicationCharset(Configuration::get('PAGSEGURO_CHARSET'));
     /*** Retrieving configurated default log info */
     if (Configuration::get('PAGSEGURO_LOG_ACTIVE')) {
         PagSeguroConfig::activeLog(_PS_ROOT_DIR_ . Configuration::get('PAGSEGURO_LOG_FILELOCATION'));
     }
     switch ($type) {
         case 'search':
             LogPagSeguro::info("PagSeguroConciliation.Search( 'Pesquisa de conciliação realizada em " . date("d/m/Y H:i") . " em um intervalo de " . $dados['days'] . " dias.')");
             break;
         default:
             LogPagSeguro::info("PagSeguroConciliation.Register( 'Alteração de Status da compra '" . $dados['idOrder'] . "' para o Status '" . $dados['newStatus'] . "(" . $dados['newIdStatus'] . ")' - '" . date("d/m/Y H:i") . "') - end");
             break;
     }
 }
 /**
  * @param PagSeguroHttpConnection $connection
  * @param string $code
  * @return bool|mixed|string
  * @throws PagSeguroServiceException
  */
 private function searchReturn($connection, $parsers, $code)
 {
     $httpStatus = new PagSeguroHttpStatus($connection->getStatus());
     switch ($httpStatus->getType()) {
         case 'OK':
             LogPagSeguro::info(sprintf("PagSeguroNotificationService.%s(notificationCode={$code}) - end ", self::$logService) . $parsers->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($parsers) ? $parsers : null;
 }
 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;
 }
 /**
  * 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;
     }
 }
 /**
  * Perform update by received PagSeguro notification
  * @param string $notificationCode
  */
 private function _doUpdateByNotification($notificationCode)
 {
     // getting configuration params data
     $paramsData = $this->_getParamsData();
     try {
         // getting credentials data
         $credentials = new PagSeguroAccountCredentials($paramsData['pagseguro_email'], $paramsData['pagseguro_token']);
         // getting transaction data object
         $transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode);
         // getting PagSeguro status number
         $statusPagSeguro = $transaction->getStatus()->getValue();
         // getting new order state
         $newStatus = $this->_getAssociatedStatus($paramsData, $statusPagSeguro);
         // getting status translation
         $statusTranslation = $this->_getStatusTranslation($statusPagSeguro);
         // performing update status
         if (!PagSeguroHelper::isEmpty($newStatus)) {
             $this->_updateOrderStatus($transaction->getReference(), $newStatus, $statusTranslation);
         }
     } catch (PagSeguroServiceException $e) {
         LogPagSeguro::error("Error trying get transaction [" . $e->getMessage() . "]");
     }
 }
 /**
  * @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;
 }
 /**
  * @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 "PreApprovalRequest":
                     $response = PagSeguroPreApprovalParser::readSuccessXml($response);
                     $result = array('code' => $response->getCode(), 'cancelUrl' => self::buildPreApprovalCancelUrl(self::$connectionData, $response->getCode()), 'checkoutUrl' => self::buildPreApprovalRequestUrl(self::$connectionData, $response->getCode()));
                     break;
                 case "PreApprovalCancel":
                     $result = PagSeguroPreApprovalParser::readCancelXml($response);
                     break;
                 case "PreApprovalPaymentCharge":
                     $result = PagSeguroPreApprovalParser::readTransactionXml($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 $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;
 }
 public static function cancelPreApproval(PagSeguroCredentials $credentials, $notificationCode)
 {
     LogPagSeguro::info("PagSeguroNotificationService.cancelPreApproval(notificationCode={$notificationCode}) - begin");
     $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME);
     try {
         $connection = new PagSeguroHttpConnection();
         $connection->get(self::buildCancelUrl($connectionData, $notificationCode), $connectionData->getServiceTimeout(), $connectionData->getCharset());
         $httpStatus = new PagSeguroHttpStatus($connection->getStatus());
         switch ($httpStatus->getType()) {
             case 'OK':
                 $paymentParserData = PagSeguroPreApprovalParser::readCancelXml($connection->getResponse());
                 LogPagSeguro::info("PagSeguroPreApprovalService.cancelPreApproval({$parserData}) - end \\{{$notificationCode}\\}");
                 break;
             case 'BAD_REQUEST':
                 $errors = PagSeguroPreApprovalParser::readErrors($connection->getResponse());
                 $e = new PagSeguroServiceException($httpStatus, $errors);
                 LogPagSeguro::error("PagSeguroPreApprovalService.cancelPreApproval(notificationCode={$notificationCode}) - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
             default:
                 $e = new PagSeguroServiceException($httpStatus);
                 LogPagSeguro::error("PagSeguroPreApprovalService.cancelPreApproval(notificationCode={$notificationCode}) - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
         }
         return isset($paymentParserData) ? $paymentParserData : false;
     } catch (PagSeguroServiceException $err) {
         LogPagSeguro::error("PagSeguroServiceException: " . $err->getMessage());
         throw $err;
     } catch (Exception $err) {
         LogPagSeguro::error("Exception: " . $err->getMessage());
         throw $err;
     }
 }
 /**
  * Perform update by received PagSeguro notification
  * @param string $notificationCode
  */
 private function _doUpdateByNotification($statuses, $notificationCode)
 {
     try {
         // getting credentials data
         $credentials = new PagSeguroAccountCredentials($this->payment_params->pagseguro_email, $this->payment_params->pagseguro_token);
         // getting transaction data object
         $transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode);
         // getting PagSeguro status number
         $statusPagSeguro = $transaction->getStatus()->getValue();
         $array_status = array(0 => 'Initiated', 1 => 'Waiting payment', 2 => 'In analysis', 3 => 'Paid', 4 => 'Available', 5 => 'In dispute', 6 => 'refunded', 7 => 'cancelled');
         // performing update status
         if (!PagSeguroHelper::isEmpty($statusPagSeguro) && (int) $statusPagSeguro == 3) {
             $orderClass = hikashop_get('class.order');
             $dbOrder = $orderClass->get((int) $transaction->getReference());
             $email = new stdClass();
             $history = new stdClass();
             $order_status = $this->payment_params->verified_status;
             $history->notified = 1;
             if ($dbOrder->order_status == $order_status) {
                 return true;
             }
             $url = HIKASHOP_LIVE . 'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id=' . $dbOrder->order_id;
             $order_text = "\r\n" . JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE', $dbOrder->order_number, HIKASHOP_LIVE);
             $order_text .= "\r\n" . str_replace('<br/>', "\r\n", JText::sprintf('ACCESS_ORDER_WITH_LINK', $url));
             $mail_status = $statuses[$order_status];
             $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Pagseguro', $array_status[$statusPagSeguro], $dbOrder->order_number);
             $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Pagseguro', $array_status[$statusPagSeguro])) . ' ' . JText::sprintf('ORDER_STATUS_CHANGED', $mail_status) . "\r\n\r\n" . $order_text;
             $this->modifyOrder($dbOrder->order_id, $order_status, $history, $email);
         } elseif ((int) $statusPagSeguro == 7) {
             $orderClass = hikashop_get('class.order');
             $dbOrder = $orderClass->get((int) $transaction->getReference());
             $email = new stdClass();
             $history = new stdClass();
             $order_status = $this->payment_params->invalid_status;
             $history->notified = 0;
             if ($dbOrder->order_status == $order_status) {
                 return true;
             }
             $url = HIKASHOP_LIVE . 'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id=' . $dbOrder->order_id;
             $order_text = "\r\n" . JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE', $dbOrder->order_number, HIKASHOP_LIVE);
             $order_text .= "\r\n" . str_replace('<br/>', "\r\n", JText::sprintf('ACCESS_ORDER_WITH_LINK', $url));
             $mail_status = $statuses[$order_status];
             $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Pagseguro', $array_status[$statusPagSeguro], $dbOrder->order_number);
             $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Pagseguro', $array_status[$statusPagSeguro])) . ' ' . JText::sprintf('ORDER_STATUS_CHANGED', $mail_status) . "\r\n\r\n" . $order_text;
             $this->modifyOrder($dbOrder->order_id, $order_status, $history, $email);
         }
     } catch (PagSeguroServiceException $e) {
         LogPagSeguro::error("Error trying get transaction [" . $e->getMessage() . "]");
     }
     return true;
 }
 /**
  * @param $connection
  * @param PagSeguroDirectPaymentRequest $request
  * @return null|PagSeguroParserData
  * @throws PagSeguroServiceException
  */
 private static function getResult($connection, PagSeguroDirectPaymentRequest $request)
 {
     $httpStatus = new PagSeguroHttpStatus($connection->getStatus());
     switch ($httpStatus->getType()) {
         case 'OK':
             $paymentReturn = PagSeguroTransactionParser::readTransaction($connection->getResponse());
             LogPagSeguro::info("PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - end {1}" . $paymentReturn->getCode());
             break;
         case 'BAD_REQUEST':
             $errors = PagSeguroTransactionParser::readErrors($connection->getResponse());
             $error = new PagSeguroServiceException($httpStatus, $errors);
             LogPagSeguro::error("PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - error " . $error->getOneLineMessage());
             throw $error;
             break;
         default:
             $error = new PagSeguroServiceException($httpStatus);
             LogPagSeguro::error("PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - error " . $error->getOneLineMessage());
             throw $error;
             break;
     }
     return isset($paymentReturn) ? $paymentReturn : false;
 }
 /**
  * @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;
 }