Skip to content

Commit

Permalink
Merge pull request #133 from OXID-eSales/AM-132-move-acdc-input
Browse files Browse the repository at this point in the history
AM-132 - Move Adyen Credit Card Input into last order step
  • Loading branch information
mariolorenz authored Oct 15, 2024
2 parents 47af560 + c15d247 commit efee424
Show file tree
Hide file tree
Showing 25 changed files with 127 additions and 190 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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/).

## [1.1.7] - 2024-??-??

### NEW
- Creditcard-Fields move from Payment-Controller to the Order-Controller.

### FIX
- Fix URLs with real slashes instead of DIRECTORY_SEPERATOR

## [1.1.6] - 2024-06-21

- add new Webhookhandler "refund failed" & "report available"
Expand Down
6 changes: 0 additions & 6 deletions metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
'osc_adyen_order.tpl' => 'osc/adyen/views/admin/tpl/osc_adyen_order.tpl',
// frontend - paymentpage
'modules/osc/adyen/payment/adyen_assets.tpl' => 'osc/adyen/views/frontend/tpl/payment/adyen_assets.tpl',
'modules/osc/adyen/payment/adyen_payment.tpl' => 'osc/adyen/views/frontend/tpl/payment/adyen_payment.tpl',
'modules/osc/adyen/payment/adyen_payment_inauthorisation.tpl' => 'osc/adyen/views/frontend/tpl/payment/adyen_payment_inauthorisation.tpl',
'modules/osc/adyen/payment/adyen_payment_psp.tpl' => 'osc/adyen/views/frontend/tpl/payment/adyen_payment_psp.tpl',
// frontend - orderpage
Expand All @@ -97,11 +96,6 @@
'block' => 'select_payment',
'file' => 'views/frontend/blocks/page/checkout/select_payment.tpl'
],
[
'template' => 'page/checkout/payment.tpl',
'block' => 'checkout_payment_main',
'file' => 'views/frontend/blocks/page/checkout/checkout_payment_main.tpl'
],
[
'template' => 'page/checkout/payment.tpl',
'block' => 'checkout_payment_nextstep',
Expand Down
23 changes: 23 additions & 0 deletions src/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
namespace OxidSolutionCatalysts\Adyen\Controller;

use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Application\Controller\PaymentController;
use OxidSolutionCatalysts\Adyen\Model\Payment;
use OxidSolutionCatalysts\Adyen\Service\OxNewService;
use OxidSolutionCatalysts\Adyen\Service\TranslationMapper;
use OxidSolutionCatalysts\Adyen\Service\OrderReturnService;
use OxidSolutionCatalysts\Adyen\Traits\ServiceContainer;
Expand Down Expand Up @@ -49,4 +52,24 @@ public function return(): ?string

return null;
}

/*
* before the adyen credit card payment can be finalized,
* it needs to be validated because this step is skipped for this payment type
*/
public function execute()
{
/** @var Payment $payment */
$payment = $this->getPayment();
if ($payment->isAdyenCreditCardPayment()) {
$oxNewService = $this->getServiceFromContainer(OxNewService::class);
$paymentController = $oxNewService->oxNew(PaymentController::class);

if ($paymentController->validatePayment() !== "order") {
Registry::getUtils()->redirect(Registry::getConfig()->getShopHomeUrl() . 'cl=payment');
}
}

return parent::execute();
}
}
40 changes: 16 additions & 24 deletions src/Controller/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OxidSolutionCatalysts\Adyen\Model\Payment as AdyenPayment;
use OxidSolutionCatalysts\Adyen\Service\CountryRepository;
use OxidSolutionCatalysts\Adyen\Service\PaymentCancel;
use OxidSolutionCatalysts\Adyen\Service\PaymentConfigService;
use OxidSolutionCatalysts\Adyen\Service\SessionSettings;
use OxidSolutionCatalysts\Adyen\Traits\RequestGetter;
use OxidSolutionCatalysts\Adyen\Service\ModuleSettings;
Expand Down Expand Up @@ -76,25 +77,6 @@ public function getPaymentList()
return $paymentList;
}

