/**
  * @param array $validationSubject
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function validate(array $validationSubject)
 {
     $response = \Magento\Payment\Gateway\Helper\SubjectReader::readResponse($validationSubject);
     $isValid = true;
     $errorMessages = [];
     if ($response['response'] != '[capture-received]') {
         $errorMsg = __('Error with capture');
         $this->adyenLogger->error($errorMsg);
         $errorMessages[] = $errorMsg;
     }
     return $this->createResult($isValid, $errorMessages);
 }
 /**
  * @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;
 }
 /**
  * @param array $validationSubject
  * @return \Magento\Payment\Gateway\Validator\ResultInterface
  */
 public function validate(array $validationSubject)
 {
     $response = \Magento\Payment\Gateway\Helper\SubjectReader::readResponse($validationSubject);
     $paymentDataObjectInterface = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($validationSubject);
     $payment = $paymentDataObjectInterface->getPayment();
     $payment->setAdditionalInformation('3dActive', false);
     $isValid = true;
     $errorMessages = [];
     // validate result
     if ($response && isset($response['resultCode'])) {
         switch ($response['resultCode']) {
             case "Authorised":
                 $payment->setAdditionalInformation('pspReference', $response['pspReference']);
                 break;
             case "Received":
                 $payment->setAdditionalInformation('pspReference', $response['pspReference']);
                 // set additionalData
                 if (isset($response['additionalData']) && is_array($response['additionalData'])) {
                     $additionalData = $response['additionalData'];
                     if (isset($additionalData['boletobancario.dueDate'])) {
                         $payment->setAdditionalInformation('dueDate', $additionalData['boletobancario.dueDate']);
                     }
                     if (isset($additionalData['boletobancario.expirationDate'])) {
                         $payment->setAdditionalInformation('expirationDate', $additionalData['boletobancario.expirationDate']);
                     }
                     if (isset($additionalData['boletobancario.url'])) {
                         $payment->setAdditionalInformation('url', $additionalData['boletobancario.url']);
                     }
                 }
                 break;
             case "RedirectShopper":
                 $payment->setAdditionalInformation('3dActive', true);
                 $payment->setAdditionalInformation('pspReference', $response['pspReference']);
                 $issuerUrl = $response['issuerUrl'];
                 $paReq = $response['paRequest'];
                 $md = $response['md'];
                 if (!empty($paReq) && !empty($md) && !empty($issuerUrl)) {
                     $payment->setAdditionalInformation('issuerUrl', $response['issuerUrl']);
                     $payment->setAdditionalInformation('paRequest', $response['paRequest']);
                     $payment->setAdditionalInformation('md', $response['md']);
                 } else {
                     $isValid = false;
                     $errorMsg = __('3D secure is not valid.');
                     $this->adyenLogger->error($errorMsg);
                     $errorMessages[] = $errorMsg;
                 }
                 break;
             case "Refused":
                 if ($response['refusalReason']) {
                     $refusalReason = $response['refusalReason'];
                     switch ($refusalReason) {
                         case "Transaction Not Permitted":
                             $errorMsg = __('The transaction is not permitted.');
                             break;
                         case "CVC Declined":
                             $errorMsg = __('Declined due to the Card Security Code(CVC) being incorrect. Please check your CVC code!');
                             break;
                         case "Restricted Card":
                             $errorMsg = __('The card is restricted.');
                             break;
                         case "803 PaymentDetail not found":
                             $errorMsg = __('The payment is REFUSED because the saved card is removed. Please try an other payment method.');
                             break;
                         case "Expiry month not set":
                             $errorMsg = __('The expiry month is not set. Please check your expiry month!');
                             break;
                         default:
                             $errorMsg = __('The payment is REFUSED.');
                             break;
                     }
                 } else {
                     $errorMsg = __('The payment is REFUSED.');
                 }
                 // this will result the specific error
                 throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
                 break;
             default:
                 $errorMsg = __('Error with payment method please select different payment method.');
                 throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
                 break;
         }
     } else {
         $errorMsg = __('Error with payment method please select different payment method.');
         throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
     }
     return $this->createResult($isValid, $errorMessages);
 }
 public function fullApiRequest($payment, $paymentMethodCode)
 {
     $order = $payment->getOrder();
     $amount = $order->getGrandTotal();
     $customerEmail = $order->getCustomerEmail();
     $shopperIp = $order->getRemoteIp();
     $orderCurrencyCode = $order->getOrderCurrencyCode();
     $merchantAccount = $this->_adyenHelper->getAdyenAbstractConfigData("merchant_account");
     $recurringType = $this->_adyenHelper->getAdyenAbstractConfigData('recurring_type');
     $realOrderId = $order->getRealOrderId();
     $customerId = $order->getCustomerId();
     $shopperReference = !empty($customerId) ? $customerId : self::GUEST_ID . $realOrderId;
     // call lib
     $service = new \Adyen\Service\Payment($this->_client);
     $amount = ['currency' => $orderCurrencyCode, 'value' => $this->_adyenHelper->formatAmount($amount, $orderCurrencyCode)];
     $browserInfo = ['userAgent' => $_SERVER['HTTP_USER_AGENT'], 'acceptHeader' => $_SERVER['HTTP_ACCEPT']];
     $request = array("merchantAccount" => $merchantAccount, "amount" => $amount, "reference" => $order->getIncrementId(), "shopperIP" => $shopperIp, "shopperEmail" => $customerEmail, "shopperReference" => $shopperReference, "fraudOffset" => "0", "browserInfo" => $browserInfo);
     // set the recurring type
     $recurringContractType = null;
     if ($recurringType) {
         if ($paymentMethodCode == \Adyen\Payment\Model\Method\Oneclick::METHOD_CODE) {
             // For ONECLICK look at the recurringPaymentType that the merchant has selected in Adyen ONECLICK settings
             if ($payment->getAdditionalInformation('customer_interaction')) {
                 $recurringContractType = \Adyen\Payment\Model\RecurringType::ONECLICK;
             } else {
                 $recurringContractType = \Adyen\Payment\Model\RecurringType::RECURRING;
             }
         } else {
             if ($paymentMethodCode == \Adyen\Payment\Model\Method\Cc::METHOD_CODE) {
                 if ($payment->getAdditionalInformation("store_cc") == "" && ($recurringType == "ONECLICK,RECURRING" || $recurringType == "RECURRING")) {
                     $recurringContractType = \Adyen\Payment\Model\RecurringType::RECURRING;
                 } elseif ($payment->getAdditionalInformation("store_cc") == "1") {
                     $recurringContractType = $recurringType;
                 }
             } else {
                 $recurringContractType = $recurringType;
             }
         }
     }
     if ($recurringContractType) {
         $recurring = array('contract' => $recurringContractType);
         $request['recurring'] = $recurring;
     }
     $this->_adyenLogger->error('storeCC?:' . $payment->getAdditionalInformation("store_cc"));
     $this->_adyenLogger->error('recuringtype' . $recurringType);
     $this->_adyenLogger->error('recurringcontractType' . $recurringContractType);
     $billingAddress = $order->getBillingAddress();
     if ($billingAddress) {
         $addressArray = $this->_adyenHelper->getStreet($billingAddress);
         $requestBilling = array("street" => $addressArray['name'], "postalCode" => $billingAddress->getPostcode(), "city" => $billingAddress->getCity(), "houseNumberOrName" => $addressArray['house_number'], "stateOrProvince" => $billingAddress->getRegionCode(), "country" => $billingAddress->getCountryId());
         // houseNumberOrName is mandatory
         if ($requestBilling['houseNumberOrName'] == "") {
             $requestBilling['houseNumberOrName'] = "NA";
         }
         $requestBilling['billingAddress'] = $requestBilling;
         $request = array_merge($request, $requestBilling);
     }
     $deliveryAddress = $order->getDeliveryAddress();
     if ($deliveryAddress) {
         $addressArray = $this->_adyenHelper->getStreet($deliveryAddress);
         $requestDelivery = array("street" => $addressArray['name'], "postalCode" => $deliveryAddress->getPostcode(), "city" => $deliveryAddress->getCity(), "houseNumberOrName" => $addressArray['house_number'], "stateOrProvince" => $deliveryAddress->getRegionCode(), "country" => $deliveryAddress->getCountryId());
         // houseNumberOrName is mandatory
         if ($requestDelivery['houseNumberOrName'] == "") {
             $requestDelivery['houseNumberOrName'] = "NA";
         }
         $requestDelivery['deliveryAddress'] = $requestDelivery;
         $request = array_merge($request, $requestDelivery);
     }
     // define the shopper interaction
     if ($paymentMethodCode == \Adyen\Payment\Model\Method\Oneclick::METHOD_CODE) {
         $recurringDetailReference = $payment->getAdditionalInformation("recurring_detail_reference");
         if ($payment->getAdditionalInformation('customer_interaction')) {
             $shopperInteraction = "Ecommerce";
         } else {
             $shopperInteraction = "ContAuth";
         }
         // For recurring Ideal and Sofort needs to be converted to SEPA for this it is mandatory to set selectBrand to sepadirectdebit
         if (!$payment->getAdditionalInformation('customer_interaction')) {
             if ($payment->getCcType() == "directEbanking" || $payment->getCcType() == "ideal") {
                 $this->selectedBrand = "sepadirectdebit";
             }
         }
     } else {
         $recurringDetailReference = null;
         $shopperInteraction = "Ecommerce";
     }
     if ($shopperInteraction) {
         $request['shopperInteraction'] = $shopperInteraction;
     }
     if ($recurringDetailReference && $recurringDetailReference != "") {
         $request['selectedRecurringDetailReference'] = $recurringDetailReference;
     }
     // If cse is enabled add encrypted card date into request
     if ($this->_adyenHelper->getAdyenCcConfigDataFlag('cse_enabled')) {
         $request['additionalData']['card.encrypted.json'] = $payment->getAdditionalInformation("encrypted_data");
     } else {
         $requestCreditCardDetails = array("expiryMonth" => $payment->getCcExpMonth(), "expiryYear" => $payment->getCcExpYear(), "holderName" => $payment->getCcOwner(), "number" => $payment->getCcNumber(), "cvc" => $payment->getCcCid());
         $cardDetails['card'] = $requestCreditCardDetails;
         $request = array_merge($request, $cardDetails);
     }
     $result = $service->authorise($request);
     return $result;
 }