private function curlConnection($method, $url, $timeout, $charset, array $data = null) { if (Tools::strtoupper($method) === 'POST') { $postFields = $data ? http_build_query($data, '', '&') : ""; $contentLength = "Content-length: " . Tools::strlen($postFields); $methodOptions = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postFields); } else { $contentLength = null; $methodOptions = array(CURLOPT_HTTPGET => true); } $options = array(CURLOPT_HTTPHEADER => array("Content-Type: application/x-www-form-urlencoded; charset=" . $charset, $contentLength, 'lib-description: php:' . PagSeguroLibrary::getVersion(), 'language-engine-description: php:' . PagSeguroLibrary::getPHPVersion()), CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CONNECTTIMEOUT => $timeout); if (!is_null(PagSeguroLibrary::getModuleVersion())) { array_push($options[CURLOPT_HTTPHEADER], 'module-description: ' . PagSeguroLibrary::getModuleVersion()); } if (!is_null(PagSeguroLibrary::getCMSVersion())) { array_push($options[CURLOPT_HTTPHEADER], 'cms-description: ' . PagSeguroLibrary::getCMSVersion()); } $options = $options + $methodOptions; $curl = curl_init(); curl_setopt_array($curl, $options); $resp = curl_exec($curl); $info = curl_getinfo($curl); $error = curl_errno($curl); $errorMessage = curl_error($curl); curl_close($curl); $this->setStatus((int) $info['http_code']); $this->setResponse((string) $resp); if ($error) { throw new Exception("CURL can't connect: {$errorMessage}"); } else { return true; } }
public function install() { if (version_compare(PagSeguroLibrary::getVersion(), '2.1.8', '<=')) { if (!$this->validatePagSeguroRequirements()) { return false; } } if (!$this->validatePagSeguroId()) { return false; } if (!$this->validateOrderMessage()) { return false; } if (!$this->generatePagSeguroOrderStatus()) { return false; } if (!$this->createTables()) { return false; } if (!$this->modulo->installConfiguration()) { return false; } if (!parent::install() or !$this->registerHook('payment') or !$this->registerHook('paymentReturn') or !Configuration::updateValue('PAGSEGURO_EMAIL', '') or !Configuration::updateValue('PAGSEGURO_TOKEN', '') or !Configuration::updateValue('PAGSEGURO_URL_REDIRECT', '') or !Configuration::updateValue('PAGSEGURO_NOTIFICATION_URL', '') or !Configuration::updateValue('PAGSEGURO_CHARSET', PagSeguroConfig::getData('application', 'charset')) or !Configuration::updateValue('PAGSEGURO_LOG_ACTIVE', PagSeguroConfig::getData('log', 'active')) or !Configuration::updateValue('PAGSEGURO_RECOVERY_ACTIVE', false) or !Configuration::updateValue('PAGSEGURO_DAYS_RECOVERY', 1) or !Configuration::updateValue('PAGSEGURO_CHECKOUT', false) or !Configuration::updateValue('PAGSEGURO_LOG_FILELOCATION', PagSeguroConfig::getData('log', 'fileLocation'))) { return false; } return true; }