public function isAdyenAssetsNecessary(): bool
{
if (is_null($this->assetsNecessary)) {
$this->assetsNecessary = false;
$paymentList = $this->getPaymentList();
if (is_array($paymentList)) {
foreach ($paymentList as $paymentObj) {
/** @var AdyenPayment $paymentObj */
if ($paymentObj->showInPaymentCtrl()) {
$this->assetsNecessary = true;
break;
}
}
}
$this->assetsNecessary = $this->assetsNecessary && !$this->isValidAdyenAuthorisation();
}
return $this->assetsNecessary;
}

public function isActiveAdyenSession(): bool
{
/** @var SessionSettings $session */
Expand Down Expand Up @@ -133,15 +115,20 @@ public function getPaymentError()
public function validatePayment()
{
$session = $this->getServiceFromContainer(SessionSettings::class);
$moduleService = $this->getServiceFromContainer(ModuleService::class);
$actualPaymentId = $session->getPaymentId();
$newPaymentId = $this->getStringRequestData('paymentid');
$pspReference = $session->getPspReference();
$moduleService = $this->getServiceFromContainer(ModuleService::class);
$actualPaymentId = $session->getPaymentId();
$newPaymentId = $this->getStringRequestData('paymentid');
$pspReference = $session->getPspReference();

// if the payment is adyen credit card, it will be validated
// from the order step where a new paymentId is impossible
$isAdyenCreditCard = $this->getAdyenPaymentConfigService()->isAdyenCreditCardPayment($actualPaymentId);
$paymentChanged = !$isAdyenCreditCard && ($actualPaymentId !== $newPaymentId);

// remove a possible old adyen payment if another one was selected
if (
$actualPaymentId &&
$actualPaymentId !== $newPaymentId &&
$paymentChanged &&
$moduleService->isAdyenPayment($actualPaymentId)
) {
$this->removeAdyenPaymentFromSession();
Expand Down Expand Up @@ -208,4 +195,9 @@ protected function removeAdyenPaymentFromSession(): void
$session->deletePaymentSession();
}
}

protected function getAdyenPaymentConfigService(): PaymentConfigService
{
return $this->getServiceFromContainer(PaymentConfigService::class);
}
}
10 changes: 1 addition & 9 deletions 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 = '1.1.6';
public const MODULE_VERSION = '1.1.7-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 Expand Up @@ -105,7 +105,6 @@ final class Module
'constraints' => self::PAYMENT_CONSTRAINTS,
'sort' => -1,
'capturedelay' => true,
'paymentCtrl' => true,
'handleAssets' => true,
],
self::PAYMENT_PAYPAL_ID => [
Expand All @@ -126,7 +125,6 @@ final class Module
'constraints' => self::PAYMENT_CONSTRAINTS,
'sort' => 0,
'capturedelay' => true,
'paymentCtrl' => false,
'handleAssets' => false,
],
self::PAYMENT_GOOGLE_PAY_ID => [
Expand All @@ -147,7 +145,6 @@ final class Module
'constraints' => self::PAYMENT_CONSTRAINTS,
'sort' => 0,
'capturedelay' => true,
'paymentCtrl' => false,
'handleAssets' => false,
],
self::PAYMENT_KLARNA_LATER_ID => [
Expand All @@ -168,7 +165,6 @@ final class Module
'constraints' => self::PAYMENT_CONSTRAINTS,
'sort' => 0,
'capturedelay' => true,
'paymentCtrl' => false,
'handleAssets' => false,
],
self::PAYMENT_KLARNA_OVER_TIME_ID => [
Expand All @@ -189,7 +185,6 @@ final class Module
'constraints' => self::PAYMENT_CONSTRAINTS,
'sort' => 0,
'capturedelay' => true,
'paymentCtrl' => false,
'handleAssets' => false,
],
self::PAYMENT_KLARNA_IMMEDIATE_ID => [
Expand All @@ -210,7 +205,6 @@ final class Module
'constraints' => self::PAYMENT_CONSTRAINTS,
'sort' => 0,
'capturedelay' => true,
'paymentCtrl' => false,
'handleAssets' => false,
],
self::PAYMENT_TWINT_ID => [
Expand All @@ -231,7 +225,6 @@ final class Module
'constraints' => self::PAYMENT_CONSTRAINTS,
'sort' => 0,
'capturedelay' => true,
'paymentCtrl' => false,
'handleAssets' => false,
'supported_currencies' => ['CHF'],
],
Expand All @@ -253,7 +246,6 @@ final class Module
'constraints' => self::PAYMENT_CONSTRAINTS,
'sort' => 0,
'capturedelay' => true,
'paymentCtrl' => false,
'handleAssets' => true,
],
];
Expand Down
12 changes: 8 additions & 4 deletions src/Core/Webhook/Handler/WebhookHandlerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OxidSolutionCatalysts\Adyen\Model\AdyenHistoryList;
use OxidSolutionCatalysts\Adyen\Model\Order as AdyenModel;
use OxidSolutionCatalysts\Adyen\Service\Context;
use OxidSolutionCatalysts\Adyen\Service\OxNewService;
use OxidSolutionCatalysts\Adyen\Traits\ServiceContainer;
use Psr\Log\LoggerInterface;

