/**
  * @return string
  */
 protected function _getCurrentCountryCode($store)
 {
     // if fixed countryCode is setup in config use this
     $countryCode = $this->_adyenHelper->getAdyenHppConfigData('country_code', $store->getId());
     if ($countryCode != "") {
         return $countryCode;
     }
     if ($country = $this->_getQuote()->getBillingAddress()->getCountry()) {
         return $country;
     }
     $defaultCountry = $this->_config->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORES, $store->getCode());
     if ($defaultCountry) {
         return $defaultCountry;
     }
     return "";
 }
 /**
  * @param $payment
  * @return array
  */
 protected function getFormFields($payment)
 {
     $order = $payment->getOrder();
     $realOrderId = $order->getRealOrderId();
     $orderCurrencyCode = $order->getOrderCurrencyCode();
     // check if paybymail has it's own skin
     $skinCode = trim($this->_adyenHelper->getAdyenPayByMailConfigData('skin_code'));
     if ($skinCode == "") {
         // use HPP skin and HMAC
         $skinCode = $this->_adyenHelper->getAdyenHppConfigData('skin_code');
         $hmacKey = $this->_adyenHelper->getHmac();
     } else {
         // use pay_by_mail skin and hmac
         $hmacKey = $this->_adyenHelper->getHmacPayByMail();
     }
     $amount = $this->_adyenHelper->formatAmount($order->getGrandTotal(), $orderCurrencyCode);
     $merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account'));
     $shopperEmail = $order->getCustomerEmail();
     $customerId = $order->getCustomerId();
     $shopperLocale = trim($this->_adyenHelper->getAdyenHppConfigData('shopper_locale'));
     $shopperLocale = !empty($shopperLocale) ? $shopperLocale : $this->_resolver->getLocale();
     $countryCode = trim($this->_adyenHelper->getAdyenHppConfigData('country_code'));
     $countryCode = !empty($countryCode) ? $countryCode : false;
     // if directory lookup is enabled use the billingadress as countrycode
     if ($countryCode == false) {
         if (is_object($order->getBillingAddress()) && $order->getBillingAddress()->getCountry() != "") {
             $countryCode = $order->getBillingAddress()->getCountry();
         } else {
             $countryCode = "";
         }
     }
     $deliveryDays = $this->_adyenHelper->getAdyenHppConfigData('delivery_days');
     $deliveryDays = !empty($deliveryDays) ? $deliveryDays : 5;
     $formFields = [];
     $formFields['merchantAccount'] = $merchantAccount;
     $formFields['merchantReference'] = $realOrderId;
     $formFields['paymentAmount'] = (int) $amount;
     $formFields['currencyCode'] = $orderCurrencyCode;
     $formFields['shipBeforeDate'] = date("Y-m-d", mktime(date("H"), date("i"), date("s"), date("m"), date("j") + $deliveryDays, date("Y")));
     $formFields['skinCode'] = $skinCode;
     $formFields['shopperLocale'] = $shopperLocale;
     if ($countryCode != "") {
         $formFields['countryCode'] = $countryCode;
     }
     $formFields['shopperEmail'] = $shopperEmail;
     // recurring
     $recurringType = trim($this->_adyenHelper->getAdyenAbstractConfigData('recurring_type'));
     $formFields['recurringContract'] = $recurringType;
     $sessionValidity = $this->_adyenHelper->getAdyenPayByMailConfigData('session_validity');
     if ($sessionValidity == "") {
         $sessionValidity = 3;
     }
     $formFields['sessionValidity'] = date("c", strtotime("+" . $sessionValidity . " days"));
     $formFields['shopperReference'] = !empty($customerId) ? $customerId : self::GUEST_ID . $realOrderId;
     // Sort the array by key using SORT_STRING order
     ksort($formFields, SORT_STRING);
     // Generate the signing data string
     $signData = implode(":", array_map([$this, 'escapeString'], array_merge(array_keys($formFields), array_values($formFields))));
     $merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true));
     $formFields['merchantSig'] = $merchantSig;
     $this->_adyenLogger->addAdyenDebug(print_r($formFields, true));
     return $formFields;
 }
