Skip to content

Commit

Permalink
Merge pull request #478 from Adyen/develop
Browse files Browse the repository at this point in the history
Release v3.15.0
  • Loading branch information
candemiralp authored May 15, 2024
2 parents a288925 + a8a59eb commit 7a032a2
Show file tree
Hide file tree
Showing 131 changed files with 2,279 additions and 1,496 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
}
],
"description": "Official Shopware 6 Plugin to connect to Payment Service Provider Adyen",
"version": "3.14.4",
"version": "3.15.0",
"type": "shopware-platform-plugin",
"license": "MIT",
"require": {
"shopware/core": "~6.4.0 || ~6.5.0",
"shopware/storefront": "~6.4.0 || ~6.5.0",
"adyen/php-api-library": "^15.0.0",
"adyen/php-api-library": "^17.5.0",
"adyen/php-webhook-module": "0.8.0",
"ext-json": "*"
},
Expand Down
204 changes: 98 additions & 106 deletions src/AdyenPaymentShopware6.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
use Adyen\Shopware\Entity\Notification\NotificationEntityDefinition;
use Adyen\Shopware\Entity\PaymentResponse\PaymentResponseEntityDefinition;
use Adyen\Shopware\Entity\PaymentStateData\PaymentStateDataEntityDefinition;
use Adyen\Shopware\Handlers\GenericGiftCardPaymentMethodHandler;
use Adyen\Shopware\PaymentMethods;
use Adyen\Shopware\Service\ConfigurationService;
use Shopware\Core\Checkout\Payment\PaymentMethodEntity;
use Shopware\Core\Framework\Plugin;
Expand All @@ -46,7 +44,6 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Doctrine\DBAL\Connection;
use Shopware\Core\System\SalesChannel\SalesChannelEntity;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AdyenPaymentShopware6 extends Plugin
{
Expand Down Expand Up @@ -154,10 +151,6 @@ public function update(UpdateContext $updateContext): void
$this->updateTo300($updateContext);
}

if (\version_compare($currentVersion, '3.1.0', '<')) {
$this->updateTo310($updateContext);
}

if (\version_compare($currentVersion, '3.2.0', '<')) {
$this->updateTo320($updateContext);
}
Expand All @@ -173,6 +166,10 @@ public function update(UpdateContext $updateContext): void
if (\version_compare($currentVersion, '3.10.0', '<')) {
$this->updateTo3100($updateContext);
}

if (\version_compare($currentVersion, '3.15.0', '<')) {
$this->updateTo3150($updateContext);
}
}

private function addPaymentMethod(PaymentMethods\PaymentMethodInterface $paymentMethod, Context $context): void
Expand Down Expand Up @@ -388,113 +385,16 @@ private function updateTo300(UpdateContext $updateContext): void
}
}

private function updateTo310(UpdateContext $updateContext): void
{
//Version 3.1.0 introduces gift cards
foreach ([
new PaymentMethods\GivexGiftCardPaymentMethod,
new PaymentMethods\WebshopGiftCardPaymentMethod,
new PaymentMethods\KadowereldGiftCardPaymentMethod,
new PaymentMethods\TCSTestGiftCardPaymentMethod,
new PaymentMethods\AlbelliGiftCardPaymentMethod,
new PaymentMethods\BijenkorfGiftCardPaymentMethod,
new PaymentMethods\VVVGiftCardPaymentMethod,
new PaymentMethods\GallGallGiftCardPaymentMethod,
new PaymentMethods\HunkemollerLingerieGiftCardPaymentMethod,
new PaymentMethods\BeautyGiftCardPaymentMethod,
new PaymentMethods\SVSGiftCardPaymentMethod,
] as $method) {
$this->addPaymentMethod(
$method,
$updateContext->getContext()
);
$this->setPaymentMethodIsActive(
true,
$updateContext->getContext(),
$method
);
}
}

