src/Adyen/HttpClient/CurlClient.php
public function requestJson(\Adyen\Service $service, $requestUrl, $params)
	{
		$client = $service->getClient();
		$config = $client->getConfig();
		$logger = $client->getLogger();
		$username = $config->getUsername();
		$password = $config->getPassword();
		$xApiKey = $config->getXApiKey();

		$jsonRequest = json_encode($params);

		// log the request
		$this->logRequest($logger, $requestUrl, $params);

		//Initiate cURL.
		$ch = curl_init($requestUrl);

		//Tell cURL that we want to send a POST request.
		curl_setopt($ch, CURLOPT_POST, 1);

		//Attach our encoded JSON string to the POST fields.
		curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonRequest);

		//create a custom User-Agent
		$userAgent = $config->get('applicationName') . " " . \Adyen\Client::USER_AGENT_SUFFIX . $client->getLibraryVersion();

		//Set the content type to application/json and use the defined userAgent
		$headers = array(
			'Content-Type: application/json',
			'User-Agent: ' . $userAgent
		);

        // set authorisation credentials according to support & availability
        if (!empty($xApiKey)) {
            //Set the content type to application/json and use the defined userAgent along with the x-api-key
            $headers[] = 'x-api-key: ' . $xApiKey;
        } elseif ($service->requiresApiKey()) {
            $msg = "Please provide a valid Checkout API Key";
            throw new \Adyen\AdyenException($msg);
        } else {

			//Set the basic auth credentials
			curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
			curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
		}

		//Set the timeout
		if ($config->getTimeout() != null) {
			curl_setopt($ch, CURLOPT_TIMEOUT, $config->getTimeout());
		}

		//Set the headers
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		// return the result
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		//Execute the request
		list($result, $httpStatus) = $this->curlRequest($ch);

		// log the raw response
		$logger->info("JSON Response is: " . $result);

		// Get errors
		list($errno, $message) = $this->curlError($ch);

		curl_close($ch);

		// result not 200 throw error
		if ($httpStatus != 200 && $result) {
			$this->handleResultError($result, $logger);
		} elseif (!$result) {
			$this->handleCurlError($requestUrl, $errno, $message, $logger);
		}

		// result in array or json
		if ($config->getOutputType() == 'array') {

			// transform to PHP Array
			$result = json_decode($result, true);

			// log the array result
			$logger->info('Params in response from Adyen:' . print_r($result, 1));
		}

		return $result;
	}
public function requestJson(\Adyen\Service $service, $requestUrl, $params)
	{
		$client = $service->getClient();
		$config = $client->getConfig();
		$logger = $client->getLogger();
		$username = $config->getUsername();
		$password = $config->getPassword();
		$xApiKey = $config->getXApiKey();

		$jsonRequest = json_encode($params);

		// log the request
		$this->logRequest($logger, $requestUrl, $params);

		//Initiate cURL.
		$ch = curl_init($requestUrl);

		//Tell cURL that we want to send a POST request.
		curl_setopt($ch, CURLOPT_POST, 1);

		//Attach our encoded JSON string to the POST fields.
		curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonRequest);

		//create a custom User-Agent
		$userAgent = $config->get('applicationName') . " " . \Adyen\Client::USER_AGENT_SUFFIX . $client->getLibraryVersion();

		//Set the content type to application/json and use the defined userAgent
		$headers = array(
			'Content-Type: application/json',
			'User-Agent: ' . $userAgent
		);

        // set authorisation credentials according to support & availability
        if (!empty($xApiKey)) {
            //Set the content type to application/json and use the defined userAgent along with the x-api-key
            $headers[] = 'x-api-key: ' . $xApiKey;
        } elseif ($service->requiresApiKey()) {
            $msg = "Please provide a valid Checkout API Key";
            throw new \Adyen\AdyenException($msg);
        } else {

			//Set the basic auth credentials
			curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
			curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
		}

		//Set the timeout
		if ($config->getTimeout() != null) {
			curl_setopt($ch, CURLOPT_TIMEOUT, $config->getTimeout());
		}

		//Set the headers
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		// return the result
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		//Execute the request
		list($result, $httpStatus) = $this->curlRequest($ch);

		// log the raw response
		$logger->info("JSON Response is: " . $result);

		// Get errors
		list($errno, $message) = $this->curlError($ch);

		curl_close($ch);

		// result not 200 throw error
		if ($httpStatus != 200 && $result) {
			$this->handleResultError($result, $logger);
		} elseif (!$result) {
			$this->handleCurlError($requestUrl, $errno, $message, $logger);
		}

		// result in array or json
		if ($config->getOutputType() == 'array') {

			// transform to PHP Array
			$result = json_decode($result, true);

			// log the array result
			$logger->info('Params in response from Adyen:' . print_r($result, 1));
		}

		return $result;
	}
