2 namespace PayPal\Handler;
3 use PayPal\Exception\PPConfigurationException;
4 use PayPal\Core\PPConstants;
5 class PPOpenIdHandler implements IPPHandler {
9 private static $sdkName = "openid-sdk-php";
10 private static $sdkVersion = "1.4.0";
12 public function __construct($apiContext) {
13 $this->apiContext = $apiContext;
16 public function handle($httpConfig, $request, $options) {
18 $config = $this->apiContext->getConfig();
20 rtrim(trim($this->_getEndpoint($config)), '/') .
21 (isset($options['path']) ? $options['path'] : '')
24 if(!array_key_exists("Authorization", $httpConfig->getHeaders())) {
25 $auth = base64_encode($config['acct1.ClientId'] . ':' . $config['acct1.ClientSecret']);
26 $httpConfig->addHeader("Authorization", "Basic $auth");
28 if(!array_key_exists("User-Agent", $httpConfig->getHeaders())) {
29 $httpConfig->addHeader("User-Agent", PPUserAgent::getValue(self::$sdkName, self::$sdkVersion));
33 private function _getEndpoint($config) {
34 if (isset($config['openid.EndPoint'])) {
35 return $config['openid.EndPoint'];
36 } else if (isset($config['service.EndPoint'])) {
37 return $config['service.EndPoint'];
38 } else if (isset($config['mode'])) {
39 switch (strtoupper($config['mode'])) {
41 return PPConstants::REST_SANDBOX_ENDPOINT;
43 return PPConstants::REST_LIVE_ENDPOINT;
45 throw new PPConfigurationException('The mode config parameter must be set to either sandbox/live');
48 throw new PPConfigurationException('You must set one of service.endpoint or mode parameters in your configuration');