Omnipay\PayPal\Message\AbstractRestRequest::sendData PHP Method

sendData() public method

public sendData ( $data )
    public function sendData($data)
    {
        // don't throw exceptions for 4xx errors
        $this->httpClient->getEventDispatcher()->addListener('request.error', function ($event) {
            if ($event['response']->isClientError()) {
                $event->stopPropagation();
            }
        });
        // Guzzle HTTP Client createRequest does funny things when a GET request
        // has attached data, so don't send the data if the method is GET.
        if ($this->getHttpMethod() == 'GET') {
            $httpRequest = $this->httpClient->createRequest($this->getHttpMethod(), $this->getEndpoint() . '?' . http_build_query($data), array('Accept' => 'application/json', 'Authorization' => 'Bearer ' . $this->getToken(), 'Content-type' => 'application/json'));
        } else {
            $httpRequest = $this->httpClient->createRequest($this->getHttpMethod(), $this->getEndpoint(), array('Accept' => 'application/json', 'Authorization' => 'Bearer ' . $this->getToken(), 'Content-type' => 'application/json'), $this->toJSON($data));
        }
        // Might be useful to have some debug code here, PayPal especially can be
        // a bit fussy about data formats and ordering.  Perhaps hook to whatever
        // logging engine is being used.
        // echo "Data == " . json_encode($data) . "\n";
        try {
            $httpRequest->getCurlOptions()->set(CURLOPT_SSLVERSION, 6);
            // CURL_SSLVERSION_TLSv1_2 for libcurl < 7.35
            $httpResponse = $httpRequest->send();
            // Empty response body should be parsed also as and empty array
            $body = $httpResponse->getBody(true);
            $jsonToArrayResponse = !empty($body) ? $httpResponse->json() : array();
            return $this->response = $this->createResponse($jsonToArrayResponse, $httpResponse->getStatusCode());
        } catch (\Exception $e) {
            throw new InvalidResponseException('Error communicating with payment gateway: ' . $e->getMessage(), $e->getCode());
        }
    }