/**
* This update will add FashionCheque and DeCadeaukaart
* It will also set Savvy to inactive, add it as GenericGiftCard.
* It will also remove all links of Savvy payment_method in sales_channel_payment_method and recreate these links
* for the new payment method
*
* @param UpdateContext $updateContext
*/
private function updateTo320(UpdateContext $updateContext): void
{
foreach ([
new PaymentMethods\FashionChequeGiftCardPaymentMethod(),
new PaymentMethods\DeCadeaukaartGiftCardPaymentMethod(),
new PaymentMethods\GenericGiftCardPaymentMethod()
] as $method) {
$this->addPaymentMethod(
$method,
$updateContext->getContext()
);
$this->setPaymentMethodIsActive(
true,
$updateContext->getContext(),
$method
);
}

// Set the Savvy payment method to inactive
/** @var EntityRepository $paymentRepository */
$paymentRepository = $this->container->get('payment_method.repository');
$salesChannelPaymentRepository = $this->container->get('sales_channel_payment_method.repository');
$savvyPaymentMethodId = $this->getPaymentMethodId(
'Adyen\Shopware\Handlers\SavvyGiftCardPaymentMethodHandler'
);
// If savvy payment method is not found, return
if (!$savvyPaymentMethodId) {
return;
}
$paymentMethodData = [
'id' => $savvyPaymentMethodId,
'active' => false
];

// Set the savvy payment method to inactive
$paymentRepository->update([$paymentMethodData], $updateContext->getContext());

$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('id', $savvyPaymentMethodId));
$criteria->addAssociation('salesChannels');

/** @var PaymentMethodEntity $savvyPaymentMethod */
$savvyPaymentMethod = $paymentRepository->search($criteria, $updateContext->getContext())->first();

$genericPaymentMethodId = $this->getPaymentMethodId(
GenericGiftCardPaymentMethodHandler::class
);

$salesChannelIds = [];
$salesChannels = $savvyPaymentMethod->getSalesChannels();

if (count($salesChannels) > 0) {
/** @var SalesChannelEntity $savvySalesChannel */
foreach ($savvyPaymentMethod->getSalesChannels() as $savvySalesChannel) {
$salesChannelIds[] = ['id' => $savvySalesChannel->getId()];
$salesChannelPaymentRepository->delete([
[
'salesChannelId' => $savvySalesChannel->getId(),
'paymentMethodId' => $savvyPaymentMethodId
]
], $updateContext->getContext());
}

// Add new Generic giftcard links to the sales channel
$paymentRepository->update([
[
'id' => $genericPaymentMethodId,
'salesChannels' => $salesChannelIds
]
], $updateContext->getContext());
}
$paymentMethodHandler = 'Adyen\Shopware\Handlers\SavvyGiftCardPaymentMethodHandler';
$this->deactivateAndRemovePaymentMethod($updateContext, $paymentMethodHandler);
}

private function updateTo350(UpdateContext $updateContext): void
Expand Down Expand Up @@ -564,6 +464,43 @@ private function updateTo3100(UpdateContext $updateContext): void
}
}

private function updateTo3150(UpdateContext $updateContext): void
{
//Version 3.15.0 introduces MultiGiftcards
$this->addPaymentMethod(
new PaymentMethods\GiftCardPaymentMethod(),
$updateContext->getContext()
);
$this->setPaymentMethodIsActive(
true,
$updateContext->getContext(),
new PaymentMethods\GiftcardPaymentMethod()
);

$deprecatedGiftcardMethods = [
'Adyen\Shopware\Handlers\AlbelliGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\BeautyGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\BijenkorfGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\DeCadeaukaartGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\FashionChequeGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\GallGallGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\GenericGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\GivexGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\HunkemollerLingerieGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\KadowereldGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\SVSGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\TCSTestGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\VVVGiftCardPaymentMethodHandler',
'Adyen\Shopware\Handlers\WebshopGiftCardPaymentMethodHandler'
];

// Disable deprecated gift card payment methods
foreach ($deprecatedGiftcardMethods as $deprecatedGiftcardMethod) {
$description = '@deprecated DO NOT ACTIVATE, use GiftCard instead';
$this->deactivateAndRemovePaymentMethod($updateContext, $deprecatedGiftcardMethod, $description);
}
}

private function safeCopyAsset($source, $destination): bool
{
try {
Expand All @@ -572,6 +509,61 @@ private function safeCopyAsset($source, $destination): bool
return false;
}
}

