Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Api/CleanupAdditionalInformationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2025 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <magento@adyen.com>
*/

namespace Adyen\Payment\Api;

use Magento\Sales\Api\Data\OrderPaymentInterface;

interface CleanupAdditionalInformationInterface
{
const FIELD_ACTION = 'action';
const FIELD_ADDITIONAL_DATA = 'additionalData';
const FIELD_DONATION_TOKEN = 'donationToken';
const FIELD_FRONTEND_TYPE = 'frontendType';
const FIELD_COMBO_CARD_TYPE = 'combo_card_type';
const FIELD_CC_TYPE = 'cc_type';
const FIELD_RESULT_CODE = 'resultCode';

const FIELDS_TO_BE_CLEANED_UP = [
self::FIELD_ACTION,
self::FIELD_ADDITIONAL_DATA,
self::FIELD_DONATION_TOKEN,
self::FIELD_FRONTEND_TYPE,
self::FIELD_COMBO_CARD_TYPE,
self::FIELD_CC_TYPE,
self::FIELD_RESULT_CODE
];

/**
* @param OrderPaymentInterface $orderPayment
* @return OrderPaymentInterface
*/
public function execute(OrderPaymentInterface $orderPayment): OrderPaymentInterface;
}
2 changes: 0 additions & 2 deletions Gateway/Validator/CheckoutResponseValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ private function validateResponse($responseSubject): void
$paymentDataObjectInterface = SubjectReader::readPayment($responseSubject);
$payment = $paymentDataObjectInterface->getPayment();

$payment->setAdditionalInformation('3dActive', false);

// Handle empty result for unexpected cases
if (empty($response['resultCode'])) {
$this->handleEmptyResultCode($response);
Expand Down
36 changes: 3 additions & 33 deletions Helper/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class Webhook
'payment_authorized' => [Order::STATE_PROCESSING]
];

// TODO::This property is not written but only is read. Check the usage.
private $boletoPaidAmount;
private ?string $klarnaReservationNumber;
private ?string $ratepayDescriptor;

Expand Down Expand Up @@ -355,23 +353,16 @@ private function addNotificationDetailsHistoryComment(Order $order, Notification
$klarnaReservationNumberText = "";
}

if ($this->boletoPaidAmount != null && $this->boletoPaidAmount != "") {
$boletoPaidAmountText = "<br /> Paid amount: " . $this->boletoPaidAmount;
} else {
$boletoPaidAmountText = "";
}

$type = 'Adyen HTTP Notification(s):';
$comment = __(
'%1 <br /> eventCode: %2 <br /> pspReference: %3 <br /> paymentMethod: %4 <br />' .
' success: %5 %6 %7',
' success: %5 %6',
$type,
$eventCode,
$notification->getPspreference(),
$notification->getPaymentMethod(),
$success,
$klarnaReservationNumberText,
$boletoPaidAmountText
$klarnaReservationNumberText
);

