PayPal\Transport\PayPalRestCall::execute PHP Method

execute() public method

public execute ( array $handlers = [], string $path, string $method, string $data = '', array $headers = [] ) : mixed
$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
return mixed
    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;
    }

Usage Example

Example #1
0
 /**
  * Extends the Payment object to create future payments
  *
  * @param null $apiContext
  * @param string|null  $clientMetadataId
  * @return $this
  */
 public function create($apiContext = null, $clientMetadataId = null)
 {
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $headers = array();
     if ($clientMetadataId != null) {
         $headers = array('PAYPAL-CLIENT-METADATA-ID' => $clientMetadataId);
     }
     $payLoad = $this->toJSON();
     $call = new PayPalRestCall($apiContext);
     $json = $call->execute(array('PayPal\\Handler\\RestHandler'), "/v1/payments/payment", "POST", $payLoad, $headers);
     $this->fromJson($json);
     return $this;
 }
All Usage Examples Of PayPal\Transport\PayPalRestCall::execute