Skip to content

Commit 92d5b2d

Browse files
committed
[ECP-9686] Create a class to clean-up additional information
1 parent 535213b commit 92d5b2d

5 files changed

Lines changed: 127 additions & 1 deletion

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
*
4+
* Adyen Payment Module
5+
*
6+
* Copyright (c) 2025 Adyen N.V.
7+
* This file is open source and available under the MIT license.
8+
* See the LICENSE file for more info.
9+
*
10+
* Author: Adyen <magento@adyen.com>
11+
*/
12+
13+
namespace Adyen\Payment\Api;
14+
15+
use Magento\Sales\Api\Data\OrderPaymentInterface;
16+
17+
interface CleanupAdditionalInformationInterface
18+
{
19+
const FIELD_ACTION = 'action';
20+
const FIELD_ADDITIONAL_DATA = 'additionalData';
21+
22+
const FIELDS_TO_BE_CLEANED_UP = [
23+
self::FIELD_ACTION,
24+
self::FIELD_ADDITIONAL_DATA
25+
];
26+
27+
/**
28+
* @param OrderPaymentInterface $orderPayment
29+
* @return OrderPaymentInterface
30+
*/
31+
public function execute(OrderPaymentInterface $orderPayment): OrderPaymentInterface;
32+
}

Helper/Webhook/AuthorisationWebhookHandler.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Adyen\Payment\Helper\Webhook;
1414

15+
use Adyen\Payment\Api\CleanupAdditionalInformationInterface;
1516
use Adyen\Payment\Api\Repository\AdyenNotificationRepositoryInterface;
1617
use Adyen\Payment\Helper\AdyenOrderPayment;
1718
use Adyen\Payment\Helper\CaseManagement;
@@ -41,6 +42,7 @@ class AuthorisationWebhookHandler implements WebhookHandlerInterface
4142
* @param PaymentMethods $paymentMethodsHelper
4243
* @param CartRepositoryInterface $cartRepository
4344
* @param AdyenNotificationRepositoryInterface $notificationRepository
45+
* @param CleanupAdditionalInformationInterface $cleanupAdditionalInformation
4446
*/
4547
public function __construct(
4648
private readonly AdyenOrderPayment $adyenOrderPaymentHelper,
@@ -52,7 +54,8 @@ public function __construct(
5254
private readonly Invoice $invoiceHelper,
5355
private readonly PaymentMethods $paymentMethodsHelper,
5456
private readonly CartRepositoryInterface $cartRepository,
55-
private readonly AdyenNotificationRepositoryInterface $notificationRepository
57+
private readonly AdyenNotificationRepositoryInterface $notificationRepository,
58+
private readonly CleanupAdditionalInformationInterface $cleanupAdditionalInformation
5659
) { }
5760

5861
/**
@@ -113,6 +116,9 @@ private function handleSuccessfulAuthorisation(Order $order, Notification $notif
113116
// Set authorized amount in sales_order_payment
114117
$order->getPayment()->setAmountAuthorized($order->getGrandTotal());
115118
$order->getPayment()->setBaseAmountAuthorized($order->getBaseGrandTotal());
119+
120+
// Clean-up the data temporarily stored in `additional_information`
121+
$this->cleanupAdditionalInformation->execute($order->getPayment());
116122
} else {
117123
$this->orderHelper->addWebhookStatusHistoryComment($order, $notification);
118124
}
@@ -186,6 +192,9 @@ private function handleFailedAuthorisation(Order $order, Notification $notificat
186192
$order->setState(Order::STATE_NEW);
187193
}
188194

195+
// Clean-up the data temporarily stored in `additional_information`
196+
$this->cleanupAdditionalInformation->execute($order->getPayment());
197+
189198
return $this->orderHelper->holdCancelOrder($order, true);
190199
}
191200

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
*
4+
* Adyen Payment Module
5+
*
6+
* Copyright (c) 2025 Adyen N.V.
7+
* This file is open source and available under the MIT license.
8+
* See the LICENSE file for more info.
9+
*
10+
* Author: Adyen <magento@adyen.com>
11+
*/
12+
13+
namespace Adyen\Payment\Model;
14+
15+
use Adyen\Payment\Api\CleanupAdditionalInformationInterface;
16+
use Magento\Sales\Api\Data\OrderPaymentInterface;
17+
18+
class CleanupAdditionalInformation implements CleanupAdditionalInformationInterface
19+
{
20+
/**
21+
* This method cleans-up the unnecessary fields in `additional_information` of OrderPayment object.
22+
*
23+
* @param OrderPaymentInterface $orderPayment
24+
* @return OrderPaymentInterface
25+
*/
26+
public function execute(OrderPaymentInterface $orderPayment): OrderPaymentInterface
27+
{
28+
foreach (self::FIELDS_TO_BE_CLEANED_UP as $field) {
29+
$orderPayment->unsAdditionalInformation($field);
30+
}
31+
32+
return $orderPayment;
33+
}
34+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
*
4+
* Adyen Payment module (https://www.adyen.com/)
5+
*
6+
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
7+
* See LICENSE.txt for license details.
8+
*
9+
* Author: Adyen <magento@adyen.com>
10+
*/
11+
12+
namespace Adyen\Payment\Test\Helper\Unit\Model;
13+
14+
use Adyen\Payment\Api\CleanupAdditionalInformationInterface;
15+
use Adyen\Payment\Model\CleanupAdditionalInformation;
16+
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
17+
use Magento\Sales\Model\Order\Payment;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
20+
class CleanupAdditionalInformationTest extends AbstractAdyenTestCase
21+
{
22+
protected ?CleanupAdditionalInformation $cleanupAdditionalInformation;
23+
protected Payment|MockObject $orderPaymentMock;
24+
25+
public function setUp(): void
26+
{
27+
$this->orderPaymentMock = $this->createMock(Payment::class);
28+
29+
$this->cleanupAdditionalInformation = new CleanupAdditionalInformation();
30+
}
31+
32+
public function tearDown(): void
33+
{
34+
$this->cleanupAdditionalInformation = null;
35+
}
36+
37+
public function testExecute()
38+
{
39+
$this->orderPaymentMock->expects($this->exactly(2))
40+
->method('unsAdditionalInformation')
41+
->willReturnMap([
42+
[CleanupAdditionalInformationInterface::FIELD_ADDITIONAL_DATA, $this->orderPaymentMock],
43+
[CleanupAdditionalInformationInterface::FIELD_ACTION, $this->orderPaymentMock]
44+
]);
45+
46+
$result = $this->cleanupAdditionalInformation->execute($this->orderPaymentMock);
47+
$this->assertInstanceOf(Payment::class, $result);
48+
}
49+
}

etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,8 @@
16551655
type="Adyen\Payment\Model\AdyenCreditmemoRepository" />
16561656
<preference for="Adyen\Payment\Api\Repository\AdyenOrderPaymentRepositoryInterface"
16571657
type="Adyen\Payment\Model\AdyenOrderPaymentRepository" />
1658+
<preference for="Adyen\Payment\Api\CleanupAdditionalInformationInterface"
1659+
type="Adyen\Payment\Model\CleanupAdditionalInformation" />
16581660
<type name="Magento\Vault\Api\PaymentTokenRepositoryInterface">
16591661
<plugin name="AdyenPaymentVaultDeleteToken" type="Adyen\Payment\Plugin\PaymentVaultDeleteToken" sortOrder="10" />
16601662
</type>

0 commit comments

Comments
 (0)