Commit 4fcfd9b2 authored by Alexandros Moraitis's avatar Alexandros Moraitis Committed by GitHub

[PW-2124] Replace ISO Country Code config field with Shopper Country dependent dropdown (#674)

* add shopper country field

* add migration script

* Update etc/adminhtml/system/payment_methods/local_payment_methods/advanced_options.xml
Co-Authored-By: default avatarAlessio Zampatti <alessio.zampatti@adyen.com>

* Update Model/Config/Source/ShopperCountryMode.php
Co-Authored-By: default avatarÁngel Campos <angel.campos@adyen.com>

* Update etc/adminhtml/system/payment_methods/local_payment_methods/advanced_options.xml
Co-Authored-By: default avatarÁngel Campos <angel.campos@adyen.com>

* Update the migration script

* fix the getAdyenCountryCodeConfigData method

* Update etc/adminhtml/system/payment_methods/local_payment_methods/advanced_options.xml
Co-authored-by: default avatarAlessio Zampatti <alessio.zampatti@adyen.com>
Co-authored-by: default avatarÁngel Campos <angel.campos@adyen.com>
parent a97b0c37
......@@ -74,7 +74,7 @@ class PayByMailCommand implements CommandInterface
$stateObject->setState(\Magento\Sales\Model\Order::STATE_NEW);
$stateObject->setStatus($this->_adyenHelper->getAdyenAbstractConfigData('order_status'));
$stateObject->setIsNotified(false);
return $this;
}
......@@ -139,7 +139,7 @@ class PayByMailCommand implements CommandInterface
$skinCode = $this->_adyenHelper->getAdyenHppConfigData('skin_code');
$hmacKey = $this->_adyenHelper->getHmac();
$shopperLocale = trim($this->_adyenHelper->getAdyenHppConfigData('shopper_locale', $storeId));
$countryCode = trim($this->_adyenHelper->getAdyenHppConfigData('country_code', $storeId));
$countryCode = trim($this->_adyenHelper->getAdyenCountryCodeConfigData($storeId));
} else {
// use pay_by_mail skin and hmac
$hmacKey = $this->_adyenHelper->getHmacPayByMail();
......@@ -184,7 +184,7 @@ class PayByMailCommand implements CommandInterface
$formFields['shopperEmail'] = $shopperEmail;
// recurring
$recurringType = $this->_adyenHelper->getRecurringTypeFromOneclickRecurringSetting($storeId);
$sessionValidity = $this->_adyenHelper->getAdyenPayByMailConfigData('session_validity', $storeId);
if ($sessionValidity == "") {
......
......@@ -1901,4 +1901,21 @@ class Data extends AbstractHelper
);
}
/**
* Gives back CountryCode configuration values
*
* @param null $storeId
* @return mixed
*/
public function getAdyenCountryCodeConfigData($storeId = null)
{
$shopperCountry = trim($this->getConfigData('shopper_country', 'adyen_hpp', $storeId));
$countryCode = trim($this->getConfigData('country_code', 'adyen_hpp', $storeId));
if ($shopperCountry == 1) {
return $countryCode;
} else {
return "";
}
}
}
......@@ -260,7 +260,7 @@ class PaymentMethods extends AbstractHelper
protected function getCurrentCountryCode($store, $country)
{
// if fixed countryCode is setup in config use this
$countryCode = $this->adyenHelper->getAdyenHppConfigData('country_code', $store->getId());
$countryCode = $this->adyenHelper->getAdyenCountryCodeConfigData($store->getId());
if ($countryCode != "") {
return $countryCode;
......@@ -391,4 +391,4 @@ class PaymentMethods extends AbstractHelper
return $responseData;
}
}
\ No newline at end of file
}
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2020 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model\Config\Source;
class ShopperCountryMode implements \Magento\Framework\Option\ArrayInterface
{
const OPTIONS = [
[
'value' => 0,
'label' => 'Based on address'
],
[
'value' => 1,
'label' => 'Custom'
],
];
/**
* @return array
*/
public function toOptionArray()
{
return self::OPTIONS;
}
}
......@@ -185,6 +185,8 @@ class UpgradeData implements UpgradeDataInterface
$this->setKarCaptureMode($connection);
$this->setShopperCountry($connection);
$this->reinitableConfig->reinit();
}
......@@ -266,7 +268,7 @@ class UpgradeData implements UpgradeDataInterface
'value AS auto_capture_openinvoice_value'
])
->where('
core_config_data.path IN
core_config_data.path IN
("payment/adyen_abstract/capture_on_shipment", "payment/adyen_abstract/auto_capture_openinvoice")
');
$configCaptureValues = $connection->fetchAll($select);
......@@ -306,4 +308,34 @@ class UpgradeData implements UpgradeDataInterface
);
}
}
/**
* Sets shoppercountry configuration by checking the value of payment/adyen_hpp/country_code
*
* @param Magento\Framework\DB\Adapter\Pdo\Mysql $connection
*/
private function setShopperCountry($connection)
{
$countryCode = "payment/adyen_hpp/country_code";
$shoppercountry = "payment/adyen_hpp/shopper_country";
$select = $connection->select()
->from($this->configDataTable)
->where('path = ?', $countryCode)
->where('value <> "" AND value IS NOT NULL');
$configCountryCodeValues = $connection->fetchAll($select);
foreach ($configCountryCodeValues as $configCountryCodeValue) {
$scope = $configCountryCodeValue['scope'];
$scopeId = $configCountryCodeValue['scope_id'];
$this->configWriter->save(
$shoppercountry,
1,
$scope,
$scopeId
);
}
}
}
......@@ -26,32 +26,42 @@
<label>Advanced options</label>
<field id="shopper_country" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Shopper country</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<!--config_path></config_path--> <!--TODO: New field? Yes-->
<source_model>Adyen\Payment\Model\Config\Source\ShopperCountryMode</source_model>
<config_path>payment/adyen_hpp/shopper_country</config_path>
</field>
<field id="ratepay_id" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="shopper_specific_country" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Custom shopper country</label>
<depends>
<field id="shopper_country">1</field>
</depends>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<validate>required-entry</validate>
<config_path>payment/adyen_hpp/country_code</config_path>
</field>
<field id="ratepay_id" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>RatePAY Device Ident SId</label>
<tooltip>Unique RatePAY Id provided by RatePAY integration consultant</tooltip>
<config_path>payment/adyen_hpp/ratepay_id</config_path>
</field>
<field id="split_payments_refund_strategy" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="split_payments_refund_strategy" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Refunds that include gift cards</label>
<comment><![CDATA[Learn more about refunds that include gift cards on <a href="https://docs.adyen.com/plugins/magento-2/set-up-the-plugin-in-magento/#split-payment" target="_blank">Adyen documentation</a>.]]></comment>
<source_model>Adyen\Payment\Model\Config\Source\SplitPaymentRefundStrategy</source_model>
<config_path>payment/adyen_abstract/split_payments_refund_strategy</config_path>
</field>
<field id="allowspecific_local_payment_methods" translate="label" type="allowspecific" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
<field id="allowspecific_local_payment_methods" translate="label" type="allowspecific" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Applicable countries</label>
<source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
<config_path>payment/adyen_hpp/allowspecific</config_path>
</field>
<field id="specificcountry" translate="label" type="multiselect" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Payment from specific countries</label>
<depends>
<field id="allowspecific_local_payment_methods">1</field>
</depends>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<can_be_empty>1</can_be_empty>
<config_path>payment/adyen_hpp/specificcountry</config_path>
<field id="specificcountry" translate="label" type="multiselect" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Payment from specific countries</label>
<depends>
<field id="allowspecific_local_payment_methods">1</field>
</depends>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<validate>required-entry</validate>
<config_path>payment/adyen_hpp/specificcountry</config_path>
</field>
</config>
......@@ -121,6 +121,7 @@
<allowspecific>0</allowspecific>
<ratepay_id>oj9GsQ</ratepay_id>
<sort_order>3</sort_order>
<shopper_country>0</shopper_country>
<payment_action>authorize</payment_action>
<can_initialize>1</can_initialize>
<is_gateway>1</is_gateway>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment