7b3c50ee16286e1a673f2204ee6c2b596d8f3577
[WP-Plugins/glm-member-db.git] /
1 <?php
2 namespace PayPal\Handler;
3 use PayPal\Core\PPConstants;
4 use PayPal\Handler\PPGenericServiceHandler;
5 use PayPal\Exception\PPConfigurationException;
6
7
8 class PPPlatformServiceHandler extends PPGenericServiceHandler {
9         private $endpoint;
10         private $config;
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());
18                 }
19                 if($options['port'] != null && isset($this->config['service.EndPoint.'.$options['port']]))
20                 {
21                         $endpnt = 'service.EndPoint.'.$options['port']; 
22                         $this->endpoint = $this->config[$endpnt];
23                 }
24                 // for backward compatibilty (for those who are using old config files with 'service.EndPoint')
25                 else if (isset($this->config['service.EndPoint']))
26                 {
27                         $this->endpoint = $this->config['service.EndPoint'];
28                 }
29                 else if (isset($this->config['mode']))
30                 {
31                         if(strtoupper($this->config['mode']) == 'SANDBOX')
32                         {
33                                 $this->endpoint = PPConstants::PLATFORM_SANDBOX_ENDPOINT;
34                         }
35                         else if(strtoupper($this->config['mode']) == 'LIVE')
36                         {
37                                 $this->endpoint = PPConstants::PLATFORM_LIVE_ENDPOINT;
38                         }
39                 }
40                 else
41                 {
42                         throw new PPConfigurationException('endpoint Not Set');
43                 }
44                 $httpConfig->setUrl($this->endpoint . $options['serviceName'] . '/' .  $options['apiMethod']);
45         
46         }
47 }