public function requestJson ( \ Adyen \ Service $ service , $ requestUrl , $ params ) { $ client = $ service -> getClient ( ) ; $ config = $ client -> getConfig ( ) ; $ logger = $ client -> getLogger ( ) ; $ username = $ config -> getUsername ( ) ; $ password = $ config -> getPassword ( ) ; $ xApiKey = $ config -> getXApiKey ( ) ; $ jsonRequest = json_encode ( $ params ) ; // log the request $ this -> logRequest ( $ logger , $ requestUrl , $ params ) ; //Initiate cURL. $ ch = curl_init ( $ requestUrl ) ; //Tell cURL that we want to send a POST request. curl_setopt ( $ ch , CURLOPT_POST , 1 ) ; //Attach our encoded JSON string to the POST fields. curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ jsonRequest ) ; //create a custom User-Agent $ userAgent = $ config -> get ( 'applicationName' ) . " " . \ Adyen \ Client :: USER_AGENT_SUFFIX . $ client -> getLibraryVersion ( ) ; //Set the content type to application/json and use the defined userAgent $ headers = array ( 'Content-Type: application/json' , 'User-Agent: ' . $ userAgent ) ; // set authorisation credentials according to support & availability if ( ! empty ( $ xApiKey ) ) { //Set the content type to application/json and use the defined userAgent along with the x-api-key $ headers [ ] = 'x-api-key: ' . $ xApiKey ; } elseif ( $ service -> requiresApiKey ( ) ) { $ msg = "Please provide a valid Checkout API Key" ; throw new \ Adyen \ AdyenException ( $ msg ) ; } else { //Set the basic auth credentials curl_setopt ( $ ch , CURLOPT_HTTPAUTH , CURLAUTH_BASIC ) ; curl_setopt ( $ ch , CURLOPT_USERPWD , $ username . ":" . $ password ) ; } //Set the timeout if ( $ config -> getTimeout ( ) != null ) { curl_setopt ( $ ch , CURLOPT_TIMEOUT , $ config -> getTimeout ( ) ) ; } //Set the headers curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ headers ) ; // return the result curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; //Execute the request list ( $ result , $ httpStatus ) = $ this -> curlRequest ( $ ch ) ; // log the raw response $ logger -> info ( "JSON Response is: " . $ result ) ; // Get errors list ( $ errno , $ message ) = $ this -> curlError ( $ ch ) ; curl_close ( $ ch ) ; // result not 200 throw error if ( $ httpStatus != 200 && $ result ) { $ this -> handleResultError ( $ result , $ logger ) ; } elseif ( ! $ result ) { $ this -> handleCurlError ( $ requestUrl , $ errno , $ message , $ logger ) ; } // result in array or json if ( $ config -> getOutputType ( ) == 'array' ) { // transform to PHP Array $ result = json_decode ( $ result , true ) ; // log the array result $ logger -> info ( 'Params in response from Adyen:' . print_r ( $ result , 1 ) ) ; } return $ result ; }
Json API request to Adyen

@param \Adyen\Service $service
@param $requestUrl
@param $params
@return mixed
@throws \Adyen\AdyenException
Json API request to Adyen