// If notification is pending status and pending status is set add the status change to the comment history
Expand Down Expand Up @@ -471,31 +462,10 @@ private function updateOrderPaymentWithAdyenAttributes(
if (isset($additionalData['authCode'])) {
$payment->setAdditionalInformation('adyen_auth_code', $additionalData['authCode']);
}
if (isset($additionalData['cardBin'])) {
$payment->setAdditionalInformation('adyen_card_bin', $additionalData['cardBin']);
}
if (isset($additionalData['expiryDate'])) {
$payment->setAdditionalInformation('adyen_expiry_date', $additionalData['expiryDate']);
}
if (isset($additionalData['issuerCountry'])) {
$payment
->setAdditionalInformation('adyen_issuer_country', $additionalData['issuerCountry']);
}
$payment->setAdyenPspReference($notification->getPspreference());
$payment->setAdditionalInformation('pspReference', $notification->getPspreference());

if ($this->klarnaReservationNumber != "") {
$payment->setAdditionalInformation(
'adyen_klarna_number',
$this->klarnaReservationNumber
);
}

if ($this->boletoPaidAmount != "") {
$payment->setAdditionalInformation('adyen_boleto_paid_amount', $this->boletoPaidAmount);
}

if ($this->ratepayDescriptor !== "") {
if (!empty($this->ratepayDescriptor)) {
$payment->setAdditionalInformation(
'adyen_ratepay_descriptor',
$this->ratepayDescriptor
Expand Down
13 changes: 11 additions & 2 deletions Helper/Webhook/AuthorisationWebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Adyen\Payment\Helper\Webhook;

use Adyen\Payment\Api\CleanupAdditionalInformationInterface;
use Adyen\Payment\Api\Repository\AdyenNotificationRepositoryInterface;
use Adyen\Payment\Helper\AdyenOrderPayment;
use Adyen\Payment\Helper\CaseManagement;
Expand Down Expand Up @@ -41,6 +42,7 @@ class AuthorisationWebhookHandler implements WebhookHandlerInterface
* @param PaymentMethods $paymentMethodsHelper
* @param CartRepositoryInterface $cartRepository
* @param AdyenNotificationRepositoryInterface $notificationRepository
* @param CleanupAdditionalInformationInterface $cleanupAdditionalInformation
*/
public function __construct(
private readonly AdyenOrderPayment $adyenOrderPaymentHelper,
Expand All @@ -52,7 +54,8 @@ public function __construct(
private readonly Invoice $invoiceHelper,
private readonly PaymentMethods $paymentMethodsHelper,
private readonly CartRepositoryInterface $cartRepository,
private readonly AdyenNotificationRepositoryInterface $notificationRepository
private readonly AdyenNotificationRepositoryInterface $notificationRepository,
private readonly CleanupAdditionalInformationInterface $cleanupAdditionalInformation
) { }

/**
Expand Down Expand Up @@ -113,6 +116,9 @@ private function handleSuccessfulAuthorisation(Order $order, Notification $notif
// Set authorized amount in sales_order_payment
$order->getPayment()->setAmountAuthorized($order->getGrandTotal());
$order->getPayment()->setBaseAmountAuthorized($order->getBaseGrandTotal());

// Clean-up the data temporarily stored in `additional_information`
$this->cleanupAdditionalInformation->execute($order->getPayment());
} else {
$this->orderHelper->addWebhookStatusHistoryComment($order, $notification);
}
Expand Down Expand Up @@ -186,6 +192,9 @@ private function handleFailedAuthorisation(Order $order, Notification $notificat
$order->setState(Order::STATE_NEW);
}

// Clean-up the data temporarily stored in `additional_information`
$this->cleanupAdditionalInformation->execute($order->getPayment());

return $this->orderHelper->holdCancelOrder($order, true);
}

Expand All @@ -200,7 +209,7 @@ private function handleAutoCapture(Order $order, Notification $notification, boo
{
$this->invoiceHelper->createInvoice($order, $notification, true);
if ($requireFraudManualReview) {
$order = $this->caseManagementHelper->markCaseAsPendingReview($order, $notification->getPspreference(), true);
$order = $this->caseManagementHelper->markCaseAsPendingReview($order, $notification->getPspreference(), true);
} else {
$order = $this->orderHelper->finalizeOrder($order, $notification);
}
Expand Down
32 changes: 15 additions & 17 deletions Helper/Webhook/CancelOrRefundWebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Adyen\Payment\Helper\Webhook;

use Adyen\Payment\Api\CleanupAdditionalInformationInterface;
use Adyen\Payment\Helper\CaseManagement;
use Adyen\Payment\Helper\Order;
use Adyen\Payment\Helper\PaymentMethods;
Expand All @@ -25,24 +26,18 @@ class CancelOrRefundWebhookHandler implements WebhookHandlerInterface
{
const MODIFICATION_ACTION = 'modification.action';

/** @var AdyenLogger */
private $adyenLogger;

/** @var SerializerInterface */
private $serializer;

/** @var Order */
private $orderHelper;

/**
* @param AdyenLogger $adyenLogger
* @param SerializerInterface $serializer
* @param Order $orderHelper
* @param CleanupAdditionalInformationInterface $cleanupAdditionalInformation
*/
public function __construct(
AdyenLogger $adyenLogger,
SerializerInterface $serializer,
Order $orderHelper
) {
$this->adyenLogger = $adyenLogger;
$this->serializer = $serializer;
$this->orderHelper = $orderHelper;
}
private readonly AdyenLogger $adyenLogger,
private readonly SerializerInterface $serializer,
private readonly Order $orderHelper,
private readonly CleanupAdditionalInformationInterface $cleanupAdditionalInformation
) { }

/**
* @throws LocalizedException
Expand Down Expand Up @@ -93,6 +88,9 @@ public function handleWebhook(MagentoOrder $order, Notification $notification, s
}
}

// Clean-up the data temporarily stored in `additional_information`
$this->cleanupAdditionalInformation->execute($order->getPayment());

return $order;
}

Expand Down
22 changes: 13 additions & 9 deletions Helper/Webhook/CancellationWebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Adyen\Payment\Helper\Webhook;

use Adyen\Payment\Api\CleanupAdditionalInformationInterface;
use Adyen\Payment\Helper\Order;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\Notification;
Expand All @@ -20,16 +21,16 @@

class CancellationWebhookHandler implements WebhookHandlerInterface
{
private Order $orderHelper;
private AdyenLogger $adyenLogger;

/**
* @param Order $orderHelper
* @param AdyenLogger $adyenLogger
* @param CleanupAdditionalInformationInterface $cleanupAdditionalInformation
*/
public function __construct(
Order $orderHelper,
AdyenLogger $adyenLogger
) {
$this->orderHelper = $orderHelper;
$this->adyenLogger = $adyenLogger;
}
private readonly Order $orderHelper,
private readonly AdyenLogger $adyenLogger,
private readonly CleanupAdditionalInformationInterface $cleanupAdditionalInformation
) { }

/**
* @throws LocalizedException
Expand Down Expand Up @@ -67,6 +68,9 @@ public function handleWebhook(
);
}

// Clean-up the data temporarily stored in `additional_information`
$this->cleanupAdditionalInformation->execute($order->getPayment());

return $order;
}
}
47 changes: 19 additions & 28 deletions Helper/Webhook/OfferClosedWebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Adyen\Payment\Helper\Webhook;

use Adyen\AdyenException;
use Adyen\Payment\Api\CleanupAdditionalInformationInterface;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Helper\Order;
use Adyen\Payment\Helper\PaymentMethods;
Expand All @@ -22,37 +23,24 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Model\Order as MagentoOrder;


class OfferClosedWebhookHandler implements WebhookHandlerInterface
{
/** @var PaymentMethods */
private $paymentMethodsHelper;

/** @var AdyenLogger */
private $adyenLogger;

/** @var Config */
private $configHelper;

/** @var Order */
private $orderHelper;

/** @var OrderPaymentResourceModel */
protected $orderPaymentResourceModel;

/**
* @param PaymentMethods $paymentMethodsHelper
* @param AdyenLogger $adyenLogger
* @param Config $configHelper
* @param Order $orderHelper
* @param OrderPaymentResourceModel $orderPaymentResourceModel
* @param CleanupAdditionalInformationInterface $cleanupAdditionalInformation
*/
public function __construct(
PaymentMethods $paymentMethodsHelper,
AdyenLogger $adyenLogger,
Config $configHelper,
Order $orderHelper,
OrderPaymentResourceModel $orderPaymentResourceModel
) {
$this->paymentMethodsHelper = $paymentMethodsHelper;
$this->adyenLogger = $adyenLogger;
$this->configHelper = $configHelper;
$this->orderHelper = $orderHelper;
$this->orderPaymentResourceModel = $orderPaymentResourceModel;
}
private readonly PaymentMethods $paymentMethodsHelper,
private readonly AdyenLogger $adyenLogger,
private readonly Config $configHelper,
private readonly Order $orderHelper,
private readonly OrderPaymentResourceModel $orderPaymentResourceModel,
private readonly CleanupAdditionalInformationInterface $cleanupAdditionalInformation
) { }

/**
* @throws LocalizedException
Expand Down Expand Up @@ -116,6 +104,9 @@ public function handleWebhook(MagentoOrder $order, Notification $notification, s
$order->setState(MagentoOrder::STATE_NEW);
}

// Clean-up the data temporarily stored in `additional_information`
$this->cleanupAdditionalInformation->execute($order->getPayment());

$this->orderHelper->holdCancelOrder($order, true);

return $order;
Expand Down
Loading
Loading