Skip to content

Commit

Permalink
Merge pull request #355 from OXID-eSales/b-7.0.x-PSPAYPAL-800-takeove…
Browse files Browse the repository at this point in the history
…r-PSPAYPAL-788

B 7.0.x pspaypal 800 takeover pspaypal 788
  • Loading branch information
mariolorenz authored Oct 17, 2024
2 parents ae02895 + b84ef89 commit 8d0cea0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 47 deletions.
93 changes: 50 additions & 43 deletions src/Core/Events/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
namespace OxidSolutionCatalysts\PayPal\Core\Events;

use OxidEsales\DoctrineMigrationWrapper\MigrationsBuilder;
use OxidEsales\Eshop\Core\Field;
use OxidEsales\Eshop\Application\Model\Payment as EshopModelPayment;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleConfigurationDaoBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleSettingBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;
use OxidSolutionCatalysts\PayPal\Core\PayPalDefinitions;
use OxidSolutionCatalysts\PayPal\Service\Logger;
use OxidSolutionCatalysts\PayPal\Service\ModuleSettings;
use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer;
Expand Down Expand Up @@ -81,8 +80,10 @@ private static function executeModuleMigrations(): void
private static function addStaticContents(): void
{
$service = self::getStaticContentService();
$service->ensureStaticContents();
$service->ensurePayPalPaymentMethods();
if ($service) {
$service->ensureStaticContents();
$service->ensurePayPalPaymentMethods();
}
}

/**
Expand All @@ -91,14 +92,12 @@ private static function addStaticContents(): void
private static function addRequireSession(): void
{
$service = self::getModuleSettingsService();
$service->addRequireSession();
if ($service) {
$service->addRequireSession();
}
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
private static function getStaticContentService(): StaticContent
private static function getStaticContentService(): ?StaticContent
{
/*
Normally I would fetch the StaticContents service like this:
Expand All @@ -111,24 +110,25 @@ private static function getStaticContentService(): StaticContent
That's why I build the containers by hand as an exception.:
*/

/** @var ContainerInterface $container */
$container = ContainerFactory::getInstance()
->getContainer();
/** @var QueryBuilderFactoryInterface $queryBuilderFactory */
$queryBuilderFactory = $container->get(QueryBuilderFactoryInterface::class);
$moduleSettings = self::getModuleSettingsService();

return new StaticContent(
$queryBuilderFactory,
$moduleSettings
);
try {
/** @var ContainerInterface $container */
$container = ContainerFactory::getInstance()
->getContainer();
/** @var QueryBuilderFactoryInterface $queryBuilderFactory */
$queryBuilderFactory = $container->get(QueryBuilderFactoryInterface::class);
$moduleSettings = self::getModuleSettingsService();

return new StaticContent(
$queryBuilderFactory,
$moduleSettings
);
} catch (NotFoundExceptionInterface | ContainerExceptionInterface $e) {
Registry::getUtilsView()->addErrorToDisplay('OSC_PAYPAL_INSTALLPROCESS_FAILED');
return null;
}
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
private static function getModuleSettingsService(): ModuleSettings
private static function getModuleSettingsService(): ?ModuleSettings
{
/*
Normally I would fetch the StaticContents service like this:
Expand All @@ -141,22 +141,29 @@ private static function getModuleSettingsService(): ModuleSettings
That's why I build the containers by hand as an exception.:
*/

/** @var ContainerInterface $container */
$container = ContainerFactory::getInstance()
->getContainer();
/** @var ModuleSettingBridgeInterface $moduleSettingsBridge */
$moduleSettingsBridge = $container->get(ModuleSettingBridgeInterface::class);
/** @var ContextInterface $context */
$context = $container->get(ContextInterface::class);
/** @var ModuleConfigurationDaoBridgeInterface $moduleConfigurationDaoBridgeInterface */
$moduleConfigurationDaoBridgeInterface = $container->get(ModuleConfigurationDaoBridgeInterface::class);
/** @var Logger $logger */
$logger = $container->get(Logger::class);
return new ModuleSettings(
$moduleSettingsBridge,
$context,
$moduleConfigurationDaoBridgeInterface,
$logger
);
try {
/** @var ContainerInterface $container */
$container = ContainerFactory::getInstance()
->getContainer();
/** @var ModuleSettingBridgeInterface $moduleSettingsBridge */
$moduleSettingsBridge = $container->get(ModuleSettingBridgeInterface::class);
/** @var ContextInterface $context */
$context = $container->get(ContextInterface::class);
/** @var ModuleConfigurationDaoBridgeInterface $moduleConfigurationDaoBridgeInterface */
$moduleConfigurationDaoBridgeInterface = $container->get(ModuleConfigurationDaoBridgeInterface::class);
/** @var Logger $logger */
$logger = $container->get(Logger::class);

return new ModuleSettings(
$moduleSettingsBridge,
$context,
$moduleConfigurationDaoBridgeInterface,
$logger
);
} catch (NotFoundExceptionInterface | ContainerExceptionInterface $exception) {
Registry::getUtilsView()->addErrorToDisplay('OSC_PAYPAL_INSTALLPROCESS_FAILED');
Registry::getLogger()->error($exception->getMessage(), [$exception]);
return null;
}
}
}
3 changes: 1 addition & 2 deletions views/de/admin_translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,5 @@
Kaufabwicklung ermöglichen. Mit ihren gespeicherten Zahlungsdaten können Kund:innen mit nur wenigen Klicks Wiederholungskäufe tätigen. Dies kann für Sie
eine höhere Checkout-Conversion bedeuten.',

// PayPal Payment
'OSC_PAYPAL_PAYMENT_DEPRECATED' => 'Diese PayPal Zahlungsart kann nicht mehr aktiviert werden, da diese demnächst entfernt wird!',
'OSC_PAYPAL_INSTALLPROCESS_FAILED' => 'Da das Modul nicht korrekt per Composer installiert ist, sind Fehler bei der (De-)Aktivierung des Moduls aufgetreten. Bitte installieren Sie das Modul via Composer frisch und wiederholen den Vorgang.',
];
3 changes: 1 addition & 2 deletions views/en/admin_translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,5 @@
Enable purchase processing. With their saved payment details, customers can make repeat purchases with just a few clicks. This can be for you
mean higher checkout conversion.',

// PayPal Payment
'OSC_PAYPAL_PAYMENT_DEPRECATED' => 'This PayPal payment method can no longer be activated as it will be removed soon!',
'OSC_PAYPAL_INSTALLPROCESS_FAILED' => 'Because the module was not installed correctly via Composer, errors occurred during the (de)activation of the module. Please reinstall the module via composer and repeat the process.',
];

0 comments on commit 8d0cea0

Please sign in to comment.