forked from LiveCarta/PayPal-PHP-SDK
Added an ability to provide Curl Options in Configuration
- Removed http.Retry, and http.ConnectionTimeout from configuration - Added ability to provide Constant and its value in Configuration File
This commit is contained in:
@@ -204,7 +204,7 @@ class OAuthTokenCredential extends PayPalResourceModel
|
||||
*/
|
||||
private function getToken($config, $clientId, $clientSecret, $payload)
|
||||
{
|
||||
$httpConfig = new PayPalHttpConfig(null, 'POST');
|
||||
$httpConfig = new PayPalHttpConfig(null, 'POST', $config);
|
||||
|
||||
$handlers = array(self::$AUTH_HANDLER);
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ class PayPalConfigManager
|
||||
* @var array
|
||||
*/
|
||||
private $configs = array(
|
||||
"http.ConnectionTimeOut" => "30",
|
||||
"http.Retry" => "5",
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,12 +54,13 @@ class PayPalHttpConfig
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $method HTTP method (GET, POST etc) defaults to POST
|
||||
* @param array $configs All Configurations
|
||||
*/
|
||||
public function __construct($url = null, $method = self::HTTP_POST)
|
||||
public function __construct($url = null, $method = self::HTTP_POST, $configs = array())
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->method = $method;
|
||||
$this->curlOptions = self::$defaultCurlOptions;
|
||||
$this->curlOptions = $this->getHttpConstantsFromConfigs($configs, 'http.') + self::$defaultCurlOptions;
|
||||
// Update the Cipher List based on OpenSSL or NSS settings
|
||||
$curl = curl_version();
|
||||
$sslVersion = isset($curl['ssl_version']) ? $curl['ssl_version'] : '';
|
||||
@@ -274,4 +275,28 @@ class PayPalHttpConfig
|
||||
{
|
||||
$this->curlOptions[CURLOPT_USERAGENT] = $userAgentString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an array of constant key, and value based on Prefix
|
||||
*
|
||||
* @param array $configs
|
||||
* @param $prefix
|
||||
* @return array
|
||||
*/
|
||||
public function getHttpConstantsFromConfigs($configs = array(), $prefix)
|
||||
{
|
||||
$arr = array();
|
||||
if ($prefix != null && is_array($configs)) {
|
||||
foreach ($configs as $k => $v) {
|
||||
// Check if it startsWith
|
||||
if (substr($k, 0, strlen($prefix)) === $prefix) {
|
||||
$newKey = ltrim($k, $prefix);
|
||||
if (defined($newKey)) {
|
||||
$arr[constant($newKey)] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class PayPalRestCall
|
||||
{
|
||||
|
||||
$config = $this->apiContext->getConfig();
|
||||
$httpConfig = new PayPalHttpConfig(null, $method);
|
||||
$httpConfig = new PayPalHttpConfig(null, $method, $config);
|
||||
$headers = $headers ? $headers : array();
|
||||
$httpConfig->setHeaders($headers +
|
||||
array(
|
||||
|
||||
Reference in New Issue
Block a user