Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v9.5.0 #2588

Merged
merged 8 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions Api/AdyenPosCloudInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2024 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Api;
interface AdyenPosCloudInterface
{
/**
* @param int $orderId
* @return void
*/
public function pay(int $orderId): void;
}
21 changes: 21 additions & 0 deletions Api/GuestAdyenPosCloudInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2024 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Api;

interface GuestAdyenPosCloudInterface
{
/**
* @param string $cartId
* @return void
*/
public function payByCart(string $cartId): void;
}
31 changes: 28 additions & 3 deletions Gateway/Response/PaymentPosCloudHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,32 @@
namespace Adyen\Payment\Gateway\Response;

use Adyen\AdyenException;
use Adyen\Payment\Helper\PaymentResponseHandler;
use Adyen\Payment\Helper\Quote;
use Adyen\Payment\Helper\Vault;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\Order\Payment;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\StatusResolver;
use Magento\Payment\Gateway\Helper\SubjectReader;
use Magento\Payment\Gateway\Response\HandlerInterface;

class PaymentPosCloudHandler implements HandlerInterface
{
private AdyenLogger $adyenLogger;
private Vault $vaultHelper;
private StatusResolver $statusResolver;
private Quote $quoteHelper;

public function __construct(
AdyenLogger $adyenLogger,
Vault $vaultHelper
Vault $vaultHelper,
StatusResolver $statusResolver,
Quote $quoteHelper
) {
$this->adyenLogger = $adyenLogger;
$this->vaultHelper = $vaultHelper;
$this->statusResolver = $statusResolver;
$this->quoteHelper = $quoteHelper;
}

public function handle(array $handlingSubject, array $response)
Expand All @@ -44,9 +53,11 @@ public function handle(array $handlingSubject, array $response)

// do not send order confirmation mail
$payment->getOrder()->setCanSendNewEmailFlag(false);
$resultCode = null;

if (!empty($paymentResponse) && isset($paymentResponse['Response']['Result'])) {
$payment->setAdditionalInformation('resultCode', $paymentResponse['Response']['Result']);
$resultCode = $paymentResponse['Response']['Result'];
$payment->setAdditionalInformation('resultCode', $resultCode);
}

if (!empty($paymentResponse['Response']['AdditionalResponse']))
Expand Down Expand Up @@ -81,5 +92,19 @@ public function handle(array $handlingSubject, array $response)
// do not close transaction so you can do a cancel() and void
$payment->setIsTransactionClosed(false);
$payment->setShouldCloseParentTransaction(false);

if ($resultCode === PaymentResponseHandler::POS_SUCCESS) {
$order = $payment->getOrder();
$status = $this->statusResolver->getOrderStatusByState(
$payment->getOrder(),
Order::STATE_NEW
);
$order->setState(Order::STATE_NEW);
$order->setStatus($status);
$message = __("Pos payment authorized");
$order->addCommentToStatusHistory($message, $status);
$order->save();
$this->quoteHelper->disableQuote($order->getQuoteId());
}
}
}
6 changes: 6 additions & 0 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Config
const XML_MOTO_MERCHANT_ACCOUNTS = 'moto_merchant_accounts';
const XML_CONFIGURATION_MODE = 'configuration_mode';
const XML_ADYEN_POS_CLOUD = 'adyen_pos_cloud';
const XML_PAYMENT_ACTION = 'payment_action';
const XML_WEBHOOK_NOTIFICATION_PROCESSOR = 'webhook_notification_processor';
const AUTO_CAPTURE_OPENINVOICE = 'auto';
const XML_RECURRING_CONFIGURATION = 'recurring_configuration';
Expand Down Expand Up @@ -465,6 +466,11 @@ public function getAdyenPosCloudConfigData(string $field, int $storeId = null, b
return $this->getConfigData($field, self::XML_ADYEN_POS_CLOUD, $storeId, $flag);
}

public function getAdyenPosCloudPaymentAction(int $storeId): string
{
return $this->getAdyenPosCloudConfigData(self::XML_PAYMENT_ACTION, $storeId);
}

public function useQueueProcessor($storeId = null): bool
{
return $this->getConfigData(
Expand Down
5 changes: 3 additions & 2 deletions Helper/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,9 @@ public function refundOrder(MagentoOrder $order, Notification $notification): Ma
);
}

$order->addStatusHistoryComment(__('Refund Webhook successfully handled'), $order->getStatus());

$order->addStatusHistoryComment(__(sprintf(
'%s Webhook successfully handled',
$notification->getEventCode())), $order->getStatus());
return $order;
}

