Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
Added an ability to provide Curl Options in Configuration
Browse files Browse the repository at this point in the history
- Removed http.Retry, and http.ConnectionTimeout from configuration
- Added ability to provide Constant and its value in Configuration File
  • Loading branch information
japatel committed Jan 11, 2015
1 parent 810fe79 commit dd99971
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/PayPal/Auth/OAuthTokenCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function updateAccessToken($config, $refreshToken = null)
*/
private function getToken($config, $clientId, $clientSecret, $payload)
{
$httpConfig = new PayPalHttpConfig(null, 'POST');
$httpConfig = new PayPalHttpConfig(null, 'POST', $config);

$handlers = array(self::$AUTH_HANDLER);

Expand Down
2 changes: 0 additions & 2 deletions lib/PayPal/Core/PayPalConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class PayPalConfigManager
* @var array
*/
private $configs = array(
"http.ConnectionTimeOut" => "30",
"http.Retry" => "5",
);

/**
Expand Down
29 changes: 27 additions & 2 deletions lib/PayPal/Core/PayPalHttpConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] : '';
Expand Down Expand Up @@ -274,4 +275,28 @@ public function setUserAgent($userAgentString)
{
$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;
}
}
2 changes: 1 addition & 1 deletion lib/PayPal/Transport/PayPalRestCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function execute($handlers = array(), $path, $method, $data = '', $header
{

$config = $this->apiContext->getConfig();
$httpConfig = new PayPalHttpConfig(null, $method);
$httpConfig = new PayPalHttpConfig(null, $method, $config);
$headers = $headers ? $headers : array();
$httpConfig->setHeaders($headers +
array(
Expand Down
2 changes: 1 addition & 1 deletion sample/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ function getApiContext($clientId, $clientSecret)
$apiContext->setConfig(
array(
'mode' => 'sandbox',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => '../PayPal.log',
'log.LogLevel' => 'FINE',
'validation.level' => 'log',
'cache.enabled' => true,
// 'http.CURLOPT_CONNECTTIMEOUT' => 30
// 'http.headers.PayPal-Partner-Attribution-Id' => '123123123'
)
);
Expand Down
6 changes: 4 additions & 2 deletions sample/sdk_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ acct1.ClientSecret = EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRb

;Connection Information
[Http]
http.ConnectionTimeOut = 30
http.Retry = 1
; Add Curl Constants to be configured
; The settings provided in configurations would override defaults
; if provided in configurations
http.CURLOPT_CONNECTTIMEOUT = 30

; Adding HTTP Headers to each request sent to PayPal APIs
;http.headers.PayPal-Partner-Attribution-Id = 123123123
Expand Down

0 comments on commit dd99971

Please sign in to comment.