/**
* @param UpdateContext $updateContext
* @param string $paymentMethodHandler
* @param string|null $description
* @return void
*/
private function deactivateAndRemovePaymentMethod(
UpdateContext $updateContext,
string $paymentMethodHandler,
string $description = null
): void {
/** @var EntityRepository $paymentRepository */
$paymentRepository = $this->container->get('payment_method.repository');
/** @var EntityRepository $salesChannelPaymentRepository */
$salesChannelPaymentRepository = $this->container->get('sales_channel_payment_method.repository');

$paymentMethodId = $this->getPaymentMethodId($paymentMethodHandler);
// If payment method is not found, return
if (!$paymentMethodId) {
return;
}
$paymentMethodData = [
'id' => $paymentMethodId,
'active' => false
];

// Update description as deprecation message
if (isset($description)) {
$paymentMethodData['description'] = $description;
}

// Set the payment method to inactive
$paymentRepository->update([$paymentMethodData], $updateContext->getContext());

$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('id', $paymentMethodId));
$criteria->addAssociation('salesChannels');

/** @var PaymentMethodEntity $paymentMethod */
$paymentMethod = $paymentRepository->search($criteria, $updateContext->getContext())->first();
$salesChannels = $paymentMethod->getSalesChannels();

if (count($salesChannels) > 0) {
/** @var SalesChannelEntity $savvySalesChannel */
foreach ($paymentMethod->getSalesChannels() as $savvySalesChannel) {
$salesChannelPaymentRepository->delete([
[
'salesChannelId' => $savvySalesChannel->getId(),
'paymentMethodId' => $paymentMethodId
]
], $updateContext->getContext());
}
}
}
}

if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
Expand Down
16 changes: 8 additions & 8 deletions src/Command/DisablePaymentMethodCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace Adyen\Shopware\Command;

use Adyen\Shopware\Handlers\Command\DisablePaymentMethodHandler;
use Adyen\Shopware\Handlers\Command\PaymentMethodStatusHandler;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -35,17 +35,17 @@ class DisablePaymentMethodCommand extends Command
protected static $defaultName = 'adyen:payment-method:disable';

/**
* @var DisablePaymentMethodHandler
* @var PaymentMethodStatusHandler
*/
protected $handler;
protected PaymentMethodStatusHandler $handler;

public function __construct(DisablePaymentMethodHandler $handler)
public function __construct(PaymentMethodStatusHandler $handler)
{
parent::__construct();
$this->handler = $handler;
}

protected function configure()
protected function configure(): void
{
$this->setDescription('Finds the payment method according to given PM handler and disables it');

Expand All @@ -64,14 +64,14 @@ protected function configure()
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$isAllSelected = $input->getOption('all');
$paymentMethodHandlerIdentifier = $input->getOption('payment-method');

if ($isAllSelected xor isset($paymentMethodHandlerIdentifier)) {
$this->handler->run($isAllSelected, $paymentMethodHandlerIdentifier);
$this->handler->run($isAllSelected, false, $paymentMethodHandlerIdentifier);
$message = 'Payment method is disabled successfully.';
} else {
throw new \Exception('Invalid parameter! For usage please check manual --help.');
Expand All @@ -81,6 +81,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$output->writeln($message);
return 0;
return Command::SUCCESS;
}
}
16 changes: 8 additions & 8 deletions src/Command/EnablePaymentMethodCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace Adyen\Shopware\Command;

use Adyen\Shopware\Handlers\Command\EnablePaymentMethodHandler;
use Adyen\Shopware\Handlers\Command\PaymentMethodStatusHandler;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -35,17 +35,17 @@ class EnablePaymentMethodCommand extends Command
protected static $defaultName = 'adyen:payment-method:enable';

/**
* @var EnablePaymentMethodHandler
* @var PaymentMethodStatusHandler
*/
protected $handler;
protected PaymentMethodStatusHandler $handler;

public function __construct(EnablePaymentMethodHandler $handler)
public function __construct(PaymentMethodStatusHandler $handler)
{
parent::__construct();
$this->handler = $handler;
}

protected function configure()
protected function configure(): void
{
$this->setDescription('Finds the payment method according to given PM handler and enables it');

Expand All @@ -64,14 +64,14 @@ protected function configure()
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$isAllSelected = $input->getOption('all');
$paymentMethodHandlerIdentifier = $input->getOption('payment-method');

if ($isAllSelected xor isset($paymentMethodHandlerIdentifier)) {
$this->handler->run($isAllSelected, $paymentMethodHandlerIdentifier);
$this->handler->run($isAllSelected, true, $paymentMethodHandlerIdentifier);
$message = 'Payment method is enabled successfully.';
} else {
throw new \Exception('Invalid parameter! For usage please check manual --help.');
Expand All @@ -81,6 +81,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$output->writeln($message);
return 0;
return Command::SUCCESS;
}
}
Loading

0 comments on commit 7a032a2

Please sign in to comment.