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; } }
/** * Returns a transaction from a notification code * * @param Credentials $credentials * @param String $notificationCode * @throws PagSeguroServiceException * @throws Exception * @return a transaction * @see Transaction */ public static function checkTransaction(Credentials $credentials, $notificationCode) { LogPagSeguro::info("NotificationService.CheckTransaction(notificationCode={$notificationCode}) - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::serviceName); try { $connection = new HttpConnection(); $connection->get(self::buildTransactionNotificationUrl($connectionData, $notificationCode), $connectionData->getServiceTimeout(), $connectionData->getCharset()); $httpStatus = new HttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': // parses the transaction $transaction = TransactionParser::readTransaction($connection->getResponse()); LogPagSeguro::info("NotificationService.CheckTransaction(notificationCode={$notificationCode}) - end " . $transaction->toString() . ")"); break; case 'BAD_REQUEST': $errors = TransactionParser::readErrors($connection->getResponse()); $e = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::info("NotificationService.CheckTransaction(notificationCode={$notificationCode}) - error " . $e->getOneLineMessage()); throw $e; break; default: $e = new PagSeguroServiceException($httpStatus); LogPagSeguro::info("NotificationService.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; } }
/** * Search transactions abandoned associated with this set of credentials within a date range * * @param Credentials $credentials * @param String $initialDate * @param String $finalDate * @param integer $pageNumber * @param integer $maxPageResults * @return a object of TransactionSerachResult class * @see TransactionSearchResult * @throws PagSeguroServiceException * @throws Exception */ public static function searchAbandoned(Credentials $credentials, $initialDate, $finalDate, $pageNumber, $maxPageResults) { LogPagSeguro::info("TransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::serviceName); $searchParams = array('initialDate' => PagSeguroHelper::formatDate($initialDate), 'finalDate' => PagSeguroHelper::formatDate($finalDate), 'pageNumber' => $pageNumber, 'maxPageResults' => $maxPageResults); try { $connection = new HttpConnection(); $connection->get(self::buildSearchUrlAbandoned($connectionData, $searchParams), $connectionData->getServiceTimeout(), $connectionData->getCharset()); $httpStatus = new HttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $searchResult = TransactionParser::readSearchResult($connection->getResponse()); LogPagSeguro::info("TransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $searchResult->toString()); break; case 'BAD_REQUEST': $errors = TransactionParser::readErrors($connection->getResponse()); $e = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error("TransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $e->getOneLineMessage()); throw $e; break; default: $e = new PagSeguroServiceException($httpStatus); LogPagSeguro::error("TransactionSearchService.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; } }