/**
  * AdyenClientService constructor.
  * @param string $applicationName
  * @param string $username
  * @param string $password
  * @param string $environment
  */
 public function __construct($applicationName, $username, $password, $environment = 'test')
 {
     $client = new \Adyen\Client();
     $client->setApplicationName($applicationName);
     $client->setUsername($username);
     $client->setPassword($password);
     $client->setEnvironment($environment);
     $this->client = $client;
 }
 /**
  * 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;
 }
 /**
  * @param $requestParams
  * @param $store
  * @return array
  * @throws \Adyen\AdyenException
  */
 protected function _getDirectoryLookupResponse($requestParams, $store)
 {
     $cacheKey = $this->_getCacheKeyForRequest($requestParams, $store);
     // initialize the adyen client
     $client = new \Adyen\Client();
     if ($this->_adyenHelper->isDemoMode()) {
         $client->setEnvironment(\Adyen\Environment::TEST);
     } else {
         $client->setEnvironment(\Adyen\Environment::LIVE);
     }
     // connect to magento log
     $client->setLogger($this->_adyenLogger);
     $hmacKey = $this->_adyenHelper->getHmac();
     // create and add signature
     try {
         $requestParams["merchantSig"] = \Adyen\Util\Util::calculateSha256Signature($hmacKey, $requestParams);
     } catch (\Adyen\AdyenException $e) {
         $this->_adyenLogger->error($e->getMessage());
         // return empty result
         return [];
     }
     // initialize service
     $service = new \Adyen\Service\DirectoryLookup($client);
     try {
         $responseData = $service->directoryLookup($requestParams);
     } catch (\Adyen\AdyenException $e) {
         $this->_adyenLogger->error("The Directory Lookup response is empty check your Adyen configuration in Magento.");
         // return empty result
         return [];
     }
     return $responseData;
 }
 /**
  * Mock client for reviewing payout
  *
  * @return \Adyen\Client
  */
 protected function createReviewPayoutClient()
 {
     // load settings from .ini file
     $settings = $this->_loadConfigIni();
     // validate username, password and MERCHANTAccount
     if (isset($settings['reviewPayoutUsername']) && isset($settings['reviewPayoutPassword'])) {
         if ($settings['reviewPayoutUsername'] == "YOUR REVIEW PAYOUT USERNAME" || $settings['reviewPayoutUsername'] == "" || $settings['reviewPayoutPassword'] == "YOUR REVIEW PAYOUT PASSWORD" || $settings['reviewPayoutPassword'] == "") {
             $client = new \Adyen\Client();
             $client->setApplicationName("My Test Application");
             $client->setEnvironment(\Adyen\Environment::TEST);
             $this->_skipTest("Skipped the test. Configure your WebService ReviewPayout Username and Password in the config");
             return $client;
         } else {
             $client = new \Adyen\Client();
             $client->setApplicationName("My Test Application");
             $client->setUsername($settings['reviewPayoutUsername']);
             $client->setPassword($settings['reviewPayoutPassword']);
             $client->setEnvironment(\Adyen\Environment::TEST);
             return $client;
         }
     } else {
         $this->_skipTest("Skipped the test. Configure your WebService ReviewPayout Username and Password in the config");
     }
 }
 public function testExceptionMissingUsernamePassword()
 {
     // initialize client
     $client = new \Adyen\Client();
     $client->setApplicationName("Adyen PHP Api Library");
     $client->setUsername("");
     $client->setPassword("");
     $client->setEnvironment(\Adyen\Environment::TEST);
     // initialize service
     $service = new Service\Recurring($client);
     // in a model form ?
     $recurring = array('contract' => \Adyen\Contract::RECURRING);
     $params = array('merchantAccount' => $this->getMerchantAccount(), 'recurring' => $recurring, 'shopperReference' => '1');
     $e = null;
     try {
         $result = $service->listRecurringDetails($params);
     } catch (\Exception $e) {
     }
     // check if exception is correct
     $this->assertEquals('Adyen\\AdyenException', get_class($e));
     $this->assertEquals("Probably your Web Service username and/or password is incorrect\n(Network error [errno 0]: )", $e->getMessage());
     $this->assertEquals('0', $e->getCode());
 }