Expand All @@ -40,10 +41,12 @@ public function __construct(
?AdyenHistoryList $adyenHistoryList = null,
?Context $context = null
) {
$oxNewService = $this->getServiceFromContainer(OxNewService::class);

// whether getting mock objects from unit test or new objects for production
$this->payment = $payment ?? oxNew(Payment::class);
$this->order = $order ?? oxNew(Order::class);
$this->adyenHistoryList = $adyenHistoryList ?? oxNew(AdyenHistoryList::class);
$this->payment = $payment ?? $oxNewService->oxNew(Payment::class);
$this->order = $order ?? $oxNewService->oxNew(Order::class);
$this->adyenHistoryList = $adyenHistoryList ?? $oxNewService->oxNew(AdyenHistoryList::class);
$this->context = $context ?? $this->getServiceFromContainer(Context::class);
}

Expand Down Expand Up @@ -143,7 +146,8 @@ protected function setHistoryEntry(
string $action
): void {
try {
$adyenHistory = oxNew(AdyenHistory::class);
$oxNewService = $this->getServiceFromContainer(OxNewService::class);
$adyenHistory = $oxNewService->oxNew(AdyenHistory::class);
$adyenHistory->setOrderId($orderId);
$adyenHistory->setShopId($shopId);
$adyenHistory->setPrice($amount);
Expand Down
10 changes: 3 additions & 7 deletions src/Model/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ public function isAdyenPayment(): bool
}

/**
* Checks if the payment method is show on Payment Controller
* Checks if the payment method is an Adyen credit card payment method
*/
public function showInPaymentCtrl(): bool
public function isAdyenCreditCardPayment(): bool
{
return ($this->isAdyenPayment() &&
$this->getServiceFromContainer(ModuleService::class)->showInPaymentCtrl($this->getId()) &&
$this->getAdyenBoolData('oxactive') === true
);
return $this->getAdyenPaymentConfigService()->isAdyenCreditCardPayment($this->getId());
}

/**
Expand All @@ -48,7 +45,6 @@ public function showInPaymentCtrl(): bool
public function showInOrderCtrl(): bool
{
return ($this->isAdyenPayment() &&
!$this->getServiceFromContainer(ModuleService::class)->showInPaymentCtrl($this->getId()) &&
$this->getAdyenBoolData('oxactive') === true
);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Model/PaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public function executePayment($amount, &$order)
$paymentId = $sessionSettings->getPaymentId();

if ($moduleService->isAdyenPayment($paymentId)) {
if (!$moduleService->showInPaymentCtrl($paymentId)) {
$payGatewayService->doCollectAdyenRequestData();
}
$payGatewayService->doCollectAdyenRequestData();
/** @var Order $order */
$payGatewayService->doFinishAdyenPayment($amount, $order);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Service/JSAPIConfigurationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ private function getPaymentPageConfigFields(
ViewConfig $viewConfig
): array {
/** @var AdyenViewConfig $viewConfig */
return ($viewConfig->getTopActiveClassName() === 'payment') ?
return
[
'paymentMethodsResponse' => $viewConfig->getAdyenPaymentMethods(),
] :
[];
];
}

