-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ECP-8712] Fix broken partial captures and implement adyen_authorized…
… status (#2316) * Revert ECP-8673 * [ECP-8712] Revert #2263 and implement new order status * [ECP-8712] Set state to payment_review while waiting for CAPTURE webhook * [ECP-8712] Set default configuration values * [ECP-8712] Revert unit test * [ECP-8712] Change the order status after invoicing * [ECP-8712] Write unit test for data patch * [ECP-8712] Write unit test for DataPatch helper class * [ECP-8712] Fix Sonar warnings * [ECP-8712] Replace the imported class
- Loading branch information
1 parent
becd00f
commit 0e97203
Showing
11 changed files
with
295 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* | ||
* Adyen Payment module (https://www.adyen.com/) | ||
* | ||
* Copyright (c) 2023 Adyen N.V. (https://www.adyen.com/) | ||
* See LICENSE.txt for license details. | ||
* | ||
* Author: Adyen <[email protected]> | ||
*/ | ||
|
||
namespace Adyen\Payment\Helper; | ||
|
||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
|
||
class DataPatch | ||
{ | ||
const CONFIG_TABLE = 'core_config_data'; | ||
|
||
public function findConfig( | ||
ModuleDataSetupInterface $setup, | ||
string $path, | ||
?string $value | ||
): ?array { | ||
$config = null; | ||
|
||
$configDataTable = $setup->getTable(self::CONFIG_TABLE); | ||
$connection = $setup->getConnection(); | ||
|
||
$select = $connection->select()->from($configDataTable)->where('path = ?', $path); | ||
$matchingConfigs = $connection->fetchAll($select); | ||
|
||
if (!empty($matchingConfigs) && is_null($value)) { | ||
$config = reset($matchingConfigs); | ||
} else { | ||
foreach ($matchingConfigs as $matchingConfig) { | ||
if ($matchingConfig['value'] === $value) { | ||
$config = $matchingConfig; | ||
} | ||
} | ||
} | ||
|
||
return $config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
/** | ||
* Adyen Payment module (https://www.adyen.com/) | ||
* | ||
* Copyright (c) 2023 Adyen N.V. (https://www.adyen.com/) | ||
* See LICENSE.txt for license details. | ||
* | ||
* Author: Adyen <[email protected]> | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Adyen\Payment\Setup\Patch\Data; | ||
|
||
use Adyen\Payment\Helper\DataPatch; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
use Magento\Framework\Setup\Patch\DataPatchInterface; | ||
use Magento\Framework\Setup\Patch\PatchVersionInterface; | ||
use Magento\Framework\App\Config\ReinitableConfigInterface; | ||
use Magento\Framework\App\Config\Storage\WriterInterface; | ||
use Magento\Sales\Model\Order; | ||
|
||
class CreateStatusAuthorized implements DataPatchInterface, PatchVersionInterface | ||
{ | ||
private ModuleDataSetupInterface $moduleDataSetup; | ||
private WriterInterface $configWriter; | ||
private ReinitableConfigInterface $reinitableConfig; | ||
private DataPatch $dataPatchHelper; | ||
|
||
const ADYEN_AUTHORIZED_STATUS = 'adyen_authorized'; | ||
const ADYEN_AUTHORIZED_STATUS_LABEL = 'Authorized'; | ||
|
||
public function __construct( | ||
ModuleDataSetupInterface $moduleDataSetup, | ||
WriterInterface $configWriter, | ||
ReinitableConfigInterface $reinitableConfig, | ||
DataPatch $dataPatchHelper | ||
) { | ||
$this->moduleDataSetup = $moduleDataSetup; | ||
$this->configWriter = $configWriter; | ||
$this->reinitableConfig = $reinitableConfig; | ||
$this->dataPatchHelper = $dataPatchHelper; | ||
} | ||
|
||
public function apply() | ||
{ | ||
$setup = $this->moduleDataSetup; | ||
|
||
$orderStateAssignmentTable = $this->moduleDataSetup->getTable('sales_order_status_state'); | ||
$orderStatusTable = $this->moduleDataSetup->getTable('sales_order_status'); | ||
|
||
$status = [ | ||
[ | ||
'status' => self::ADYEN_AUTHORIZED_STATUS, | ||
'label' => self::ADYEN_AUTHORIZED_STATUS_LABEL | ||
] | ||
]; | ||
|
||
$this->moduleDataSetup->getConnection()->insertOnDuplicate($orderStatusTable, $status); | ||
|
||
$stateAssignment = [ | ||
[ | ||
'status' => self::ADYEN_AUTHORIZED_STATUS, | ||
'state' => Order::STATE_NEW, | ||
'is_default' => 0, | ||
'visible_on_front' => 1 | ||
] | ||
]; | ||
|
||
$this->moduleDataSetup->getConnection()->insertOnDuplicate($orderStateAssignmentTable, $stateAssignment); | ||
|
||
$path = 'payment/adyen_abstract/payment_pre_authorized'; | ||
|
||
$config = $this->dataPatchHelper->findConfig($setup, $path, Order::STATE_PROCESSING); | ||
if (isset($config)) { | ||
$this->configWriter->save( | ||
$path, | ||
self::ADYEN_AUTHORIZED_STATUS, | ||
$config['scope'], | ||
$config['scope_id'] | ||
); | ||
} | ||
|
||
// re-initialize otherwise it will cause errors | ||
$this->reinitableConfig->reinit(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getAliases(): array | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function getDependencies(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public static function getVersion(): string | ||
{ | ||
return '9.0.3'; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.