Create request payload to be sent to PayPal.

@param string $method
493044
private function createRequestPayload($method)
    {
        $this->apiUrl = $this->config['api_url'].'/'.$method;

        $this->post = $this->post->merge($this->options);
    }
878746
private function createRequest($method, array $payload)
    {
        // Override the endpoint for this payload.
        if (!is_null($this->endpoint)) {
            $token = $payload['token'];
            unset($payload['token']);

            // Convert payload back to an array.
            foreach ($payload as &$value) {
                $value = json_decode($value);
            }

            // Encode payload.
            $payload = json_encode($payload, JSON_UNESCAPED_UNICODE);

            return new Request(
                'POST',
                $this->endpoint,
                ['Content-Type' => 'application/json'],
                $payload
            );
        }

        return new Request(
            'POST',
            self::API_BASE_URL . $method,
            ['Content-Type' => 'application/x-www-form-urlencoded'],
            http_build_query($payload)
        );
    }
845207
protected function createRequest($method, $payload = [])
    {
        $this->setMockResponses();
        $this->setupHttpClientSettings();

        $this->request = $this->httpClient->createRequest($method, $this->environment, ['json' => $payload]);

        $this->setRequestFullPath();
        $this->setRequestQueryString();

        return $this->send();
    }
264016
protected function configureHTTPMethod($method) {
        switch($method){
            case self::HTTP_GET:
                $this->removeHeader('Content-Type');
                break;
            case self::HTTP_POST:
            case self::HTTP_PUT:
                $this->addHeader("Content-Type", "multipart/form-data");
        }
        return parent::configureHTTPMethod($method);
    }
315421
private function doPayPalRequest($method)
    {
        // Setup PayPal API Request Payload
        $this->createRequestPayload($method);

        try {
            $response = $this->makeHttpRequest();

            return \GuzzleHttp\json_decode($response, true);
        } catch (\Exception $e) {
            $message = $e->getMessage();
        }

        return [
            'type'    => 'error',
            'message' => $message,
        ];
    }
759760
protected static function executeCall(
        $method,
        $payLoad,
        $headers = array(),
        $apiContext = null,
        $soapCall = null,
        $handlers = array('PayU\Handler\BasicAuthHandler'),
        $path = ''
    )
    {
        //Initialize the context and rest call object if not provided explicitly
        $apiContext = $apiContext ? $apiContext : new ApiContext(self::$credential);
        self::$apiContext = $apiContext;
        $soapCall = $soapCall ? $soapCall : new SoapCall($apiContext);

        //Make the execution call
        $json = $soapCall->execute($method, $payLoad, $handlers, $headers, $path);
        return $json;
    }
1192955
private function buildRequestParams($method, $parameters = array()) {

        switch ($this->mode) {
            case 'client':
                $parameters['email'] = $this->email;
                $parameters['tkn']   = $this->token;
                $parameters['a']     = $method;
                break;
            case 'host':
                $parameters['host_key'] = $this->host_key;
                $parameters['act']      = $method;
                break;
        }


        return $parameters;
    }
151398
public function createRequest(string $method, string $url, $body=null, array $headers=[])
  {
    # Merge Default Headers with user provided headers
    $headers = array_merge(
      [
         'Accept'          => '*/*',
         'Accept-Encoding' => 'gzip, deflate'
      ],
      $headers
    );

    # Create the httpRequest
    $this->httpRequest = new \GuzzleHttp\Psr7\Request( $method, $url, $headers, $body );

    return $this->httpRequest;
  }
