2 namespace PayPal\Handler;
3 use PayPal\Core\PPConstants;
4 use PayPal\Handler\PPGenericServiceHandler;
5 use PayPal\Exception\PPConfigurationException;
8 class PPPlatformServiceHandler extends PPGenericServiceHandler {
11 public function handle($httpConfig, $request, $options) {
12 parent::handle($httpConfig, $request, $options);
13 $this->config = $options['config'];
14 $credential = $request->getCredential();
15 //TODO: Assuming existence of getApplicationId
16 if($credential && $credential->getApplicationId() != NULL) {
17 $httpConfig->addHeader('X-PAYPAL-APPLICATION-ID', $credential->getApplicationId());
19 if($options['port'] != null && isset($this->config['service.EndPoint.'.$options['port']]))
21 $endpnt = 'service.EndPoint.'.$options['port'];
22 $this->endpoint = $this->config[$endpnt];
24 // for backward compatibilty (for those who are using old config files with 'service.EndPoint')
25 else if (isset($this->config['service.EndPoint']))
27 $this->endpoint = $this->config['service.EndPoint'];
29 else if (isset($this->config['mode']))
31 if(strtoupper($this->config['mode']) == 'SANDBOX')
33 $this->endpoint = PPConstants::PLATFORM_SANDBOX_ENDPOINT;
35 else if(strtoupper($this->config['mode']) == 'LIVE')
37 $this->endpoint = PPConstants::PLATFORM_LIVE_ENDPOINT;
42 throw new PPConfigurationException('endpoint Not Set');
44 $httpConfig->setUrl($this->endpoint . $options['serviceName'] . '/' . $options['apiMethod']);