예제 #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;
 }
예제 #2
0
 /**
  * @param array $handlers array of handlers
  * @param string $path   Resource path relative to base service endpoint
  * @param string $method HTTP method - one of GET, POST, PUT, DELETE, PATCH etc
  * @param string $data   Request payload
  * @param array $headers HTTP headers
  */
 public function execute($handlers, $path, $method, $data = '', $headers = array())
 {
     $config = $this->apiContext->getConfig();
     $httpConfig = new PPHttpConfig(null, $method);
     $httpConfig->setHeaders($headers + array('Content-Type' => 'application/json'));
     foreach ($handlers as $handler) {
         $handler->handle($httpConfig, $data, array('path' => $path, 'apiContext' => $this->apiContext));
     }
     $connection = new PPHttpConnection($httpConfig, $config);
     $response = $connection->execute($data);
     $this->logger->fine($response);
     return $response;
 }
예제 #3
0
 /**
  * This function returns a new PPHttpConnection object
  */
 public function getConnection()
 {
     $connection = new PPHttpConnection();
     $configMgr = PPConfigManager::getInstance();
     if ($configMgr->get("http.ConnectionTimeOut")) {
         $connection->setHttpTimeout($configMgr->get("http.ConnectionTimeOut"));
     }
     if ($configMgr->get("http.Proxy")) {
         $connection->setHttpProxy($configMgr->get("http.Proxy"));
     }
     if ($configMgr->get("http.Retry")) {
         $retry = $configMgr->get("http.Retry");
         $connection->setHttpRetry($retry);
     }
     return $connection;
 }