755050
public function request($method, $api_method, $body = NULL, $checksum)
    {
        /**
         * Check if the Merchant ID is set
         */
        if (empty($this->api_key)) {
            throw new \Exception("Please configure your ICEPAY Merchant ID.");
        }

        /**
         * Check if the Secret Code is set
         */
        if (empty($this->api_secret)) {
            throw new \Exception("Please configure your ICEPAY Secret Code.");
        }

        /**
         * Check if the CompletedURL is set
         */
        if (empty($this->api_completed_url)) {
            throw new \Exception("Please configure your setCompletedURL()");
        }

        /**
         * Check if the ErrorURL is set
         */
        if (empty($this->api_error_url)) {
            throw new \Exception("Please configure your setErrorURL()");
        }

        /**
         * Start a curl session
         */
        if (empty($this->ch) || !function_exists("curl_reset")) {
            $this->ch = curl_init();
        } else {
            curl_reset($this->ch);
        }

        /**
         * Set the curl options
         */
        curl_setopt($this->ch, CURLOPT_URL, $this->api_endpoint . $api_method);
        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($this->ch, CURLOPT_TIMEOUT, 15);
        curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($this->ch, CURLOPT_HEADER, TRUE);

        /**
         * Possible output: 5.6.9
         */
        $php_version = phpversion();

        /**
         * Prepare the curl headers
         */
        $api_headers = array(
            "MerchantID: {$this->api_key}",
            "Checksum: {$checksum}",
            "User-Agent: ICEPAY API/{$this->api_version} PHP/{$php_version}",
            "Accept: application/json"
        );

        /**
         * If the body is not null, let curl post the request as json content
         */
        if ($body !== NULL) {
            $api_headers[] = "Content-Type: application/json";

            curl_setopt($this->ch, CURLOPT_POST, 1);
            curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($body));
        }

        /**
         * Set the curl headers for the payment server
         */
        curl_setopt($this->ch, CURLOPT_HTTPHEADER, $api_headers);

        /**
         * Set the SSL options
         */
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, TRUE);

        /**
         * Execute the request
         */
        $response = curl_exec($this->ch);

        /**
         * Invalid or no certificate authority found, using bundled information
         */
        if (curl_errno($this->ch) == 77 /* CURLE_SSL_CACERT_BADFILE */ || curl_errno($this->ch) == 60 /* CURLE_SSL_CACERT */) {
            curl_setopt($this->ch, CURLOPT_CAINFO, realpath(dirname(__FILE__) . '/Assets/icepay.pem'));

            $response = curl_exec($this->ch);
        }

//        /**
//         * Verifying peer certificate fails on OpenSSL 0.9 or earlier.
//         * We done all we could to check the certificate on the host.
//         * This webserver simply will not accept it and we need to connect.
//         */
//        Uncommenting this code block can be insecure, use at your own risk
//        if (strpos(curl_error($this->ch), 'certificate subject name') !== FALSE) {
//            curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
//
//            $response = curl_exec($this->ch);
//        }

        /**
         * Check if we got any error, if so, exception it
         */
        if (curl_errno($this->ch)) {

            $exception_no = curl_errno($this->ch);
            $exception = curl_error($this->ch);

            curl_close($this->ch);
            $this->ch = NULL;

            throw new \Exception('Unable to reach the ICEPAY payment server (' . $exception_no . '):' . $exception);
        }

        /**
         * Separate headers and response body
         */
        $header_size = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
        $response_header = substr($response, 0, $header_size);
        $response_body = substr($response, $header_size);

        /**
         * Close the connection
         */
        if (!function_exists("curl_reset")) {
            curl_close($this->ch);
            $this->ch = null;
        } else {
            curl_reset($this->ch);
            $this->ch = null;
        }

        /**
         * Verify response checksum. If it does not match, throw an exception.
         * Always require presence of a checksum header.
         */
        $parsed_headers = $this->parse_headers($response_header);
        if (isset($parsed_headers[0]["Checksum"])) {
            $checksumVerification = $this->generateChecksum(
                $this->api_endpoint .
                $api_method .
                $this->api_post .
                $this->api_key .
                $this->api_secret .
                $response_body
            );
            if ($checksumVerification != $parsed_headers[0]["Checksum"]) {
                throw new \Exception("Response checksum invalid");
            }
        }
        else
        {
            //if no checksum header was present in the response, the most likely cause is that the sender ID was invalid
            throw new \Exception("Response checksum not found. Verify your merchant ID.");
        }

        /**
         * Return the decoded json response
         */
        return json_decode($response_body);
    }
