protected function _apiRequest($request) { // log the request $this->_adyenLogger->info('The request to adyen: ' . print_r($request, true)); $webserviceUsername = $this->_adyenHelper->getWsUsername(); $webservicePassword = $this->_adyenHelper->getWsPassword(); $url = $this->_adyenHelper->getWsUrl(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $webserviceUsername . ":" . $webservicePassword); curl_setopt($ch, CURLOPT_POST, count($request)); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $results = curl_exec($ch); $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpStatus != 200) { throw new \Magento\Framework\Exception\LocalizedException(__('HTTP Status code' . $httpStatus . " " . $webserviceUsername . ":" . $webservicePassword)); } if ($results === false) { throw new \Magento\Framework\Exception\LocalizedException(__('HTTP Status code' . $results)); } parse_str($results, $resultArr); curl_close($ch); // log the result $this->_adyenLogger->info('The response to adyen: ' . print_r($resultArr, true)); return $resultArr; }
/** * PaymentRequest constructor. * * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor * @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger * @param \Adyen\Payment\Model\RecurringType $recurringType * @param array $data */ public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Logger\AdyenLogger $adyenLogger, \Adyen\Payment\Model\RecurringType $recurringType, array $data = []) { $this->_encryptor = $encryptor; $this->_adyenHelper = $adyenHelper; $this->_adyenLogger = $adyenLogger; $this->_recurringType = $recurringType; $this->_appState = $context->getAppState(); // initialize client $webserviceUsername = $this->_adyenHelper->getWsUsername(); $webservicePassword = $this->_adyenHelper->getWsPassword(); $client = new \Adyen\Client(); $client->setApplicationName("Magento 2 plugin"); $client->setUsername($webserviceUsername); $client->setPassword($webservicePassword); if ($this->_adyenHelper->isDemoMode()) { $client->setEnvironment(\Adyen\Environment::TEST); } else { $client->setEnvironment(\Adyen\Environment::LIVE); } // assign magento log $client->setLogger($adyenLogger); $this->_client = $client; }