Requires the PHP curl module to be enabled. See for full requirements the PHP manual: http://php.net/curl
Exemplo n.º 1
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
  * @return mixed
  * @throws \PayPal\Exception\PayPalConnectionException
  */
 public function execute($handlers = array(), $path, $method, $data = '', $headers = array())
 {
     $config = $this->apiContext->getConfig();
     $httpConfig = new PayPalHttpConfig(null, $method, $config);
     $headers = $headers ? $headers : array();
     $httpConfig->setHeaders($headers + array('Content-Type' => 'application/json'));
     /** @var \Paypal\Handler\IPayPalHandler $handler */
     foreach ($handlers as $handler) {
         if (!is_object($handler)) {
             $fullHandler = "\\" . (string) $handler;
             $handler = new $fullHandler($this->apiContext);
         }
         $handler->handle($httpConfig, $data, array('path' => $path, 'apiContext' => $this->apiContext));
     }
     $connection = new PayPalHttpConnection($httpConfig, $config);
     $response = $connection->execute($data);
     return $response;
 }
 /**
  * Retrieves the token based on the input configuration
  *
  * @param array $config
  * @param string $clientId
  * @param string $clientSecret
  * @param string $payload
  * @return mixed
  * @throws PayPalConfigurationException
  * @throws \PayPal\Exception\PayPalConnectionException
  */
 protected function getToken($config, $clientId, $clientSecret, $payload)
 {
     $httpConfig = new PayPalHttpConfig(null, 'POST', $config);
     $handlers = array(self::$AUTH_HANDLER);
     /** @var IPayPalHandler $handler */
     foreach ($handlers as $handler) {
         if (!is_object($handler)) {
             $fullHandler = "\\" . (string) $handler;
             $handler = new $fullHandler(new ApiContext($this));
         }
         $handler->handle($httpConfig, $payload, array('clientId' => $clientId, 'clientSecret' => $clientSecret));
     }
     $connection = new PayPalHttpConnection($httpConfig, $config);
     $res = $connection->execute($payload);
     $response = json_decode($res, true);
     return $response;
 }