Exemple #3
0
 /**
  * @return array
  */
 public function getFormFields()
 {
     $formFields = [];
     try {
         if ($this->_order->getPayment()) {
             $realOrderId = $this->_order->getRealOrderId();
             $orderCurrencyCode = $this->_order->getOrderCurrencyCode();
             $skinCode = trim($this->_adyenHelper->getAdyenHppConfigData('skin_code'));
             $amount = $this->_adyenHelper->formatAmount($this->_order->getGrandTotal(), $orderCurrencyCode);
             $merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account'));
             $shopperEmail = $this->_order->getCustomerEmail();
             $customerId = $this->_order->getCustomerId();
             $shopperIP = $this->_order->getRemoteIp();
             $browserInfo = $_SERVER['HTTP_USER_AGENT'];
             $deliveryDays = $this->_adyenHelper->getAdyenHppConfigData('delivery_days');
             $shopperLocale = trim($this->_adyenHelper->getAdyenHppConfigData('shopper_locale'));
             $shopperLocale = !empty($shopperLocale) ? $shopperLocale : $this->_resolver->getLocale();
             $countryCode = trim($this->_adyenHelper->getAdyenHppConfigData('country_code'));
             $countryCode = !empty($countryCode) ? $countryCode : false;
             // if directory lookup is enabled use the billingadress as countrycode
             if ($countryCode == false) {
                 if ($this->_order->getBillingAddress() && $this->_order->getBillingAddress()->getCountryId() != "") {
                     $countryCode = $this->_order->getBillingAddress()->getCountryId();
                 }
             }
             $formFields = [];
             $formFields['merchantAccount'] = $merchantAccount;
             $formFields['merchantReference'] = $realOrderId;
             $formFields['paymentAmount'] = (int) $amount;
             $formFields['currencyCode'] = $orderCurrencyCode;
             $formFields['shipBeforeDate'] = date("Y-m-d", mktime(date("H"), date("i"), date("s"), date("m"), date("j") + $deliveryDays, date("Y")));
             $formFields['skinCode'] = $skinCode;
             $formFields['shopperLocale'] = $shopperLocale;
             $formFields['countryCode'] = $countryCode;
             $formFields['shopperIP'] = $shopperIP;
             $formFields['browserInfo'] = $browserInfo;
             $formFields['sessionValidity'] = date(DATE_ATOM, mktime(date("H") + 1, date("i"), date("s"), date("m"), date("j"), date("Y")));
             $formFields['shopperEmail'] = $shopperEmail;
             // recurring
             $recurringType = trim($this->_adyenHelper->getAdyenAbstractConfigData('recurring_type'));
             $brandCode = $this->_order->getPayment()->getAdditionalInformation("brand_code");
             // Paypal does not allow ONECLICK,RECURRING only RECURRING
             if ($brandCode == "paypal" && $recurringType == 'ONECLICK,RECURRING') {
                 $recurringType = "RECURRING";
             }
             $formFields['recurringContract'] = $recurringType;
             $formFields['shopperReference'] = !empty($customerId) ? $customerId : self::GUEST_ID . $realOrderId;
             //blocked methods
             $formFields['blockedMethods'] = "";
             $baseUrl = $this->_storeManager->getStore($this->getStore())->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);
             $formFields['resURL'] = $baseUrl . 'adyen/process/result';
             $hmacKey = $this->_adyenHelper->getHmac();
             if ($brandCode) {
                 $formFields['brandCode'] = $brandCode;
             }
             $issuerId = $this->_order->getPayment()->getAdditionalInformation("issuer_id");
             if ($issuerId) {
                 $formFields['issuerId'] = $issuerId;
             }
             $formFields = $this->setBillingAddressData($formFields);
             $formFields = $this->setShippingAddressData($formFields);
             $formFields = $this->setOpenInvoiceData($formFields);
             $formFields['shopper.gender'] = $this->getGenderText($this->_order->getCustomerGender());
             $dob = $this->_order->getCustomerDob();
             if ($dob) {
                 $formFields['shopper.dateOfBirthDayOfMonth'] = trim($this->_getDate($dob, 'd'));
                 $formFields['shopper.dateOfBirthMonth'] = trim($this->_getDate($dob, 'm'));
                 $formFields['shopper.dateOfBirthYear'] = trim($this->_getDate($dob, 'Y'));
             }
             if ($this->_order->getPayment()->getAdditionalInformation(\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE) == "klarna") {
                 //  // needed for DE and AT
                 $formFields['klarna.acceptPrivacyPolicy'] = 'true';
                 // don't allow editable shipping/delivery address
                 $formFields['billingAddressType'] = "1";
                 $formFields['deliveryAddressType'] = "1";
                 // make setting to make this optional
                 $adyFields['shopperType'] = "1";
             }
             // Sort the array by key using SORT_STRING order
             ksort($formFields, SORT_STRING);
             // Generate the signing data string
             $signData = implode(":", array_map([$this, 'escapeString'], array_merge(array_keys($formFields), array_values($formFields))));
             $merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true));
             $formFields['merchantSig'] = $merchantSig;
             $this->_adyenLogger->addAdyenDebug(print_r($formFields, true));
         }
     } catch (Exception $e) {
         // do nothing for now
     }
     return $formFields;
 }