PayPal\Transport\PPRestCall::execute PHP Method

execute() public method

public execute ( array $handlers, string $path, string $method, string $data = '', array $headers = [] )
$handlers array array of handlers
$path string Resource path relative to base service endpoint
$method string HTTP method - one of GET, POST, PUT, DELETE, PATCH etc
$data string Request payload
$headers array 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) {
            if (!is_object($handler)) {
                $shandler = "\\" . $handler;
                $handler = new $shandler($this->apiContext);
            }
            $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;
    }

Usage Example

 /**
  * returns user details
  *
  * @path /v1/identity/openidconnect/userinfo
  * @method GET
  * @param array $params (allowed values are access_token)
  * 					access_token - access token from the createFromAuthorizationCode / createFromRefreshToken calls  
  * @param PPApiContext $apiContext Optional API Context
  * @return PPOpenIdUserinfo
  */
 public static function getUserinfo($params, $apiContext = null)
 {
     static $allowedParams = array('schema' => 1);
     if (is_null($apiContext)) {
         $apiContext = new PPApiContext();
     }
     if (!array_key_exists('schema', $params)) {
         $params['schema'] = 'openid';
     }
     $requestUrl = "/v1/identity/openidconnect/userinfo?" . http_build_query(array_intersect_key($params, $allowedParams));
     $call = new PPRestCall($apiContext);
     $ret = new PPOpenIdUserinfo();
     $ret->fromJson($call->execute(array(new PPOpenIdHandler($apiContext)), $requestUrl, "GET", "", array('Authorization' => "Bearer " . $params['access_token'], 'Content-Type' => 'x-www-form-urlencoded')));
     return $ret;
 }
All Usage Examples Of PayPal\Transport\PPRestCall::execute