public static function createCheckoutRequest(PagSeguroCredentials $credentials, PagSeguroPaymentRequest $paymentRequest) { LogPagSeguro::info("PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::serviceName); try { $connection = new PagSeguroHttpConnection(); $connection->post(self::buildCheckoutRequestUrl($connectionData), PagSeguroPaymentParser::getData($paymentRequest), $connectionData->getServiceTimeout(), $connectionData->getCharset()); $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $PaymentParserData = PagSeguroPaymentParser::readSuccessXml($connection->getResponse()); $paymentUrl = self::buildCheckoutUrl($connectionData, $PaymentParserData->getCode()); LogPagSeguro::info("PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - end {1}" . $PaymentParserData->getCode()); break; case 'BAD_REQUEST': $errors = PagSeguroPaymentParser::readErrors($connection->getResponse()); $e = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error("PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . $e->getOneLineMessage()); throw $e; break; default: $e = new PagSeguroServiceException($httpStatus); LogPagSeguro::error("PagSeguroPaymentService.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; } }