Skip to content

Commit

Permalink
Merge pull request #327 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 3.8.1
  • Loading branch information
peterojo authored Dec 5, 2022
2 parents 9c2b5a5 + 0b88683 commit baabae0
Show file tree
Hide file tree
Showing 16 changed files with 700 additions and 103 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"description": "Official Shopware 6 Plugin to connect to Payment Service Provider Adyen",
"version": "3.8.0",
"version": "3.8.1",
"type": "shopware-platform-plugin",
"license": "MIT",
"require": {
Expand Down
176 changes: 88 additions & 88 deletions composer.lock

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions src/Command/DisablePaymentMethodCommand.php
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;
}
}
86 changes: 86 additions & 0 deletions src/Command/EnablePaymentMethodCommand.php
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;
}
}
112 changes: 112 additions & 0 deletions src/Handlers/Command/DisablePaymentMethodHandler.php
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()
);
}
}
Loading

0 comments on commit baabae0

Please sign in to comment.