private function getOrderPageConfigFields(
Expand Down
5 changes: 3 additions & 2 deletions src/Service/JSAPITemplateConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ private function getViewData(
&& $paymentId === Module::PAYMENT_GOOGLE_PAY_ID,
'orderPaymentApplePay' => $controller instanceof OrderController
&& $paymentId === Module::PAYMENT_APPLE_PAY_ID,
'orderPaymentCreditCard' => $controller instanceof Ordercontroller
&& $paymentId === Module::PAYMENT_CREDITCARD_ID,
'paymentConfigNeedsCard' => $this->paymentMethodsConfigurationNeedsCardField(
$controller,
$viewConfig,
Expand Down Expand Up @@ -159,9 +161,8 @@ private function paymentMethodsConfigurationNeedsCardField(
): bool {
/** @var AdyenPayment $payment */
/** @var AdyenViewConfig $viewConfig */
return $controller instanceof PaymentController
return $controller instanceof OrderController
&& $payment instanceof Payment
&& $payment->showInPaymentCtrl()
&& $payment->getId() === $viewConfig->getAdyenPaymentCreditCardId();
}
}
5 changes: 2 additions & 3 deletions src/Service/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ public function isAdyenPayment(string $paymentId): bool
return (isset(ModuleCore::PAYMENT_DEFINTIONS[$paymentId]));
}

public function showInPaymentCtrl(string $paymentId): bool
public function isAdyenCreditCardPayment(string $paymentId): bool
{
return ($this->isAdyenPayment($paymentId) &&
ModuleCore::PAYMENT_DEFINTIONS[$paymentId]['paymentCtrl']);
return $paymentId === ModuleCore::PAYMENT_CREDITCARD_ID;
}

public function handleAssets(string $paymentId): bool
Expand Down
8 changes: 8 additions & 0 deletions src/Service/PaymentConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public function isAdyenPayment(string $paymentId): bool
return $this->moduleService->isAdyenPayment($paymentId);
}

/**
* Checks if the payment method is an Adyen credit card payment method
*/
public function isAdyenCreditCardPayment(string $paymentId): bool
{
return $this->moduleService->isAdyenCreditCardPayment($paymentId);
}

/**
* Checks if the payment allow manual Capture
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Service/PaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function doFinishAdyenPayment(float $amount, Order $order): bool
);
$order->save();

// trigger Capture for all PaymentCtrl-Payments with Capture-Delay "immediate"
// trigger Capture for all Payments with Capture-Delay "immediate"
if ($this->paymentConfigService->isAdyenImmediateCapture($paymentId)) {
$order->captureAdyenOrder($amount);
}
Expand All @@ -86,7 +86,7 @@ public function doFinishAdyenPayment(float $amount, Order $order): bool
}

/**
* put RequestData from OrderCtrl in the session as well as from PaymentCtrl
* put RequestData from OrderCtrl in the session
*/
public function doCollectAdyenRequestData(): void
{
Expand Down
12 changes: 0 additions & 12 deletions tests/Integration/Model/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,11 @@ public function testIsAdyenPaymentAndCheckCapture($paymentId, $isManualCapture,
$payment->load($paymentId);
$this->assertSame(isset(Module::PAYMENT_DEFINTIONS[$paymentId]), $payment->isAdyenPayment());

// Check: showInPaymentCtrl
$isActive = $payment->getFieldData('oxactive') === '1' ;
$this->assertSame(
(
isset(Module::PAYMENT_DEFINTIONS[$paymentId]) &&
Module::PAYMENT_DEFINTIONS[$paymentId]['paymentCtrl'] &&
$isActive
),
$payment->showInPaymentCtrl()
);

// Check: showInOrderCtrl
$isActive = $payment->getFieldData('oxactive') === '1' ;
$this->assertSame(
(
isset(Module::PAYMENT_DEFINTIONS[$paymentId]) &&
!Module::PAYMENT_DEFINTIONS[$paymentId]['paymentCtrl'] &&
$isActive
),
$payment->showInOrderCtrl()
Expand Down
Loading

0 comments on commit efee424

Please sign in to comment.