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; } }
/** * 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 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; }
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; } }
/** * @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; } }
/** * 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; } }
/** * @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 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 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; }