-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from Adyen/develop
Release 3.8.1
- Loading branch information
Showing
16 changed files
with
700 additions
and
103 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,86 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* ###### | ||
* ###### | ||
* ############ ####( ###### #####. ###### ############ ############ | ||
* ############# #####( ###### #####. ###### ############# ############# | ||
* ###### #####( ###### #####. ###### ##### ###### ##### ###### | ||
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ###### | ||
* ###### ###### #####( ###### #####. ###### ##### ##### ###### | ||
* ############# ############# ############# ############# ##### ###### | ||
* ############ ############ ############# ############ ##### ###### | ||
* ###### | ||
* ############# | ||
* ############ | ||
* | ||
* Adyen Payment Module | ||
* | ||
* Copyright (c) 2022 Adyen N.V. | ||
* This file is open source and available under the MIT license. | ||
* See the LICENSE file for more info. | ||
* | ||
* Author: Adyen <[email protected]> | ||
*/ | ||
|
||
namespace Adyen\Shopware\Command; | ||
|
||
use Adyen\Shopware\Handlers\Command\DisablePaymentMethodHandler; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class DisablePaymentMethodCommand extends Command | ||
{ | ||
protected static $defaultName = 'adyen:payment-method:disable'; | ||
|
||
/** | ||
* @var DisablePaymentMethodHandler | ||
*/ | ||
protected $handler; | ||
|
||
public function __construct(DisablePaymentMethodHandler $handler) | ||
{ | ||
parent::__construct(); | ||
$this->handler = $handler; | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this->setDescription('Finds the payment method according to given PM handler and disables it'); | ||
|
||
$this->addOption( | ||
'all', | ||
'A', | ||
InputOption::VALUE_NONE, | ||
'Disables all Adyen payment methods' | ||
); | ||
|
||
$this->addOption( | ||
'payment-method', | ||
'm', | ||
InputOption::VALUE_REQUIRED, | ||
'Disables given Adyen payment method' | ||
); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
try { | ||
$isAllSelected = $input->getOption('all'); | ||
$paymentMethodHandlerIdentifier = $input->getOption('payment-method'); | ||
|
||
if ($isAllSelected xor isset($paymentMethodHandlerIdentifier)) { | ||
$this->handler->run($isAllSelected, $paymentMethodHandlerIdentifier); | ||
$message = 'Payment method is disabled successfully.'; | ||
} else { | ||
throw new \Exception('Invalid parameter! For usage please check manual --help.'); | ||
} | ||
} catch (\Exception $e) { | ||
$message = $e->getMessage(); | ||
} | ||
|
||
$output->writeln($message); | ||
return 0; | ||
} | ||
} |
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,86 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* ###### | ||
* ###### | ||
* ############ ####( ###### #####. ###### ############ ############ | ||
* ############# #####( ###### #####. ###### ############# ############# | ||
* ###### #####( ###### #####. ###### ##### ###### ##### ###### | ||
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ###### | ||
* ###### ###### #####( ###### #####. ###### ##### ##### ###### | ||
* ############# ############# ############# ############# ##### ###### | ||
* ############ ############ ############# ############ ##### ###### | ||
* ###### | ||
* ############# | ||
* ############ | ||
* | ||
* Adyen Payment Module | ||
* | ||
* Copyright (c) 2022 Adyen N.V. | ||
* This file is open source and available under the MIT license. | ||
* See the LICENSE file for more info. | ||
* | ||
* Author: Adyen <[email protected]> | ||
*/ | ||
|
||
namespace Adyen\Shopware\Command; | ||
|
||
use Adyen\Shopware\Handlers\Command\EnablePaymentMethodHandler; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class EnablePaymentMethodCommand extends Command | ||
{ | ||
protected static $defaultName = 'adyen:payment-method:enable'; | ||
|
||
/** | ||
* @var EnablePaymentMethodHandler | ||
*/ | ||
protected $handler; | ||
|
||
public function __construct(EnablePaymentMethodHandler $handler) | ||
{ | ||
parent::__construct(); | ||
$this->handler = $handler; | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this->setDescription('Finds the payment method according to given PM handler and enables it'); | ||
|
||
$this->addOption( | ||
'all', | ||
'A', | ||
InputOption::VALUE_NONE, | ||
'Enables all Adyen payment methods' | ||
); | ||
|
||
$this->addOption( | ||
'payment-method', | ||
'm', | ||
InputOption::VALUE_REQUIRED, | ||
'Enables given Adyen payment method' | ||
); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
try { | ||
$isAllSelected = $input->getOption('all'); | ||
$paymentMethodHandlerIdentifier = $input->getOption('payment-method'); | ||
|
||
if ($isAllSelected xor isset($paymentMethodHandlerIdentifier)) { | ||
$this->handler->run($isAllSelected, $paymentMethodHandlerIdentifier); | ||
$message = 'Payment method is enabled successfully.'; | ||
} else { | ||
throw new \Exception('Invalid parameter! For usage please check manual --help.'); | ||
} | ||
} catch (\Exception $e) { | ||
$message = $e->getMessage(); | ||
} | ||
|
||
$output->writeln($message); | ||
return 0; | ||
} | ||
} |
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,112 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* ###### | ||
* ###### | ||
* ############ ####( ###### #####. ###### ############ ############ | ||
* ############# #####( ###### #####. ###### ############# ############# | ||
* ###### #####( ###### #####. ###### ##### ###### ##### ###### | ||
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ###### | ||
* ###### ###### #####( ###### #####. ###### ##### ##### ###### | ||
* ############# ############# ############# ############# ##### ###### | ||
* ############ ############ ############# ############ ##### ###### | ||
* ###### | ||
* ############# | ||
* ############ | ||
* | ||
* Adyen Payment Module | ||
* | ||
* Copyright (c) 2022 Adyen N.V. | ||
* This file is open source and available under the MIT license. | ||
* See the LICENSE file for more info. | ||
* | ||
* Author: Adyen <[email protected]> | ||
*/ | ||
|
||
namespace Adyen\Shopware\Handlers\Command; | ||
|
||
use Adyen\Shopware\Provider\AdyenPluginProvider; | ||
use Shopware\Core\Framework\Context; | ||
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\ContainsFilter; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; | ||
|
||
class DisablePaymentMethodHandler | ||
{ | ||
/** | ||
* @var AdyenPluginProvider | ||
*/ | ||
private $adyenPluginProvider; | ||
|
||
/** | ||
* @var EntityRepositoryInterface | ||
*/ | ||
private $paymentMethodRepository; | ||
|
||
/** | ||
* @var EntityRepositoryInterface | ||
*/ | ||
private $salesChannelRepository; | ||
|
||
/** | ||
* @var EntityRepositoryInterface | ||
*/ | ||
private $salesChannelPaymentMethodRepository; | ||
|
||
public function __construct( | ||
AdyenPluginProvider $adyenPluginProvider, | ||
EntityRepositoryInterface $paymentMethodRepository, | ||
EntityRepositoryInterface $salesChannelRepository, | ||
EntityRepositoryInterface $salesChannelPaymentMethodRepository | ||
) { | ||
$this->adyenPluginProvider = $adyenPluginProvider; | ||
$this->paymentMethodRepository = $paymentMethodRepository; | ||
$this->salesChannelRepository = $salesChannelRepository; | ||
$this->salesChannelPaymentMethodRepository = $salesChannelPaymentMethodRepository; | ||
} | ||
|
||
public function run(bool $isAll, ?string $paymentMethodHandlerIdentifier): void | ||
{ | ||
$criteria = new Criteria(); | ||
$criteria->addFilter( | ||
new EqualsFilter('pluginId', $this->adyenPluginProvider->getAdyenPluginId()) | ||
); | ||
if (!$isAll) { | ||
$criteria->addFilter( | ||
new ContainsFilter('handlerIdentifier', $paymentMethodHandlerIdentifier) | ||
); | ||
} | ||
|
||
$paymentMethods = $this->paymentMethodRepository | ||
->search($criteria, Context::createDefaultContext()) | ||
->getEntities(); | ||
|
||
if (!count($paymentMethods->getElements())) { | ||
throw new \Exception('No payment methods found!'); | ||
} | ||
|
||
$criteria = new Criteria(); | ||
$salesChannels = $this->salesChannelRepository | ||
->searchIds($criteria, Context::createDefaultContext()) | ||
->getData(); | ||
|
||
echo "Following payment methods will be disabled: \n"; | ||
foreach ($paymentMethods->getElements() as $paymentMethod) { | ||
$paymentMethodName = $paymentMethod->getName(); | ||
echo "* $paymentMethodName \n"; | ||
|
||
foreach ($salesChannels as $salesChannel) { | ||
$this->disablePaymentMethod($paymentMethod->getId(), $salesChannel['id']); | ||
} | ||
} | ||
} | ||
|
||
private function disablePaymentMethod(string $paymentMethodId, string $salesChannelId) | ||
{ | ||
$this->salesChannelPaymentMethodRepository | ||
->delete( | ||
[['paymentMethodId' => $paymentMethodId, 'salesChannelId' => $salesChannelId]], | ||
Context::createDefaultContext() | ||
); | ||
} | ||
} |
Oops, something went wrong.