Commit a97b0c37 authored by Ángel Campos's avatar Ángel Campos Committed by GitHub

[PW-2121]: Migration script for auto_capture_openinvoice / capture_on_shipment...

[PW-2121]: Migration script for auto_capture_openinvoice / capture_on_shipment and usage of new config kar_capture_mode (#670)
parent 30925dc7
......@@ -27,11 +27,15 @@ class KarCaptureMode implements \Magento\Framework\Option\ArrayInterface
{
const OPTIONS = [
[
'value' => 0,
'value' => 'capture_on_shipment',
'label' => 'Capture on shipment'
],
[
'value' => 'capture_immediately',
'label' => 'Capture immediately'
],
[
'value' => 1,
'value' => 'capture_manually',
'label' => 'Capture manually'
],
];
......
......@@ -1429,7 +1429,7 @@ class Cron
));
$_paymentCode = $this->_paymentMethodCode();
$captureModeOpenInvoice = $this->_getConfigData(
'auto_capture_openinvoice',
'kar_capture_mode',
'adyen_abstract',
$this->_order->getStoreId()
);
......@@ -1478,12 +1478,12 @@ class Cron
}
}
// if auto capture mode for openinvoice is turned on then use auto capture
if ($captureModeOpenInvoice == true &&
// if capture immediately for openinvoice is turned on then use auto capture
if (strcmp($captureModeOpenInvoice, 'capture_immediately') === 0 &&
$this->_adyenHelper->isPaymentMethodOpenInvoiceMethod($this->_paymentMethod)
) {
$this->_adyenLogger->addAdyenNotificationCronjob(
'This payment method is configured to be working as auto capture '
'This payment method is configured to be working as capture immediately'
);
return true;
}
......
......@@ -54,9 +54,9 @@ class BeforeShipmentObserver extends AbstractDataAssignObserver
{
$shipment = $observer->getEvent()->getShipment();
$order = $shipment->getOrder();
$captureOnShipment = $this->adyenHelper->getConfigData('capture_on_shipment', 'adyen_abstract', $order->getStoreId());
$captureOnShipment = $this->adyenHelper->getConfigData('kar_capture_mode', 'adyen_abstract', $order->getStoreId());
if ($this->isPaymentMethodAdyen($order) && $captureOnShipment) {
if ($this->isPaymentMethodAdyen($order) && strcmp($captureOnShipment, 'capture_on_shipment') === 0) {
$payment = $order->getPayment();
$brandCode = $payment->getAdditionalInformation(
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE
......
......@@ -46,6 +46,11 @@ class UpgradeData implements UpgradeDataInterface
*/
private $reinitableConfig;
/**
* @var configDataTable
*/
private $configDataTable;
public function __construct(
WriterInterface $configWriter,
ReinitableConfigInterface $reinitableConfig
......@@ -173,15 +178,30 @@ class UpgradeData implements UpgradeDataInterface
public function updateDataVersion600(ModuleDataSetupInterface $setup)
{
$this->configDataTable = $setup->getTable('core_config_data');
$connection = $setup->getConnection();
$this->setTerminalSelection($connection);
$this->setKarCaptureMode($connection);
$this->reinitableConfig->reinit();
}
/**
* Sets terminal_selection configuration by checking the value of pos_store_id
*
* @param Magento\Framework\DB\Adapter\Pdo\Mysql $connection
*/
private function setTerminalSelection($connection)
{
$pathTerminalSelection = "payment/adyen_pos_cloud/terminal_selection";
$pathPosStoreId = "payment/adyen_pos_cloud/pos_store_id";
$configDataTable = $setup->getTable('core_config_data');
$connection = $setup->getConnection();
//Setting terminal_selection=store_level for scopes that have pos_store_id set
$select = $connection->select()
->from($configDataTable)
->from($this->configDataTable)
->where('path = ?', $pathPosStoreId)
->where('value <> "" AND value IS NOT NULL');
$configPosStoreIdValues = $connection->fetchAll($select);
......@@ -198,7 +218,7 @@ class UpgradeData implements UpgradeDataInterface
//Setting terminal_selection=merchant_account_level for scopes where pos_store_id is empty
$select = $connection->select()
->from($configDataTable)
->from($this->configDataTable)
->where('path = ?', $pathPosStoreId)
->where('value = ""');
$configPosStoreIdEmptyValues = $connection->fetchAll($select);
......@@ -212,8 +232,78 @@ class UpgradeData implements UpgradeDataInterface
$scopeIdEmpty
);
}
}
$this->reinitableConfig->reinit();
/**
* Sets kar_capture_mode configuration by checking the values of capture_on_shipment and auto_capture_openinvoice
*
* @param Magento\Framework\DB\Adapter\Pdo\Mysql $connection
*/
private function setKarCaptureMode($connection)
{
$pathKarCaptureMode = "payment/adyen_abstract/kar_capture_mode";
//Selecting capture_on_shipment and auto_capture_openinvoice by scope
$select = $connection->select()
->from($this->configDataTable,
[
'scope AS core_config_data_scope',
'scope_id AS core_config_data_scope_id'
]
)
->joinLeft($this->configDataTable . ' AS capture_on_shipment',
'capture_on_shipment.path = "payment/adyen_abstract/capture_on_shipment"
AND capture_on_shipment.scope = core_config_data.scope
AND capture_on_shipment.scope_id = core_config_data.scope_id',
[
'value AS capture_on_shipment_value'
])
->joinLeft($this->configDataTable . ' AS auto_capture_openinvoice',
'auto_capture_openinvoice.path = "payment/adyen_abstract/auto_capture_openinvoice"
AND auto_capture_openinvoice.scope = core_config_data.scope
AND auto_capture_openinvoice.scope_id = core_config_data.scope_id',
[
'value AS auto_capture_openinvoice_value'
])
->where('
core_config_data.path IN
("payment/adyen_abstract/capture_on_shipment", "payment/adyen_abstract/auto_capture_openinvoice")
');
$configCaptureValues = $connection->fetchAll($select);
foreach ($configCaptureValues as $configCaptureValue) {
//If the configuration is not set we assume the default value (0)
if ($configCaptureValue['capture_on_shipment_value'] == null) {
$configCaptureValue['capture_on_shipment_value'] = 0;
}
if ($configCaptureValue['auto_capture_openinvoice_value'] == null) {
$configCaptureValue['auto_capture_openinvoice_value'] = 0;
}
//Assigning values to kar_capture_mode according to source model Adyen\Payment\Model\Config\Source\KarCaptureMode
switch ([
$configCaptureValue['capture_on_shipment_value'],
$configCaptureValue['auto_capture_openinvoice_value']
]) {
case [1, 1]:
case [0, 1]:
$karCaptureModeValue = 'capture_immediately';
break;
case [1, 0]:
$karCaptureModeValue = 'capture_on_shipment';
break;
case [0, 0]:
$karCaptureModeValue = 'capture_manually';
break;
}
$this->configWriter->save(
$pathKarCaptureMode,
$karCaptureModeValue,
$configCaptureValue['core_config_data_scope'],
$configCaptureValue['core_config_data_scope_id']
);
}
}
}
......@@ -29,9 +29,9 @@
<source_model>Adyen\Payment\Model\Config\Source\CaptureMode</source_model>
<config_path>payment/adyen_abstract/capture_mode</config_path>
</field>
<field id="capture_mode_kar" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1"> <!--TODO: Combine fields 15 + 16 and aggregate fields into options-->
<field id="capture_mode_kar" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Capture delay for Klarna, AfterPay, and RatePAY</label>
<!--source_model>Adyen\Payment\Model\Config\Source\KarCaptureMode?</source_model-->
<source_model>Adyen\Payment\Model\Config\Source\KarCaptureMode</source_model>
<config_path>payment/adyen_abstract/kar_capture_mode</config_path>
<comment><![CDATA[This setting should only be changed when instructed by the Adyen <a href="https://support.adyen.com/hc/en-us/requests/new" target="_blank">support team</a>.]]></comment>
</field>
......
......@@ -47,6 +47,7 @@
<fraud_manual_review_accept_status>processing</fraud_manual_review_accept_status>
<send_email_bank_sepa_on_pending>0</send_email_bank_sepa_on_pending>
<ignore_refund_notification>0</ignore_refund_notification>
<kar_capture_mode>capture_manually</kar_capture_mode>
</adyen_abstract>
<adyen_cc>
<active>1</active>
......
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