Skip to content

Commit

Permalink
Update adyen payment module and fix maintenance mode issue for oxid 7
Browse files Browse the repository at this point in the history
  • Loading branch information
maexware-danny committed Jan 17, 2024
1 parent 0f59abc commit b5caccf
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 64 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.1.2] - 2024-01-16

- [0007569](https://bugs.oxid-esales.com/view.php?id=7569): Fix Maintenance Mode after entering Sandbox Data


## [2.1.1] - 2023-??-??

- Split Version for OXID 7
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class Module
{
public const MODULE_NAME_DE = 'Adyen Payment für OXID';
public const MODULE_NAME_EN = 'Adyen Payment for OXID';
public const MODULE_VERSION = '2.1.1.rc.1';
public const MODULE_VERSION = '2.1.2.rc.1';
public const MODULE_VERSION_FULL = self::MODULE_VERSION . ' SDK-Version ' . self::ADYEN_SDK_VERSION;
public const MODULE_PLATFORM_NAME = 'OXID';
public const MODULE_PLATFORM_VERSION = '1.0';
Expand Down
178 changes: 128 additions & 50 deletions src/Core/ViewConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use OxidSolutionCatalysts\Adyen\Service\CountryRepository;
use OxidSolutionCatalysts\Adyen\Service\ModuleSettings;
use OxidSolutionCatalysts\Adyen\Service\PaymentMethods;
use OxidSolutionCatalysts\Adyen\Service\SessionSettings;
use OxidSolutionCatalysts\Adyen\Service\UserRepository;
use OxidSolutionCatalysts\Adyen\Traits\AdyenPayment;
use OxidSolutionCatalysts\Adyen\Traits\Json;
Expand All @@ -38,35 +37,29 @@ class ViewConfig extends ViewConfig_parent
use ServiceContainer;
use AdyenPayment;

protected ModuleSettings $moduleSettings;
protected Context $context;
protected PaymentMethods $adyenPaymentMethods;
protected CountryRepository $countryRepository;
protected SessionSettings $sessionSettings;
protected ?ModuleSettings $adyenModuleSettings = null;
protected ?Context $adyenContext = null;
protected ?PaymentMethods $adyenPaymentMethods = null;

/**
* @inheritDoc
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __construct()
public function getAdyen(): bool
{
parent::__construct();

$this->moduleSettings = $this->getServiceFromContainer(ModuleSettings::class);
$this->context = $this->getServiceFromContainer(Context::class);
$this->adyenPaymentMethods = $this->getServiceFromContainer(PaymentMethods::class);
$this->countryRepository = $this->getServiceFromContainer(CountryRepository::class);
$this->sessionSettings = $this->getServiceFromContainer(SessionSettings::class);
return $this->getModuleSettingsSrvc()->checkConfigHealth();
}

/**
* @throws AdyenException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function checkAdyenHealth(): bool
{
$isHealthy = false;

try {
$isHealthy = $this->moduleSettings->checkConfigHealth() && $this->existsAdyenPaymentMethods();
$isHealthy = $this->getModuleSettingsSrvc()->checkConfigHealth() && $this->existsAdyenPaymentMethods();
} catch (AdyenException $exception) {
$this->getServiceFromContainer(LoggerInterface::class)->error(
'ViewConfig::checkAdyenHealth could not prove existsAdyenPaymentMethods because of exception',
Expand All @@ -77,49 +70,85 @@ public function checkAdyenHealth(): bool
return $isHealthy;
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function checkAdyenConfigHealth(): bool
{
return $this->moduleSettings->checkConfigHealth();
return $this->getModuleSettingsSrvc()->checkConfigHealth();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getAdyenOperationMode(): string
{
return $this->moduleSettings->getOperationMode();
return $this->getModuleSettingsSrvc()->getOperationMode();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getGooglePayOperationMode(): string
{
return $this->moduleSettings->getGooglePayOperationMode();
return $this->getModuleSettingsSrvc()->getGooglePayOperationMode();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function isAdyenLoggingActive(): bool
{
return $this->moduleSettings->isLoggingActive();
return $this->getModuleSettingsSrvc()->isLoggingActive();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function isAdyenAnalyticsActive(): bool
{
return $this->moduleSettings->isAnalyticsActive();
return $this->getModuleSettingsSrvc()->isAnalyticsActive();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function isAdyenSandboxMode(): bool
{
return $this->moduleSettings->isSandBoxMode();
return $this->getModuleSettingsSrvc()->isSandBoxMode();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getAdyenClientKey(): string
{
return $this->moduleSettings->getClientKey();
return $this->getModuleSettingsSrvc()->getClientKey();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getAdyenPayPalMerchantId(): string
{
return $this->moduleSettings->getPayPalMerchantId();
return $this->getModuleSettingsSrvc()->getPayPalMerchantId();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getAdyenMerchantAccount(): string
{
return $this->moduleSettings->getMerchantAccount();
return $this->getModuleSettingsSrvc()->getMerchantAccount();
}

public function getAdyenSDKVersion(): string
Expand Down Expand Up @@ -177,26 +206,34 @@ public function getAdyenErrorInvalidSession(): string
return Module::ADYEN_ERROR_INVALIDSESSION_NAME;
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getWebhookControllerUrl(): string
{
return $this->context->getWebhookControllerUrl();
return $this->getContextSrvc()->getWebhookControllerUrl();
}

/**
* @throws AdyenException
* @throws Exception
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getAdyenPaymentMethods(): array
{
return $this->adyenPaymentMethods->getAdyenPaymentMethods();
return $this->getPaymentMethodsSrvc()->getAdyenPaymentMethods();
}

/**
* @throws AdyenException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function existsAdyenPaymentMethods(): bool
{
return (bool)count($this->adyenPaymentMethods->getAdyenPaymentMethods());
return (bool)count($this->getPaymentMethodsSrvc()->getAdyenPaymentMethods());
}

/**
Expand All @@ -208,27 +245,44 @@ public function getAdyenShopperLocale(): string
return $this->getServiceFromContainer(UserRepository::class)->getUserLocale();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getAdyenCountryIso(): string
{
return $this->countryRepository->getCountryIso();
return $this->getServiceFromContainer(CountryRepository::class)
->getCountryIso();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getAdyenAmountValue(): string
{
/** @var Basket $basket */
$basket = Registry::getSession()->getBasket();
$amount = $basket->getPrice()->getBruttoPrice();
return $this->getAdyenAmount(
$amount,
$this->context->getActiveCurrencyDecimals()
$this->getContextSrvc()->getActiveCurrencyDecimals()
);
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getAdyenAmountCurrency(): string
{
return $this->context->getActiveCurrencyName();
return $this->getContextSrvc()->getActiveCurrencyName();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getTemplateConfiguration(
FrontendController $oView,
?Payment $payment
Expand All @@ -237,14 +291,10 @@ public function getTemplateConfiguration(
->getConfiguration($this, $oView, $payment);
}

public function isApplePay(
FrontendController $oView,
?Payment $payment
): bool {
return $this->getServiceFromContainer(JSAPITemplateConfiguration::class)
->isApplePay($oView, $payment);
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getTemplateCheckoutCreateId(?Payment $payment): string
{
return $payment ? $this->getServiceFromContainer(JSAPITemplateCheckoutCreate::class)
Expand All @@ -253,17 +303,9 @@ public function getTemplateCheckoutCreateId(?Payment $payment): string
}

/**
* added for apex theme to verify whether checkout submit button needs to be overwritten
* @param Payment|null $payment
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function hasTemplateCheckoutCreateId(?Payment $payment): bool
{
return $this->getServiceFromContainer(JSAPITemplateCheckoutCreate::class)
->getCreateId($payment->getId())
!== 'no_create_id_found';
}

public function getGooglePayTransactionInfo(): string
{
return $this->getServiceFromContainer(AdyenAPITransactionInfoService::class)
Expand All @@ -274,4 +316,40 @@ public function getTemplatePayButtonContainerId(?Payment $payment): string
{
return $payment ? $payment->getId() . '-container' : '';
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getModuleSettingsSrvc(): ModuleSettings
{
if (is_null($this->adyenModuleSettings)) {
$this->adyenModuleSettings = $this->getServiceFromContainer(ModuleSettings::class);
}
return $this->adyenModuleSettings;
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function getContextSrvc(): Context
{
if (is_null($this->adyenContext)) {
$this->adyenContext = $this->getServiceFromContainer(Context::class);
}
return $this->adyenContext;
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function getPaymentMethodsSrvc(): PaymentMethods
{
if (is_null($this->adyenPaymentMethods)) {
$this->adyenPaymentMethods = $this->getServiceFromContainer(PaymentMethods::class);
}
return $this->adyenPaymentMethods;
}
}
26 changes: 13 additions & 13 deletions src/Model/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use OxidSolutionCatalysts\Adyen\Traits\DataGetter;
use OxidSolutionCatalysts\Adyen\Traits\ServiceContainer;
use OxidSolutionCatalysts\Adyen\Service\Module as ModuleService;
use OxidSolutionCatalysts\Adyen\Core\Module as CoreModule;

/**
*
Expand All @@ -24,21 +23,12 @@ class Payment extends Payment_parent
use ServiceContainer;
use DataGetter;

private PaymentConfigService $paymentConfigService;

public function __construct()
{
parent::__construct();

$this->paymentConfigService = $this->getServiceFromContainer(PaymentConfigService::class);
}

/**
* Checks if the payment method is an Adyen payment method
*/
public function isAdyenPayment(): bool
{
return $this->paymentConfigService->isAdyenPayment($this->getId());
return $this->getAdyenPaymentConfigService()->isAdyenPayment($this->getId());
}

/**
Expand Down Expand Up @@ -68,14 +58,24 @@ public function showInOrderCtrl(): bool
*/
public function isAdyenManualCapture(): bool
{
return $this->paymentConfigService->isAdyenManualCapture($this->getId());
return $this->getAdyenPaymentConfigService()->isAdyenManualCapture($this->getId());
}

/**
* Checks if the payment allow immediate Capture
*/
public function isAdyenImmediateCapture(): bool
{
return $this->paymentConfigService->isAdyenImmediateCapture($this->getId());
return $this->getAdyenPaymentConfigService()->isAdyenImmediateCapture($this->getId());
}

/**
* get the PaymentConfigService.
* Normally this could be in the constructor. This model is used when the module is activated
* and the services are not yet available at that moment. That's why it's outsourced here.
*/
protected function getAdyenPaymentConfigService(): PaymentConfigService
{
return $this->getServiceFromContainer(PaymentConfigService::class);
}
}

0 comments on commit b5caccf

Please sign in to comment.