659617
private function createRequest($method, $resource, array $data = [])
    {
        if (!empty($data)) {
            $data['signature'] = $this->apiSignature;
        }

        return $this->requestFactory->createRequest($method, $resource, [], $this->encode($data));
    }
464724
public function sendRequest($method = null){
        \Pingqu\OpenApi\Auth\Sign::setConfig([
            'accessKeyId'=>$this->accessKeyId,
            'accessKey'=>$this->accessKeySecret
        ]);
        $method = empty($method)?'GET':$method;
        $para = empty($this->params)?[]:$this->params;
        $httpCore = new \Pingqu\OpenApi\Http\RequestCore($this->api);
        $httpCore->set_body(\DdvPhp\DdvUrl::buildQuery($para));
        $httpCore->set_method($method);
        foreach ($this->header as $key=>$item) {
            $httpCore->add_header($key,$item);
        }
        $httpCore->add_header('Authorization', \Pingqu\OpenApi\Auth\Sign::getAuth($httpCore));
        $httpResponse = $httpCore->send_request(true);
        return $httpResponse;
    }
617420
public function sendRequest($action, $data = null, $method = RequestInterface::POST)
    {
        // don't throw exceptions for 4xx errors
        $this->httpClient->getEventDispatcher()->addListener(
            'request.error',
            function ($event) {
                if ($event['response']->isClientError()) {
                    $event->stopPropagation();
                }
            }
        );

        // Return the response we get back from Pin Payments
        return $this->httpClient->createRequest(
            $method,
            $this->getEndpoint() . $action,
            array('Authorization' => 'Basic ' . base64_encode($this->getSecretKey() . ':')),
            $data
        )->send();
    }
967160
public function createSymmetricEncryptedRequest(
        string $method,
        string $uri,
        string $body,
        SharedEncryptionKey $key,
        array $headers = []
    ): RequestInterface {
        return new Request(
            $method,
            $uri,
            $headers,
            Base64UrlSafe::encode(Simple::encrypt($body, $key))
        );
    }
370775
public function sendRequest($method, $params = [])
    {
        $request = $this->request($method, $params);
        $this->lastResponse = $this->client->sendRequest($request);
        if ($this->lastResponse->isError()) {
            $this->lastResponse->throwException();
        }

        return $this->lastResponse;
    }
1050067
public function createRequest($method, $uri, array $headers = [], $body = null, $protocol = '1.1')
    {
        if (is_array($body)) {
            $body = http_build_query($body, '', '&');
        }

        if ($method == 'GET') {
            $uri .= ((strpos('?', $uri) === false) ? '?' : '&').$body;
            $body = '';
        }

        return $this->requestFactory->createRequest($method, $uri, $headers, $body, $protocol);
    }
485568
public function send($method, $arguments)
    {
        $uri = $arguments[0];
        $params = isset($arguments[1]) ? $arguments[1] : [];
        if (substr($uri, 0, 1) !== '/') {
            $uri = '/' . $uri;
        }

        $response = $this->httpClient->send(
            new Request($method, new Uri($uri)),
            $params
        );

        return $response;
    }
1275005
public function method($method)
    {
        $method  = strtolower($method);
        $builder = new RequestBuilder([
            'domain' => $this->domain,
            'basePath' => $this->basePath,
            'method' => $method,
            'guzzleOptions' => $this->guzzleOptions,
            'returnType' => $this->returnType,
        ]);
        $builder->withHeaders($this->headers);

        if (in_array($method, [ 'patch', 'post', 'put' ])) {
            $builder->withHeader(new ContentType('application/json'));
        }

        return $builder;
    }