Configurable Headers for All Requests to PayPal

- Allows adding additional headers to every call to PayPal APIs.
- Refactored OAuthTokenCredential to share code for making Rest Calls
- SDK Config to add headers with http.headers.* syntax
- Fixes #193
This commit is contained in:
japatel
2014-12-17 15:36:41 -06:00
parent 515b747223
commit 20038e7525
8 changed files with 170 additions and 52 deletions

View File

@@ -58,6 +58,26 @@ class ApiContext
return $this->credential;
}
public function getRequestHeaders()
{
$result = PPConfigManager::getInstance()->get('http.headers');
$headers = array();
foreach ($result as $header => $value) {
$headerName = ltrim($header, 'http.headers');
$headers[$headerName] = $value;
}
return $headers;
}
public function addRequestHeader($name, $value)
{
// Determine if the name already has a 'http.headers' prefix. If not, add one.
if (!(substr($name, 0, strlen('http.headers')) === 'http.headers')) {
$name = 'http.headers.' . $name;
}
PPConfigManager::getInstance()->addConfigs(array($name => $value));
}
/**
* Get Request ID
*