/**
  * @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject
  * @return mixed
  * @throws ClientException
  */
 public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
 {
     $request = $transferObject->getBody();
     // call lib
     $service = new \Adyen\Service\Payment($this->_client);
     try {
         $response = $service->authorise($request);
     } catch (\Adyen\AdyenException $e) {
         $response['error'] = $e->getMessage();
     }
     return $response;
 }
 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;
 }