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; } }
/** * @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; } }
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; } }
public static function checkoutRequest(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()); return self::getResult($connection, $request); } catch (PagSeguroServiceException $error) { throw $error; } catch (Exception $error) { LogPagSeguro::error("Exception: " . $error->getMessage()); throw $error; } }
public static function createAuthorizationRequest(PagSeguroCredentials $credentials, PagSeguroAuthorizationRequest $authorizationRequest, $onlyAuthorizationCode) { LogPagSeguro::info("PagSeguroAuthorizationService.Register(" . $authorizationRequest->toString() . ") - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); try { $connection = new PagSeguroHttpConnection(); $connection->post(self::buildAuthorizationUrl($connectionData), PagSeguroAuthorizationParser::getData($authorizationRequest, $credentials), $connectionData->getServiceTimeout(), $connectionData->getCharset()); return self::authorizationReturn($connection, $authorizationRequest, $connectionData, $onlyAuthorizationCode); } catch (PagSeguroServiceException $err) { throw $err; } catch (Exception $err) { LogPagSeguro::error("Exception: " . $err->getMessage()); throw $err; } }
/** * @param PagSeguroCredentials $credentials * @param $transactionCode * @throws Exception * @throws PagSeguroServiceException */ public static function requestCancel(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()); return self::getResult($connection); } catch (PagSeguroServiceException $err) { throw $err; } catch (Exception $err) { LogPagSeguro::error("Exception: " . $err->getMessage()); throw $err; } }
public static function createPreApprovalRequest(PagSeguroCredentials $credentials, PagSeguroPaymentRequest $paymentRequest) { LogPagSeguro::info("PagSeguroPreApprovalService.createPreApprovalRequest(" . $paymentRequest->toString() . ") - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); $data = array_merge($connectionData->getCredentials()->getAttributesMap(), PagSeguroPreApprovalParser::getData($paymentRequest)); // On preApproval, credentials goes with data, not in the url query string try { $connection = new PagSeguroHttpConnection(); $connection->post(self::buildCheckoutRequestUrl($connectionData), $data, $connectionData->getServiceTimeout(), $connectionData->getCharset()); $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $PaymentParserData = PagSeguroPreApprovalParser::readSuccessXml($connection->getResponse()); $paymentReturn = array('code' => $PaymentParserData->getCode(), 'cancelUrl' => self::buildCancelUrl($connectionData, $PaymentParserData->getCode()), 'checkoutUrl' => self::buildCheckoutUrl($connectionData, $PaymentParserData->getCode())); LogPagSeguro::info("PagSeguroPreApprovalService.createPreApprovalRequest(" . $paymentRequest->toString() . ") - end {1}" . $PaymentParserData->getCode()); break; case 'BAD_REQUEST': $errors = PagSeguroPreApprovalParser::readErrors($connection->getResponse()); $e = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error("PagSeguroPreApprovalService.createPreApprovalRequest(" . $paymentRequest->toString() . ") - error " . $e->getOneLineMessage()); throw $e; break; default: $e = new PagSeguroServiceException($httpStatus); LogPagSeguro::error("PagSeguroPreApprovalService.createPreApprovalRequest(" . $paymentRequest->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 PagSeguroPreApprovalCharge $charge * @return null|PagSeguroParserData * @throws Exception * @throws PagSeguroServiceException */ public static function paymentCharge(PagSeguroCredentials $credentials, PagSeguroPreApprovalCharge $charge) { LogPagSeguro::info("PagSeguroPreApprovalService.PreApprovalPaymentCharge(" . $charge->toString() . ") - begin"); self::$connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); $data = array_merge(self::$connectionData->getCredentials()->getAttributesMap(), PagSeguroPreApprovalParser::getCharge($charge)); try { $connection = new PagSeguroHttpConnection(); $connection->post(self::buildPreApprovalPaymentUrl(self::$connectionData), $data, self::$connectionData->getServiceTimeout(), self::$connectionData->getCharset()); self::$service = "PreApprovalPaymentCharge"; return self::getResult($connection); } catch (PagSeguroServiceException $err) { //Logging LogPagSeguro::error("PagSeguroServiceException: " . $err->getMessage()); //Exception throw $err; } catch (Exception $err) { //Logging LogPagSeguro::error("Exception: " . $err->getMessage()); //Exception throw $err; } }