Exemple #1
0
 /**
  *
  * @param string $path
  * @param string $data
  * @param PayPal/Rest/ApiContext $apiContext
  * @param array $headers
  */
 public function execute($path, $method, $data = '', $apiContext, $headers = array())
 {
     $configMgr = \PPConfigManager::getInstance();
     $credential = $apiContext->getCredential();
     if ($credential == NULL) {
         // Try picking credentials from the config file
         $credMgr = \PPCredentialManager::getInstance();
         $credValues = $credMgr->getCredentialObject();
         if (!is_array($credValues)) {
             throw new \PPMissingCredentialException("Empty or invalid credentials passed");
         }
         $credential = new OAuthTokenCredential($credValues['clientId'], $credValues['clientSecret']);
     }
     if ($credential == NULL || !$credential instanceof OAuthTokenCredential) {
         throw new \PPInvalidCredentialException("Invalid credentials passed");
     }
     $resourceUrl = rtrim(trim($configMgr->get('service.EndPoint')), '/') . $path;
     $config = new \PPHttpConfig($resourceUrl, $method);
     $headers += array('Content-Type' => 'application/json', 'User-Agent' => UserAgent::getValue());
     if (!is_null($credential) && $credential instanceof OAuthTokenCredential) {
         $headers['Authorization'] = "Bearer " . $credential->getAccessToken();
     }
     if ($method == 'POST' || $method == 'PUT') {
         $headers['PayPal-Request-Id'] = $apiContext->getRequestId();
     }
     $config->setHeaders($headers);
     $connection = new \PPHttpConnection($config);
     $response = $connection->execute($data);
     $this->logger->fine($response);
     return $response;
 }
 public function testGetValue()
 {
     $ua = UserAgent::getValue();
     list($id, $version, $features) = sscanf($ua, "PayPalSDK/%s %s (%s)");
     // Check that we pass the useragent in the expected format
     $this->assertNotNull($id);
     $this->assertNotNull($version);
     $this->assertNotNull($features);
     // Check that we pass in these mininal features
     $this->assertThat($features, $this->stringContains("OS="));
     $this->assertThat($features, $this->stringContains("Bit="));
     $this->assertThat($features, $this->stringContains("Lang="));
     $this->assertThat($features, $this->stringContains("V="));
     $this->assertGreaterThan(5, count(explode(';', $features)));
 }