/** * @param PayPalHttpConfig $httpConfig * @param string $request * @param mixed $options * @return mixed|void * @throws PayPalConfigurationException * @throws PayPalInvalidCredentialException * @throws PayPalMissingCredentialException */ public function handle($httpConfig, $request, $options) { $config = $this->apiContext->getConfig(); $httpConfig->setUrl(rtrim(trim($this->_getEndpoint($config)), '/') . (isset($options['path']) ? $options['path'] : '')); $headers = array("User-Agent" => PayPalUserAgent::getValue(PayPalConstants::SDK_NAME, PayPalConstants::SDK_VERSION), "Authorization" => "Basic " . base64_encode($options['clientId'] . ":" . $options['clientSecret']), "Accept" => "*/*"); $httpConfig->setHeaders($headers); // Add any additional Headers that they may have provided $headers = $this->apiContext->getRequestHeaders(); foreach ($headers as $key => $value) { $httpConfig->addHeader($key, $value); } }
/** * @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; }