Expand Down
6 changes: 4 additions & 2 deletions Helper/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Adyen\Webhook\Processor\ProcessorFactory;
use DateTime;
use Exception;
use Adyen\Payment\Model\Notification as NotificationEntity;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Sales\Model\Order;
Expand All @@ -39,7 +40,8 @@ class Webhook
Order::STATE_PROCESSING => PaymentStates::STATE_IN_PROGRESS,
Order::STATE_COMPLETE => PaymentStates::STATE_PAID,
Order::STATE_CANCELED => PaymentStates::STATE_CANCELLED,
Order::STATE_CLOSED => PaymentStates::STATE_REFUNDED
Order::STATE_CLOSED => PaymentStates::STATE_REFUNDED,
NotificationEntity::STATE_ADYEN_AUTHORIZED => PaymentStates::STATE_PENDING
];

/**
Expand Down Expand Up @@ -271,7 +273,7 @@ private function getTransitionState(Notification $notification, $currentOrderSta
'additionalData' => !empty($notification->getAdditionalData())
? $this->serializer->unserialize($notification->getAdditionalData()) : null,
]);
$processor = ProcessorFactory::create($webhookNotificationItem, $currentOrderState, $this->logger);
$processor = ProcessorFactory::create($webhookNotificationItem, $currentOrderState);

return $processor->process();
}
Expand Down
81 changes: 81 additions & 0 deletions Helper/Webhook/AbstractDisputeWebhookHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2024 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Helper\Webhook;

use Adyen\Payment\Helper\Order;
use Adyen\Payment\Model\Notification;
use Adyen\Webhook\PaymentStates;
use Magento\Sales\Model\Order as MagentoOrder;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Helper\Config;


abstract class AbstractDisputeWebhookHandler implements WebhookHandlerInterface
{
/** @var Order */
private $orderHelper;

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

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

public function __construct(Order $orderHelper, AdyenLogger $adyenLogger, Config $configHelper)
{
$this->orderHelper = $orderHelper;
$this->adyenLogger = $adyenLogger;
$this->configHelper = $configHelper;
}

public function handleWebhook(MagentoOrder $order, Notification $notification, string $transitionState): MagentoOrder
{
$ignoreDisputeNotifications = $this->configHelper->getConfigData(
'ignore_dispute_notification',
'adyen_abstract',
$order->getStoreId()
);

if ($transitionState === PaymentStates::STATE_REFUNDED && !$ignoreDisputeNotifications){
$order = $this->orderHelper->refundOrder($order, $notification);
$this->adyenLogger->addAdyenNotification(sprintf(
'The order has been updated by the %s notification. ',
$notification->getEventCode(),
), [
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]);
}
elseif ($ignoreDisputeNotifications){
$this->adyenLogger->addAdyenNotification(sprintf(
'Config to ignore dispute notification is enabled. Notification %s will be ignored',
$notification->getId()
), [
'pspReference' => $notification->getPspreference(),
'merchantReference' => $notification->getMerchantReference()
]);
}
else {
$this->orderHelper->addWebhookStatusHistoryComment($order, $notification);
$this->adyenLogger->addAdyenNotification(sprintf(
'There is a %s notification for the order.',
$notification->getEventCode(),
), [
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]);
}
return $order;
}

}
23 changes: 23 additions & 0 deletions Helper/Webhook/ChargebackReversedWebhookHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2024 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Helper\Webhook;

use Adyen\Payment\Helper\Order;
use Adyen\Payment\Model\Notification;
use Magento\Sales\Model\Order as MagentoOrder;


class ChargebackReversedWebhookHandler extends AbstractDisputeWebhookHandler implements WebhookHandlerInterface
{

}
23 changes: 23 additions & 0 deletions Helper/Webhook/ChargebackWebhookHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2024 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Helper\Webhook;

use Adyen\Payment\Helper\Order;
use Adyen\Payment\Model\Notification;
use Magento\Sales\Model\Order as MagentoOrder;


class ChargebackWebhookHandler extends AbstractDisputeWebhookHandler implements WebhookHandlerInterface
{

}
23 changes: 23 additions & 0 deletions Helper/Webhook/NotificationOfChargebackWebhookHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2024 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Helper\Webhook;

use Adyen\Payment\Helper\Order;
use Adyen\Payment\Model\Notification;
use Magento\Sales\Model\Order as MagentoOrder;


class NotificationOfChargebackWebhookHandler extends AbstractDisputeWebhookHandler implements WebhookHandlerInterface
{

}
23 changes: 23 additions & 0 deletions Helper/Webhook/RequestForInformationWebhookHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2024 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Helper\Webhook;

use Adyen\Payment\Helper\Order;
use Adyen\Payment\Model\Notification;
use Magento\Sales\Model\Order as MagentoOrder;


class RequestForInformationWebhookHandler extends AbstractDisputeWebhookHandler implements WebhookHandlerInterface
{

}
23 changes: 23 additions & 0 deletions Helper/Webhook/SecondChargebackWebhookHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2024 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Helper\Webhook;

use Adyen\Payment\Helper\Order;
use Adyen\Payment\Model\Notification;
use Magento\Sales\Model\Order as MagentoOrder;


class SecondChargebackWebhookHandler extends AbstractDisputeWebhookHandler implements WebhookHandlerInterface
{

}
Loading
Loading