public static function createCheckoutRequest(PagSeguroCredentials $credentials, PagSeguroDirectPaymentRequest $request)
 {
     LogPagSeguro::info("PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - begin");
     $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME);
     try {
         $connection = new PagSeguroHttpConnection();
         $connection->post(self::buildCheckoutRequestUrl($connectionData), PagSeguroDirectPaymentParser::getData($request), $connectionData->getServiceTimeout(), $connectionData->getCharset());
         $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());
                 $e = new PagSeguroServiceException($httpStatus, $errors);
                 LogPagSeguro::error("PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
             default:
                 $e = new PagSeguroServiceException($httpStatus);
                 LogPagSeguro::error("PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
         }
         return isset($paymentReturn) ? $paymentReturn : false;
     } catch (PagSeguroServiceException $e) {
         throw $e;
     } catch (Exception $e) {
         LogPagSeguro::error("Exception: " . $e->getMessage());
         throw $e;
     }
 }
 /**
  * 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;
     }
 }
 public static function checkTransaction(PagSeguroCredentials $credentials, $notificationCode)
 {
     LogPagSeguro::info("PagSeguroNotificationService.CheckTransaction(notificationCode={$notificationCode}) - begin");
     $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME);
     try {
         $connection = new PagSeguroHttpConnection();
         $connection->get(self::buildTransactionNotificationUrl($connectionData, $notificationCode), $connectionData->getServiceTimeout(), $connectionData->getCharset());
         $transaction = PagSeguroTransactionParser::readTransaction($connection->getResponse());
         self::$logService = "CheckTransaction";
         return self::searchReturn($connection, $transaction, $notificationCode);
     } catch (PagSeguroServiceException $err) {
         throw $err;
     } catch (Exception $err) {
         LogPagSeguro::error("Exception: " . $err->getMessage());
         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;
     }
 }
 /**
  * @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;
 }
 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;
 }
 /**
  * @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;
 }