/** * 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; } }
/** * Get from webservice installments for direct payment. * @param PagSeguroCredentials $credentials * @param $amount * @param $cardBrand * @param $maxInstallmentNoInterest * @return bool|PagSeguroInstallment * @throws Exception * @throws PagSeguroServiceException */ public static function getInstallments(PagSeguroCredentials $credentials, $amount, $cardBrand = null, $maxInstallmentNoInterest = null) { $amount = PagSeguroHelper::decimalFormat($amount); LogPagSeguro::info("PagSeguroInstallmentService.getInstallments(" . $amount . ") - begin"); self::$connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildInstallmentURL(self::$connectionData, $amount, $cardBrand, $maxInstallmentNoInterest), self::$connectionData->getServiceTimeout(), self::$connectionData->getCharset()); $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $installments = PagSeguroInstallmentParser::readInstallments($connection->getResponse()); LogPagSeguro::info("PagSeguroInstallmentService.getInstallments() - end "); 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; } }
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; } }
/** * 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; } }
public static function searchByReference(PagSeguroCredentials $credentials, $reference) { LogPagSeguro::info("PagSeguroAuthorizationSearchService.SearchByReference({$reference}) - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildSearchUrlByReference($connectionData, $reference), $connectionData->getServiceTimeout(), $connectionData->getCharset()); self::$logService = "SearchByReference"; return self::searchAuthorizationsReturn($connection, $reference); } catch (PagSeguroServiceException $err) { throw $err; } catch (Exception $err) { LogPagSeguro::error("Exception: " . $err->getMessage()); throw $err; } }
/** * @param PagSeguroCredentials $credentials * @param $notificationCode * @return null|PagSeguroParserData * @throws Exception * @throws PagSeguroServiceException */ public static function findByNotification(PagSeguroCredentials $credentials, $notificationCode) { LogPagSeguro::info("PagSeguroPreApprovalService.FindByNotification({$notificationCode}) - begin"); self::$connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildFindByNotificationUrl(self::$connectionData, $notificationCode), self::$connectionData->getServiceTimeout(), self::$connectionData->getCharset()); self::$service = "FindByNotification"; return self::getResult($connection, $notificationCode); } catch (PagSeguroServiceException $err) { //Logging LogPagSeguro::error("PagSeguroServiceException: " . $err->getMessage()); //Exception throw $err; } catch (Exception $err) { //Logging LogPagSeguro::error("Exception: " . $err->getMessage()); //Exception throw $err; } }
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; } }
/** * @param PagSeguroCredentials $credentials * @param $code * @return null|PagSeguroParserData * @throws Exception * @throws PagSeguroServiceException */ public static function cancelPreApproval(PagSeguroCredentials $credentials, $code) { //Logging $log['text'] = "PagSeguroNotificationService.PreApprovalCancel({$code}) - begin"; LogPagSeguro::info($log['text']); self::$connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildPreApprovalCancelUrl(self::$connectionData, $code), self::$connectionData->getServiceTimeout(), self::$connectionData->getCharset()); self::$service = "PreApprovalCancel"; return self::getResult($connection, $code); } catch (PagSeguroServiceException $err) { //Logging LogPagSeguro::error("PagSeguroServiceException: " . $err->getMessage()); //Exception throw $err; } catch (Exception $err) { //Logging LogPagSeguro::error("Exception: " . $err->getMessage()); //Exception throw $err; } }
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; } }
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 = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildSearchUrlAbandoned($connectionData, $searchParams), $connectionData->getServiceTimeout(), $connectionData->getCharset()); self::$logService = "searchAbandoned"; return self::searchResult($connection, $initialDate, $finalDate); } catch (PagSeguroServiceException $err) { throw $err; } catch (Exception $err) { LogPagSeguro::error("Exception: " . $err->getMessage()); throw $err; } }
/** * @param PagSeguroCredentials $credentials * @param $reference * @param null $initialDate * @param null $finalDate * @param null $pageNumber * @param null $maxPageResults * @throws Exception * @throws PagSeguroServiceException */ public static function searchByReference(PagSeguroCredentials $credentials, $reference, $initialDate = null, $finalDate = null, $pageNumber = null, $maxPageResults = null) { LogPagSeguro::info("PagSeguroTransactionSearchService.SearchByReference(reference=" . $reference . ") - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); if ($initialDate) { $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); } else { $searchParams = null; } try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildSearchUrlByReference($connectionData, $reference, $searchParams), $connectionData->getServiceTimeout(), $connectionData->getCharset()); self::$logService = "SearchByReference"; return self::searchResult($connection); } catch (PagSeguroServiceException $err) { throw $err; } catch (Exception $err) { LogPagSeguro::error("Exception: " . $err->getMessage()); throw $err; } }
/** * Returns a pre approval from a notification code * @param PagSeguroCredentials $credentials * @param $notificationCode * @return bool|mixed|string * @throws Exception * @throws PagSeguroServiceException */ public static function checkPreApproval(PagSeguroCredentials $credentials, $notificationCode) { LogPagSeguro::info("PagSeguroNotificationService.CheckPreApproval(notificationCode={$notificationCode}) - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildPreApprovalNotificationUrl($connectionData, $notificationCode), $connectionData->getServiceTimeout(), $connectionData->getCharset()); self::$service = "CheckPreApproval"; return self::getResult($connection, $notificationCode); } catch (PagSeguroServiceException $err) { throw $err; } catch (Exception $err) { LogPagSeguro::error("Exception: " . $err->getMessage()); throw $err; } }