This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
<?php
|
||||
|
||||
class PayPalConnect extends Paypal
|
||||
{
|
||||
private $_logs = array();
|
||||
|
||||
public function makeConnection($host, $script, $body, $simple_mode = false)
|
||||
{
|
||||
$this->_logs[] = $this->l('Making new connection to').' \''.$host.$script.'\'';
|
||||
if (function_exists('curl_exec'))
|
||||
$return = $this->_connectByCURL($host.$script, $body);
|
||||
if (isset($return) AND $return)
|
||||
return $return;
|
||||
$tmp = $this->_connectByFSOCK($host, $script, $body);
|
||||
if (!$simple_mode || !preg_match('/[A-Z]+=/', $tmp, $result))
|
||||
return $tmp;
|
||||
$pos = strpos($tmp, $result[0]);
|
||||
$body = substr($tmp, $pos);
|
||||
return $body;
|
||||
}
|
||||
|
||||
public function getLogs()
|
||||
{
|
||||
return $this->_logs;
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
/********************** CONNECT METHODS **********************/
|
||||
/************************************************************/
|
||||
|
||||
private function _connectByCURL($url, $body)
|
||||
{
|
||||
$ch = @curl_init();
|
||||
if (!$ch)
|
||||
$this->_logs[] = $this->l('Connect failed with CURL method');
|
||||
else
|
||||
{
|
||||
$this->_logs[] = $this->l('Connect with CURL method successful');
|
||||
$this->_logs[] = '<b>'.$this->l('Sending this params:').'</b>';
|
||||
$this->_logs[] = $body;
|
||||
@curl_setopt($ch, CURLOPT_URL, 'https://'.$url);
|
||||
@curl_setopt($ch, CURLOPT_POST, true);
|
||||
@curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
@curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
@curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
@curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||
$result = @curl_exec($ch);
|
||||
if (!$result)
|
||||
$this->_logs[] = $this->l('Send with CURL method failed ! Error:').' '.curl_error($ch);
|
||||
else
|
||||
$this->_logs[] = $this->l('Send with CURL method successful');
|
||||
@curl_close($ch);
|
||||
}
|
||||
return (isset($result) ? $result : false);
|
||||
}
|
||||
|
||||
private function _connectByFSOCK($host, $script, $body)
|
||||
{
|
||||
$fp = @fsockopen('ssl://'.$host, 443, $errno, $errstr, 4);
|
||||
if (!$fp)
|
||||
$this->_logs[] = $this->l('Connect failed with fsockopen method');
|
||||
else
|
||||
{
|
||||
$header = $this->_makeHeader($host, $script, strlen($body));
|
||||
$this->_logs[] = $this->l('Connect with fsockopen method successful');
|
||||
$this->_logs[] = $this->l('Sending this params:').' '.$header.$body;
|
||||
@fputs($fp, $header.$body);
|
||||
$tmp = '';
|
||||
while (!feof($fp))
|
||||
$tmp .= trim(fgets($fp, 1024));
|
||||
fclose($fp);
|
||||
$result = $tmp;
|
||||
if (!$result)
|
||||
$this->_logs[] = $this->l('Send with fsockopen method failed !');
|
||||
else
|
||||
$this->_logs[] = $this->l('Send with fsockopen method successful');
|
||||
}
|
||||
return (isset($result) ? $result : false);
|
||||
}
|
||||
|
||||
private function _makeHeader($host, $script, $lenght)
|
||||
{
|
||||
$header = 'POST '.strval($script).' HTTP/1.0'."\r\n" .
|
||||
'Host: '.strval($host)."\r\n".
|
||||
'Content-Type: application/x-www-form-urlencoded'."\r\n".
|
||||
'Content-Length: '.(int)($lenght)."\r\n".
|
||||
'Connection: close'."\r\n\r\n";
|
||||
return $header;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
define('PAYPAL_API_VERSION', '60.0');
|
||||
|
||||
class PaypalLib extends Paypal
|
||||
{
|
||||
private $_logs = array();
|
||||
|
||||
public function getLogs()
|
||||
{
|
||||
return $this->_logs;
|
||||
}
|
||||
|
||||
public function makeCall($host, $script, $methodName, $string)
|
||||
{
|
||||
// Making request string
|
||||
$request = 'METHOD='.urlencode($methodName).'&VERSION='.urlencode(PAYPAL_API_VERSION);
|
||||
$request .= '&PWD='.urlencode(Configuration::get('PAYPAL_API_PASSWORD')).'&USER='.urlencode(Configuration::get('PAYPAL_API_USER'));
|
||||
$request .= '&SIGNATURE='.urlencode(Configuration::get('PAYPAL_API_SIGNATURE')).$string;
|
||||
|
||||
// Making connection
|
||||
include_once(_PS_MODULE_DIR_.'paypal/api/paypalconnect.php');
|
||||
$ppConnect = new PaypalConnect();
|
||||
$result = $ppConnect->makeConnection($host, $script, $request, true);
|
||||
$this->_logs = $ppConnect->getLogs();
|
||||
|
||||
// Formating response value
|
||||
$response = explode('&', $result);
|
||||
foreach ($response as $k => $res)
|
||||
{
|
||||
$tmp = explode('=', $res);
|
||||
if (!isset($tmp[1]))
|
||||
$response[$tmp[0]] = urldecode($tmp[0]);
|
||||
else
|
||||
{
|
||||
$response[$tmp[0]] = urldecode($tmp[1]);
|
||||
unset($response[$k]);
|
||||
}
|
||||
}
|
||||
if (!Configuration::get('PAYPAL_MODE_DEBUG'))
|
||||
$this->_logs = array();
|
||||
$toExclude = array('TOKEN', 'SUCCESSPAGEREDIRECTREQUESTED', 'VERSION', 'BUILD', 'ACK', 'CORRELATIONID');
|
||||
$this->_logs[] = '<b>'.$this->l('PayPal response:').'</b>';
|
||||
foreach ($response as $k => $res)
|
||||
{
|
||||
if (!Configuration::get('PAYPAL_MODE_DEBUG') AND in_array($k, $toExclude))
|
||||
continue;
|
||||
$this->_logs[] = $k.' -> '.$res;
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function makeSimpleCall($host, $script, $request)
|
||||
{
|
||||
// Making connection
|
||||
include_once(_PS_MODULE_DIR_.'paypal/api/paypalconnect.php');
|
||||
$ppConnect = new PaypalConnect();
|
||||
$result = $ppConnect->makeConnection($host, $script, $request);
|
||||
$this->_logs = $ppConnect->getLogs();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user