/**
  * @test
  */
 public function testSourceHeader()
 {
     $httpConfig = new PPHttpConfig();
     $handler = new PPGenericServiceHandler('sdkname', 'sdkversion');
     $handler->handle($httpConfig, new PPRequest(new StdClass(), 'NV'), array('config' => array()));
     $headers = $httpConfig->getHeaders();
     $this->assertArrayHasKey('X-PAYPAL-REQUEST-SOURCE', $headers);
     $this->assertRegExp('/.*sdkname.*/', $headers['X-PAYPAL-REQUEST-SOURCE']);
     $this->assertRegExp('/.*sdkversion.*/', $headers['X-PAYPAL-REQUEST-SOURCE']);
 }
 public function handle($httpConfig, $request, $options)
 {
     parent::handle($httpConfig, $request, $options);
     $this->config = $options['config'];
     $credential = $request->getCredential();
     //TODO: Assuming existence of getApplicationId
     if ($credential && $credential->getApplicationId() != NULL) {
         $httpConfig->addHeader('X-PAYPAL-APPLICATION-ID', $credential->getApplicationId());
     }
     if ($options['port'] != null && isset($this->config['service.EndPoint.' . $options['port']])) {
         $endpnt = 'service.EndPoint.' . $options['port'];
         $this->endpoint = $this->config[$endpnt];
     } else {
         if (isset($this->config['service.EndPoint'])) {
             $this->endpoint = $this->config['service.EndPoint'];
         } else {
             if (isset($this->config['mode'])) {
                 if (strtoupper($this->config['mode']) == 'SANDBOX') {
                     $this->endpoint = PPConstants::PLATFORM_SANDBOX_ENDPOINT;
                 } else {
                     if (strtoupper($this->config['mode']) == 'LIVE') {
                         $this->endpoint = PPConstants::PLATFORM_LIVE_ENDPOINT;
                     }
                 }
             } else {
                 throw new PPConfigurationException('endpoint Not Set');
             }
         }
     }
     $httpConfig->setUrl($this->endpoint . $options['serviceName'] . '/' . $options['apiMethod']);
 }
 public function handle($httpConfig, $request)
 {
     parent::handle($httpConfig, $request);
     if ($httpConfig->getHeader('X-PAYPAL-AUTHORIZATION')) {
         $httpConfig->addHeader('X-PP-AUTHORIZATION', $httpConfig->getHeader('X-PAYPAL-AUTHORIZATION'));
         $httpConfig->removeHeader('X-PAYPAL-AUTHORIZATION');
     }
     $request->addBindingInfo("namespace", "xmlns:ns=\"urn:ebay:api:PayPalAPI\" xmlns:ebl=\"urn:ebay:apis:eBLBaseComponents\" xmlns:cc=\"urn:ebay:apis:CoreComponentTypes\" xmlns:ed=\"urn:ebay:apis:EnhancedDataTypes\"");
 }
 public function handle($httpConfig, $request)
 {
     parent::handle($httpConfig, $request);
     $credential = $request->getCredential();
     //TODO: Assuming existence of getApplicationId
     if ($credential && $credential->getApplicationId() != NULL) {
         $httpConfig->addHeader('X-PAYPAL-APPLICATION-ID', $credential->getApplicationId());
     }
 }
 public function handle($httpConfig, $request, $options)
 {
     parent::handle($httpConfig, $request, $options);
     $config = $options['config'];
     if (is_string($this->apiUsername) || is_null($this->apiUsername)) {
         // $apiUsername is optional, if null the default account in config file is taken
         $credMgr = PPCredentialManager::getInstance($options['config']);
         $request->setCredential(clone $credMgr->getCredentialObject($this->apiUsername));
     } else {
         $request->setCredential($this->apiUsername);
     }
     $endpoint = '';
     $credential = $request->getCredential();
     if (isset($options['port']) && isset($config['service.EndPoint.' . $options['port']])) {
         $endpoint = $config['service.EndPoint.' . $options['port']];
     } else {
         if (isset($config['service.EndPoint'])) {
             $endpoint = $config['service.EndPoint'];
         } else {
             if (isset($config['mode'])) {
                 if (strtoupper($config['mode']) == 'SANDBOX') {
                     if ($credential instanceof PPSignatureCredential) {
                         $endpoint = PPConstants::MERCHANT_SANDBOX_SIGNATURE_ENDPOINT;
                     } else {
                         if ($credential instanceof PPCertificateCredential) {
                             $endpoint = PPConstants::MERCHANT_SANDBOX_CERT_ENDPOINT;
                         }
                     }
                 } else {
                     if (strtoupper($config['mode']) == 'LIVE') {
                         if ($credential instanceof PPSignatureCredential) {
                             $endpoint = PPConstants::MERCHANT_LIVE_SIGNATURE_ENDPOINT;
                         } else {
                             if ($credential instanceof PPCertificateCredential) {
                                 $endpoint = PPConstants::MERCHANT_LIVE_CERT_ENDPOINT;
                             }
                         }
                     }
                 }
             } else {
                 throw new PPConfigurationException('endpoint Not Set');
             }
         }
     }
     if ($request->getBindingType() == 'SOAP') {
         $httpConfig->setUrl($endpoint);
     } else {
         throw new PPConfigurationException('expecting service binding to be SOAP');
     }
     $request->addBindingInfo("namespace", "xmlns:ns=\"urn:ebay:api:PayPalAPI\" xmlns:ebl=\"urn:ebay:apis:eBLBaseComponents\" xmlns:cc=\"urn:ebay:apis:CoreComponentTypes\" xmlns:ed=\"urn:ebay:apis:EnhancedDataTypes\"");
     // Call the authentication handler to tack authentication related info
     $handler = new PPAuthenticationHandler();
     $handler->handle($httpConfig, $request, $options);
 }
 public function handle($httpConfig, $request, $options)
 {
     parent::handle($httpConfig, $request, $options);
     $this->config = $options['config'];
     $credential = $request->getCredential();
     if ($options['port'] != null && isset($this->config['service.EndPoint.' . $options['port']])) {
         $this->endpoint = $this->config['service.EndPoint.' . $options['port']];
     } else {
         if (isset($this->config['service.EndPoint'])) {
             $this->endpoint = $this->config['service.EndPoint'];
         } else {
             if (isset($this->config['mode'])) {
                 if (strtoupper($this->config['mode']) == 'SANDBOX') {
                     if ($credential instanceof PPSignatureCredential) {
                         $this->endpoint = PPConstants::MERCHANT_SANDBOX_SIGNATURE_ENDPOINT;
                     } else {
                         if ($credential instanceof PPCertificateCredential) {
                             $this->endpoint = PPConstants::MERCHANT_SANDBOX_CERT_ENDPOINT;
                         }
                     }
                 } else {
                     if (strtoupper($this->config['mode']) == 'LIVE') {
                         if ($credential instanceof PPSignatureCredential) {
                             $this->endpoint = PPConstants::MERCHANT_LIVE_SIGNATURE_ENDPOINT;
                         } else {
                             if ($credential instanceof PPCertificateCredential) {
                                 $this->endpoint = PPConstants::MERCHANT_LIVE_CERT_ENDPOINT;
                             }
                         }
                     }
                 }
             } else {
                 throw new PPConfigurationException('endpoint Not Set');
             }
         }
     }
     if ($options['serviceBinding'] == 'SOAP') {
         $httpConfig->setUrl($this->endpoint);
     } else {
         throw new PPConfigurationException('expecting service binding to be SOAP');
     }
     $request->addBindingInfo("namespace", "xmlns:ns=\"urn:ebay:api:PayPalAPI\" xmlns:ebl=\"urn:ebay:apis:eBLBaseComponents\" xmlns:cc=\"urn:ebay:apis:CoreComponentTypes\" xmlns:ed=\"urn:ebay:apis:EnhancedDataTypes\"");
 }
 public function handle($httpConfig, $request, $options)
 {
     parent::handle($httpConfig, $request, $options);
     if (is_string($this->apiUsername) || is_null($this->apiUsername)) {
         // $apiUsername is optional, if null the default account in config file is taken
         $credMgr = PPCredentialManager::getInstance($options['config']);
         $request->setCredential(clone $credMgr->getCredentialObject($this->apiUsername));
     } else {
         $request->setCredential($this->apiUsername);
     }
     $config = $options['config'];
     $credential = $request->getCredential();
     //TODO: Assuming existence of getApplicationId
     if ($credential && $credential->getApplicationId() != NULL) {
         $httpConfig->addHeader('X-PAYPAL-APPLICATION-ID', $credential->getApplicationId());
     }
     if (isset($config['port']) && isset($config['service.EndPoint.' . $options['port']])) {
         $endpoint = $config['service.EndPoint.' . $options['port']];
     } else {
         if (isset($config['service.EndPoint'])) {
             $endpoint = $config['service.EndPoint'];
         } else {
             if (isset($config['mode'])) {
                 if (strtoupper($config['mode']) == 'SANDBOX') {
                     $endpoint = PPConstants::PLATFORM_SANDBOX_ENDPOINT;
                 } else {
                     if (strtoupper($config['mode']) == 'LIVE') {
                         $endpoint = PPConstants::PLATFORM_LIVE_ENDPOINT;
                     }
                 }
             } else {
                 throw new PPConfigurationException('endpoint Not Set');
             }
         }
     }
     $httpConfig->setUrl($endpoint . $options['serviceName'] . '/' . $options['apiMethod']);
     // Call the authentication handler to tack authentication related info
     $handler = new PPAuthenticationHandler();
     $handler->handle($httpConfig, $request, $options);
 }