diff --git a/Gateway/Response/AbstractOrderStatusHistoryHandler.php b/Gateway/Response/AbstractOrderStatusHistoryHandler.php
new file mode 100644
index 000000000..536c187a9
--- /dev/null
+++ b/Gateway/Response/AbstractOrderStatusHistoryHandler.php
@@ -0,0 +1,55 @@
+
+ */
+
+namespace Adyen\Payment\Gateway\Response;
+
+use Adyen\AdyenException;
+use Adyen\Payment\Helper\OrderStatusHistory;
+use Magento\Payment\Gateway\Helper\SubjectReader;
+use Magento\Payment\Gateway\Response\HandlerInterface;
+
+class AbstractOrderStatusHistoryHandler implements HandlerInterface
+{
+ /**
+ * @param string $eventType Indicates the API call event type (authorization, capture etc.)
+ * @param OrderStatusHistory $orderStatusHistoryHelper
+ */
+ public function __construct(
+ protected readonly string $eventType,
+ protected readonly OrderStatusHistory $orderStatusHistoryHelper
+ ) { }
+
+ /**
+ * @throws AdyenException
+ */
+ public function handle(array $handlingSubject, array $responseCollection): void
+ {
+ if (empty($this->eventType)) {
+ throw new AdyenException(
+ __('Order status history can not be handled due to missing event type!')
+ );
+ }
+
+ $readPayment = SubjectReader::readPayment($handlingSubject);
+ $payment = $readPayment->getPayment();
+ $order = $payment->getOrder();
+
+ // Temporary workaround to clean-up `hasOnlyGiftCards` key. It needs to be handled separately.
+ if (isset($responseCollection['hasOnlyGiftCards'])) {
+ unset($responseCollection['hasOnlyGiftCards']);
+ }
+
+ foreach ($responseCollection as $response) {
+ $comment = $this->orderStatusHistoryHelper->buildApiResponseComment($response, $this->eventType);
+ $order->addCommentToStatusHistory($comment, $order->getStatus());
+ }
+ }
+}
diff --git a/Gateway/Response/CheckoutPaymentCommentHistoryHandler.php b/Gateway/Response/CheckoutPaymentCommentHistoryHandler.php
deleted file mode 100644
index 1fc333259..000000000
--- a/Gateway/Response/CheckoutPaymentCommentHistoryHandler.php
+++ /dev/null
@@ -1,47 +0,0 @@
-
- */
-
-namespace Adyen\Payment\Gateway\Response;
-
-use Magento\Payment\Gateway\Helper\SubjectReader;
-use Magento\Payment\Gateway\Response\HandlerInterface;
-
-class CheckoutPaymentCommentHistoryHandler implements HandlerInterface
-{
- /**
- * @param array $handlingSubject
- * @param array $responseCollection
- * @return $this
- */
- public function handle(array $handlingSubject, array $responseCollection): self
- {
- $readPayment = SubjectReader::readPayment($handlingSubject);
- $payment = $readPayment->getPayment();
- $comment = __("Adyen Result response:");
-
- foreach ($responseCollection as $response) {
- $responseCode = $response['resultCode'] ?? $response['response'] ?? '';
-
- if (!empty($responseCode)) {
- $comment .= '
' . __('authResult:') . ' ' . $responseCode;
- $payment->getOrder()->setAdyenResulturlEventCode($responseCode);
- }
-
- if (isset($response['pspReference'])) {
- $comment .= '
' . __('pspReference:') . ' ' . $response['pspReference'];
- }
- $comment .= '
';
- }
-
- $payment->getOrder()->addStatusHistoryComment($comment, $payment->getOrder()->getStatus());
- return $this;
- }
-}
diff --git a/Gateway/Response/CheckoutPaymentsDetailsHandler.php b/Gateway/Response/CheckoutPaymentsDetailsHandler.php
index 1731b7db1..495bd480d 100644
--- a/Gateway/Response/CheckoutPaymentsDetailsHandler.php
+++ b/Gateway/Response/CheckoutPaymentsDetailsHandler.php
@@ -69,6 +69,10 @@ public function handle(array $handlingSubject, array $responseCollection)
$payment->setTransactionId($response['pspReference']);
}
+ if (isset($response['resultCode'])) {
+ $payment->getOrder()->setAdyenResulturlEventCode($response['resultCode']);
+ }
+
// do not close transaction, so you can do a cancel() and void
$payment->setIsTransactionClosed(false);
$payment->setShouldCloseParentTransaction(false);
diff --git a/Helper/Data.php b/Helper/Data.php
index b5116c956..34cdb2048 100755
--- a/Helper/Data.php
+++ b/Helper/Data.php
@@ -561,8 +561,9 @@ public function getLiveEndpointPrefix($storeId = null)
* Cancels the order
*
* @param $order
+ * @param null $reason
*/
- public function cancelOrder($order)
+ public function cancelOrder($order, $reason = null)
{
$orderStatus = $this->configHelper->getAdyenAbstractConfigData('payment_cancelled');
$order->setActionFlag($orderStatus, true);
@@ -577,12 +578,11 @@ public function cancelOrder($order)
if ($order->canCancel()) {
if ($this->orderManagement->cancel($order->getEntityId())) { //new canceling process
try {
- $orderStatusHistory = $this->orderStatusHistoryFactory->create()
- ->setParentId($order->getEntityId())
- ->setEntityName('order')
- ->setStatus(Order::STATE_CANCELED)
- ->setComment(__('Order has been cancelled by "%1" payment response.', $order->getPayment()->getMethod()));
- $this->orderManagement->addComment($order->getEntityId(), $orderStatusHistory);
+ $comment = __('Order has been cancelled.', $order->getPayment()->getMethod());
+ if ($reason) {
+ $comment .= '
' . __("Reason: %1", $reason) . '
';
+ }
+ $order->addCommentToStatusHistory($comment, $order->getStatus());
} catch (Exception $e) {
$this->adyenLogger->addAdyenDebug(
__('Order cancel history comment error: %1', $e->getMessage()),
diff --git a/Helper/Invoice.php b/Helper/Invoice.php
index 75183d1fd..30e6df3f4 100644
--- a/Helper/Invoice.php
+++ b/Helper/Invoice.php
@@ -219,11 +219,11 @@ public function createAdyenInvoice(
*
* @param Order $order
* @param Notification $notification
- * @return AdyenInvoice
+ * @return array
+ * @throws AdyenWebhookException
* @throws AlreadyExistsException
- * @throws Exception
*/
- public function handleCaptureWebhook(Order $order, Notification $notification): AdyenInvoice
+ public function handleCaptureWebhook(Order $order, Notification $notification): array
{
$invoiceFactory = $this->adyenInvoiceFactory->create();
$adyenInvoice = $this->adyenInvoiceResourceModel->getAdyenInvoiceByCaptureWebhook($order, $notification);
@@ -280,12 +280,19 @@ public function handleCaptureWebhook(Order $order, Notification $notification):
$magentoInvoice = $this->magentoInvoiceFactory->create()->load($adyenInvoiceObject->getInvoiceId());
if ($this->isFullInvoiceAmountManuallyCaptured($magentoInvoice)) {
+ /*
+ * Magento Invoice updates the Order object while paying the invoice. This creates two divergent
+ * Order objects. In the downstream, some information might be missing due to setting them on the
+ * wrong order object as the Order might be already updated in the upstream without persisting
+ * it to the database. Setting the order again on the Invoice makes sure we are dealing
+ * with the same order object always.
+ */
+ $magentoInvoice->setOrder($order);
$magentoInvoice->pay();
$this->invoiceRepository->save($magentoInvoice);
- $this->magentoOrderResourceModel->save($magentoInvoice->getOrder());
}
- return $adyenInvoiceObject;
+ return [$adyenInvoiceObject, $magentoInvoice, $order];
}
/**
diff --git a/Helper/OrderStatusHistory.php b/Helper/OrderStatusHistory.php
new file mode 100644
index 000000000..a56633ad9
--- /dev/null
+++ b/Helper/OrderStatusHistory.php
@@ -0,0 +1,140 @@
+
+ */
+
+namespace Adyen\Payment\Helper;
+
+use Adyen\Payment\Api\Data\NotificationInterface;
+use Adyen\Payment\Model\Notification;
+use Magento\Sales\Api\Data\OrderInterface;
+
+class OrderStatusHistory
+{
+ /**
+ * @param ChargedCurrency $chargedCurrencyHelper
+ * @param Data $adyenHelper
+ */
+ public function __construct(
+ private readonly ChargedCurrency $chargedCurrencyHelper,
+ private readonly Data $adyenHelper
+ ) { }
+
+ /**
+ * Builds the order status history comment based on the Checkout API response
+ *
+ * @param array $response
+ * @param string $actionName
+ * @return string
+ */
+ public function buildApiResponseComment(array $response, string $actionName): string
+ {
+ $comment = '' . __("Adyen %1 response", $actionName) . '
';
+
+ if (isset($response['resultCode'])) {
+ $comment .= __("Result code: %1", $response['resultCode']) . '
';
+ }
+
+ // Modification responses contain `status` but not `resultCode`.
+ if (isset($response['status'])) {
+ $comment .= __("Status: %1", $response['status']) . '
';
+ }
+
+ if (isset($response['pspReference'])) {
+ $comment .= __("PSP reference: %1", $response['pspReference']) . '
';
+ }
+
+ if ($paymentMethod = $response['paymentMethod']['brand'] ?? $response['paymentMethod']['type'] ?? null) {
+ $comment .= __("Payment method: %1", $paymentMethod) . '
';
+ }
+
+ if (isset($response['refusalReason'])) {
+ $comment .= __("Refusal reason: %1", $response['refusalReason']) . '
';
+ }
+
+ if (isset($response['errorCode'])) {
+ $comment .= __("Error code: %1", $response['errorCode']) . '
';
+ }
+
+ return $comment;
+ }
+
+ /**
+ * Builds the order status history comment based on the webhook
+ *
+ * @param OrderInterface $order
+ * @param NotificationInterface $notification
+ * @param string|null $klarnaReservationNumber
+ * @return string
+ */
+ public function buildWebhookComment(
+ OrderInterface $order,
+ NotificationInterface $notification,
+ ?string $klarnaReservationNumber = null,
+ ): string {
+ $comment = '' . __(
+ "Adyen %1%2 webhook",
+ $this->getIsWebhookForPartialPayment($order, $notification) ? 'partial ': '',
+ $notification->getEventCode()
+ ) . '
';
+
+ if (!empty($notification->getPspreference())) {
+ $comment .= __("PSP reference: %1", $notification->getPspreference()) . '
';
+ }
+
+ if (!empty($notification->getPaymentMethod())) {
+ $comment .= __("Payment method: %1", $notification->getPaymentMethod()) . '
';
+ }
+
+ if (!empty($notification->getSuccess())) {
+ $status = $notification->isSuccessful() ? 'Successful' : 'Failed';
+ $comment .= __("Event status: %1", $status) . '
';
+ }
+
+ if (!empty($notification->getReason())) {
+ $comment .= __("Reason: %1", $notification->getReason()) . '
';
+ }
+
+ if (isset($klarnaReservationNumber)) {
+ $comment .= __("Reservation number: %1", $klarnaReservationNumber) . '
';
+ }
+
+ return $comment;
+ }
+
+ /**
+ * Identifies whether if the notification belongs to a partial modification or not
+ *
+ * @param OrderInterface $order
+ * @param NotificationInterface $notification
+ * @return bool
+ */
+ private function getIsWebhookForPartialPayment(
+ OrderInterface $order,
+ NotificationInterface $notification
+ ): bool {
+ $isPartial = false;
+
+ if (in_array($notification->getEventCode(), [Notification::REFUND, Notification::CAPTURE])) {
+ // check if it is a full or partial refund
+ $amount = $notification->getAmountValue();
+ $orderAmountCurrency = $this->chargedCurrencyHelper->getOrderAmountCurrency($order, false);
+ $formattedOrderAmount = $this->adyenHelper->formatAmount(
+ $orderAmountCurrency->getAmount(),
+ $orderAmountCurrency->getCurrencyCode()
+ );
+
+ if ($amount !== $formattedOrderAmount) {
+ $isPartial = true;
+ }
+ }
+
+ return $isPartial;
+ }
+}
diff --git a/Helper/PaymentResponseHandler.php b/Helper/PaymentResponseHandler.php
index d74b3e1d6..218d31c1c 100644
--- a/Helper/PaymentResponseHandler.php
+++ b/Helper/PaymentResponseHandler.php
@@ -12,6 +12,7 @@
namespace Adyen\Payment\Helper;
use Adyen\Model\Checkout\CancelOrderRequest;
+use Adyen\Payment\Helper\Order as AdyenOrderHelper;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\ResourceModel\PaymentResponse\CollectionFactory as PaymentResponseCollectionFactory;
use Exception;
@@ -50,48 +51,35 @@ class PaymentResponseHandler
];
/**
- * @var AdyenLogger
+ * @param AdyenLogger $adyenLogger
+ * @param Vault $vaultHelper
+ * @param Order $orderResourceModel
+ * @param Data $dataHelper
+ * @param Quote $quoteHelper
+ * @param AdyenOrderHelper $orderHelper
+ * @param OrderRepository $orderRepository
+ * @param HistoryFactory $orderHistoryFactory
+ * @param StateData $stateDataHelper
+ * @param PaymentResponseCollectionFactory $paymentResponseCollectionFactory
+ * @param Config $configHelper
+ * @param PaymentMethods $paymentMethodsHelper
+ * @param OrderStatusHistory $orderStatusHistoryHelper
*/
- private AdyenLogger $adyenLogger;
- private Vault $vaultHelper;
- private Order $orderResourceModel;
- private Data $dataHelper;
- private Quote $quoteHelper;
- private \Adyen\Payment\Helper\Order $orderHelper;
- private OrderRepository $orderRepository;
- private HistoryFactory $orderHistoryFactory;
- private StateData $stateDataHelper;
- private PaymentResponseCollectionFactory $paymentResponseCollectionFactory;
- private Config $configHelper;
- private PaymentMethods $paymentMethodsHelper;
-
public function __construct(
- AdyenLogger $adyenLogger,
- Vault $vaultHelper,
- Order $orderResourceModel,
- Data $dataHelper,
- Quote $quoteHelper,
- \Adyen\Payment\Helper\Order $orderHelper,
- OrderRepository $orderRepository,
- HistoryFactory $orderHistoryFactory,
- StateData $stateDataHelper,
- PaymentResponseCollectionFactory $paymentResponseCollectionFactory,
- Config $configHelper,
- PaymentMethods $paymentMethodsHelper
- ) {
- $this->adyenLogger = $adyenLogger;
- $this->vaultHelper = $vaultHelper;
- $this->orderResourceModel = $orderResourceModel;
- $this->dataHelper = $dataHelper;
- $this->quoteHelper = $quoteHelper;
- $this->orderHelper = $orderHelper;
- $this->orderRepository = $orderRepository;
- $this->orderHistoryFactory = $orderHistoryFactory;
- $this->stateDataHelper = $stateDataHelper;
- $this->paymentResponseCollectionFactory = $paymentResponseCollectionFactory;
- $this->configHelper = $configHelper;
- $this->paymentMethodsHelper = $paymentMethodsHelper;
- }
+ private readonly AdyenLogger $adyenLogger,
+ private readonly Vault $vaultHelper,
+ private readonly Order $orderResourceModel,
+ private readonly Data $dataHelper,
+ private readonly Quote $quoteHelper,
+ private readonly AdyenOrderHelper $orderHelper,
+ private readonly OrderRepository $orderRepository,
+ private readonly HistoryFactory $orderHistoryFactory,
+ private readonly StateData $stateDataHelper,
+ private readonly PaymentResponseCollectionFactory $paymentResponseCollectionFactory,
+ private readonly Config $configHelper,
+ private readonly PaymentMethods $paymentMethodsHelper,
+ private readonly OrderStatusHistory $orderStatusHistoryHelper
+ ) { }
public function formatPaymentResponse(
string $resultCode,
@@ -170,23 +158,6 @@ public function handlePaymentsDetailsResponse(
return false;
}
- $paymentMethod = $paymentsDetailsResponse['paymentMethod']['brand'] ??
- $paymentsDetailsResponse['paymentMethod']['type'] ??
- '';
-
- $pspReference = isset($paymentsDetailsResponse['pspReference']) ?
- trim((string) $paymentsDetailsResponse['pspReference']) :
- '';
-
- $type = 'Adyen paymentsDetails response:';
- $comment = __(
- '%1
authResult: %2
pspReference: %3
paymentMethod: %4',
- $type,
- $authResult,
- $pspReference,
- $paymentMethod
- );
-
$resultCode = $paymentsDetailsResponse['resultCode'];
if (!empty($resultCode)) {
$payment->setAdditionalInformation('resultCode', $resultCode);
@@ -234,9 +205,15 @@ public function handlePaymentsDetailsResponse(
* Otherwise keep the order state as pending_payment.
*/
$order = $this->orderHelper->setStatusOrderCreation($order);
- $this->orderRepository->save($order);
}
+ // Add order status history comment for /payments/details API response
+ $comment = $this->orderStatusHistoryHelper->buildApiResponseComment(
+ $paymentsDetailsResponse,
+ 'payments/details'
+ );
+ $order->addCommentToStatusHistory($comment, $order->getStatus());
+
// Cleanup state data if exists.
try {
$this->stateDataHelper->cleanQuoteStateData($order->getQuoteId(), $authResult);
@@ -244,6 +221,10 @@ public function handlePaymentsDetailsResponse(
$this->adyenLogger->error(__('Error cleaning the payment state data: %s', $exception->getMessage()));
}
+ $paymentMethod = $paymentsDetailsResponse['paymentMethod']['brand'] ??
+ $paymentsDetailsResponse['paymentMethod']['type'] ??
+ '';
+
switch ($resultCode) {
case self::AUTHORISED:
if (!empty($paymentsDetailsResponse['pspReference'])) {
@@ -273,16 +254,18 @@ public function handlePaymentsDetailsResponse(
// do nothing wait for the notification
if (strpos((string) $paymentMethod, "bankTransfer") !== false) {
- $comment .= "
Waiting for the customer to transfer the money.";
+ $pendingComment = "Waiting for the customer to transfer the money.";
} elseif ($paymentMethod == "sepadirectdebit") {
- $comment .= "
This request will be send to the bank at the end of the day.";
+ $pendingComment = "This request will be send to the bank at the end of the day.";
} else {
- $comment .= "
The payment result is not confirmed (yet).
+ $pendingComment = "The payment result is not confirmed (yet).
Once the payment is authorised, the order status will be updated accordingly.
If the order is stuck on this status, the payment can be seen as unsuccessful.
The order can be automatically cancelled based on the OFFER_CLOSED notification.
Please contact Adyen Support to enable this.";
}
+
+ $order->addCommentToStatusHistory($pendingComment, $order->getStatus());
$this->adyenLogger->addAdyenResult('Do nothing wait for the notification');
$result = true;
@@ -318,7 +301,7 @@ public function handlePaymentsDetailsResponse(
if ($order->canCancel()) {
// Proceed to set cancellation action flag and cancel the order
$order->setActionFlag(\Magento\Sales\Model\Order::ACTION_FLAG_CANCEL, true);
- $this->dataHelper->cancelOrder($order);
+ $this->dataHelper->cancelOrder($order, $resultCode);
} else {
$this->adyenLogger->addAdyenResult('The order cannot be cancelled');
}
@@ -337,14 +320,6 @@ public function handlePaymentsDetailsResponse(
break;
}
- $history = $this->orderHistoryFactory->create()
- ->setStatus($order->getStatus())
- ->setComment($comment)
- ->setEntityName('order')
- ->setOrder($order);
-
- $history->save();
-
// needed because then we need to save $order objects
$order->setAdyenResulturlEventCode($authResult);
$this->orderResourceModel->save($order);
diff --git a/Helper/Webhook.php b/Helper/Webhook.php
index ddaac33fb..57b2b10db 100644
--- a/Helper/Webhook.php
+++ b/Helper/Webhook.php
@@ -51,34 +51,28 @@ 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;
/**
- * @param Data $adyenHelper
* @param SerializerInterface $serializer
* @param TimezoneInterface $timezone
* @param Config $configHelper
- * @param ChargedCurrency $chargedCurrency
* @param AdyenLogger $logger
* @param WebhookHandlerFactory $webhookHandlerFactory
* @param OrderHelper $orderHelper
* @param OrderRepository $orderRepository
- * @param PaymentMethods $paymentMethodsHelper
+ * @param OrderStatusHistory $orderStatusHistoryHelper
*/
public function __construct(
- private readonly Data $adyenHelper,
private readonly SerializerInterface $serializer,
private readonly TimezoneInterface $timezone,
private readonly ConfigHelper $configHelper,
- private readonly ChargedCurrency $chargedCurrency,
private readonly AdyenLogger $logger,
private readonly WebhookHandlerFactory $webhookHandlerFactory,
private readonly OrderHelper $orderHelper,
private readonly OrderRepository $orderRepository,
- private readonly PaymentMethods $paymentMethodsHelper
+ private readonly OrderStatusHistory $orderStatusHistoryHelper
) {
$this->klarnaReservationNumber = null;
$this->ratepayDescriptor = null;
@@ -287,76 +281,17 @@ private function declareVariables(Notification $notification): void
private function addNotificationDetailsHistoryComment(Order $order, Notification $notification): Order
{
- $successResult = $notification->isSuccessful() ? 'true' : 'false';
- $reason = $notification->getReason();
- $success = (!empty($reason)) ? "$successResult
reason:$reason" : $successResult;
-
- $payment = $order->getPayment();
- $paymentMethodInstance = $payment->getMethodInstance();
-
- $eventCode = $notification->getEventCode();
- if ($eventCode == Notification::REFUND || $eventCode == Notification::CAPTURE) {
- // check if it is a full or partial refund
- $amount = $notification->getAmountValue();
- $orderAmountCurrency = $this->chargedCurrency->getOrderAmountCurrency($order, false);
- $formattedOrderAmount = $this->adyenHelper
- ->formatAmount($orderAmountCurrency->getAmount(), $orderAmountCurrency->getCurrencyCode());
-
- if ($amount == $formattedOrderAmount) {
- $order->setData(
- 'adyen_notification_event_code',
- $eventCode . " : " . strtoupper($successResult)
- );
- } else {
- $order->setData(
- 'adyen_notification_event_code',
- "(PARTIAL) " .
- $eventCode . " : " . strtoupper($successResult)
- );
- }
- } else {
- $order->setData(
- 'adyen_notification_event_code',
- $eventCode . " : " . strtoupper($successResult)
- );
- }
-
- // if payment method is klarna, ratepay or openinvoice/afterpay show the reservartion number
- if ($this->paymentMethodsHelper->isOpenInvoice($paymentMethodInstance) &&
- !empty($this->klarnaReservationNumber)) {
- $klarnaReservationNumberText = "
reservationNumber: " . $this->klarnaReservationNumber;
- } else {
- $klarnaReservationNumberText = "";
- }
-
- if ($this->boletoPaidAmount != null && $this->boletoPaidAmount != "") {
- $boletoPaidAmountText = "
Paid amount: " . $this->boletoPaidAmount;
- } else {
- $boletoPaidAmountText = "";
- }
-
- $type = 'Adyen HTTP Notification(s):';
- $comment = __(
- '%1
eventCode: %2
pspReference: %3
paymentMethod: %4
' .
- ' success: %5 %6 %7',
- $type,
- $eventCode,
- $notification->getPspreference(),
- $notification->getPaymentMethod(),
- $success,
- $klarnaReservationNumberText,
- $boletoPaidAmountText
- );
+ $comment = $this->orderStatusHistoryHelper->buildWebhookComment($order, $notification);
// If notification is pending status and pending status is set add the status change to the comment history
- if ($eventCode == Notification::PENDING) {
+ if ($notification->getEventCode() == Notification::PENDING) {
$pendingStatus = $this->configHelper->getConfigData(
'pending_status',
'adyen_abstract',
$order->getStoreId()
);
if ($pendingStatus != "") {
- $order->addStatusHistoryComment($comment, $pendingStatus);
+ $order->addCommentToStatusHistory($comment, $pendingStatus);
$this->logger->addAdyenNotification(
'Created comment history for this notification with status change to: ' . $pendingStatus,
array_merge(
@@ -368,7 +303,7 @@ private function addNotificationDetailsHistoryComment(Order $order, Notification
}
}
- $order->addStatusHistoryComment($comment, $order->getStatus());
+ $order->addCommentToStatusHistory($comment, $order->getStatus());
$this->logger->addAdyenNotification(
'Created comment history for this notification',
[
@@ -465,10 +400,6 @@ private function updateOrderPaymentWithAdyenAttributes(
);
}
- if ($this->boletoPaidAmount != "") {
- $payment->setAdditionalInformation('adyen_boleto_paid_amount', $this->boletoPaidAmount);
- }
-
if ($this->ratepayDescriptor !== "") {
$payment->setAdditionalInformation(
'adyen_ratepay_descriptor',
@@ -521,7 +452,7 @@ private function setNotificationError(Notification $notification, string $errorM
private function addNotificationErrorComment(Order $order, string $errorMessage): Order
{
$comment = __('The order failed to update: %1', $errorMessage);
- $order->addStatusHistoryComment($comment, $order->getStatus());
+ $order->addCommentToStatusHistory($comment, $order->getStatus());
$this->orderRepository->save($order);
return $order;
}
diff --git a/Helper/Webhook/CaptureWebhookHandler.php b/Helper/Webhook/CaptureWebhookHandler.php
index 77914f851..9504a60b2 100644
--- a/Helper/Webhook/CaptureWebhookHandler.php
+++ b/Helper/Webhook/CaptureWebhookHandler.php
@@ -93,10 +93,9 @@ public function handleWebhook(MagentoOrder $order, Notification $notification, s
return $order;
}
- // TODO Get functionality out of the invoiceHelper function, so we don't have to fetch the order from the db
- $adyenInvoice = $this->invoiceHelper->handleCaptureWebhook($order, $notification);
- // Refresh the order by fetching it from the db
- $order = $this->orderHelper->fetchOrderByIncrementId($notification);
+ list($adyenInvoice, $magentoInvoice, $order) =
+ $this->invoiceHelper->handleCaptureWebhook($order, $notification);
+
$adyenOrderPayment = $this->adyenOrderPaymentFactory->create()->load($adyenInvoice->getAdyenPaymentOrderId(), OrderPaymentInterface::ENTITY_ID);
$this->adyenOrderPaymentHelper->refreshPaymentCaptureStatus($adyenOrderPayment, $notification->getAmountCurrency());
$this->adyenLogger->addAdyenNotification(
@@ -112,7 +111,6 @@ public function handleWebhook(MagentoOrder $order, Notification $notification, s
]
);
- $magentoInvoice = $this->magentoInvoiceFactory->create()->load($adyenInvoice->getInvoiceId(), MagentoInvoice::ENTITY_ID);
$this->adyenLogger->addAdyenNotification(
sprintf('Notification %s updated invoice {invoiceId}', $notification->getEntityId()),
array_merge(
diff --git a/Test/Unit/Gateway/Response/CheckoutPaymentCommentHistoryHandlerTest.php b/Test/Unit/Gateway/Response/CheckoutPaymentCommentHistoryHandlerTest.php
deleted file mode 100644
index fc6f90b54..000000000
--- a/Test/Unit/Gateway/Response/CheckoutPaymentCommentHistoryHandlerTest.php
+++ /dev/null
@@ -1,122 +0,0 @@
-checkoutPaymentCommentHistoryHandler = new CheckoutPaymentCommentHistoryHandler();
-
- $orderAdapterMock = $this->createMock(OrderAdapterInterface::class);
- $this->orderMock = $this->createMock(Order::class);
-
- $this->paymentMock = $this->createMock(Payment::class);
- $this->paymentMock->method('getOrder')->willReturn($this->orderMock);
- $this->paymentDataObject = new PaymentDataObject($orderAdapterMock, $this->paymentMock);
-
- $this->handlingSubject = [
- 'payment' => $this->paymentDataObject,
- 'paymentAction' => "authorize",
- 'stateObject' => null
- ];
- }
- public function testIfGeneralFlowIsHandledCorrectly()
- {
- // Prepare the sample response collection
- $responseCollection = [
- 'hasOnlyGiftCards' => false,
- 0 => [
- 'additionalData' => [],
- 'amount' => [],
- 'resultCode' => 'Authorised',
- 'pspReference' => 'MDH54321',
- 'paymentMethod' => [
- 'name' => 'giftcard',
- 'type' => 'Givex',
- ],
- ],
- 1 => [
- 'additionalData' => [],
- 'amount' => [],
- 'resultCode' => 'Authorised',
- 'pspReference' => 'ABC12345',
- 'paymentMethod' => [
- 'name' => 'card',
- 'type' => 'CreditCard',
- ],
- ],
- ];
-
- // Set expectations for the mocked order object
- $this->orderMock
- ->expects($this->once())
- ->method('addStatusHistoryComment')
- ->with(
- $this->stringContains(
- "authResult: Authorised
pspReference: MDH54321
" .
- "
authResult: Authorised
pspReference: ABC12345
"
- ),
- $this->anything()
- );
-
- $this->checkoutPaymentCommentHistoryHandler->handle($this->handlingSubject, $responseCollection);
- }
-
- public function testIfEmptyResponseCodeIsHandledCorrectly()
- {
- // Prepare a sample response collection without a resultCode
- $responseCollection = [
- [
- 'pspReference' => '123456789'
- ]
- ];
-
- // Set expectations for the mocked order object
- $this->orderMock
- ->expects($this->once())
- ->method('addStatusHistoryComment')
- ->with(
- $this->stringContains('pspReference: 123456789'),
- $this->anything()
- );
-
- // Execute the handler
- $this->checkoutPaymentCommentHistoryHandler->handle($this->handlingSubject, $responseCollection);
- }
-
- public function testIfNoPspReferenceIsHandledCorrectly()
- {
- // Prepare a sample response collection without a pspReference
- $responseCollection = [
- [
- 'resultCode' => 'Authorised'
- ]
- ];
-
- // Set expectations for the mocked order object
- $this->orderMock
- ->expects($this->once())
- ->method('addStatusHistoryComment')
- ->with(
- $this->stringContains('authResult: Authorised'),
- $this->anything()
- );
-
- // Execute the handler
- $this->checkoutPaymentCommentHistoryHandler->handle($this->handlingSubject, $responseCollection);
- }
-}
diff --git a/etc/di.xml b/etc/di.xml
index c078079d3..c60945adc 100755
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -1292,11 +1292,31 @@
- Adyen\Payment\Gateway\Response\CheckoutPaymentsDetailsHandler
- Adyen\Payment\Gateway\Response\VaultDetailsHandler
- - Adyen\Payment\Gateway\Response\CheckoutPaymentCommentHistoryHandler
+ - AdyenPaymentAuthorisationOrderStatusHistoryHandler
- Adyen\Payment\Gateway\Response\StateDataHandler
+
+
+ authorisation
+
+
+
+
+ capture
+
+
+
+
+ refund
+
+
+
+
+ cancellation
+
+
@@ -1316,7 +1336,7 @@
- Adyen\Payment\Gateway\Response\PaymentRefundDetailsHandler
- - Adyen\Payment\Gateway\Response\PaymentCommentHistoryRefundHandler
+ - AdyenPaymentRefundOrderStatusHistoryHandler
@@ -1324,7 +1344,7 @@
- Adyen\Payment\Gateway\Response\PaymentCancelDetailsHandler
- - Adyen\Payment\Gateway\Response\PaymentCommentHistoryHandler
+ - AdyenPaymentCancellationOrderStatusHistoryHandler