Skip to content

Commit

Permalink
Comments refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hossam-adyen committed Feb 22, 2024
1 parent ef303ee commit 7cde2ae
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Api/AdyenPosCloudInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ interface AdyenPosCloudInterface
* @param int $orderId
* @return void
*/
public function pay(int $orderId, string $payload): void;
public function pay(int $orderId): void;
}
2 changes: 1 addition & 1 deletion Model/Api/AdyenPosCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
$this->adyenLogger = $adyenLogger;
}

public function pay(int $orderId, string $payload): void
public function pay(int $orderId): void
{
$order = $this->orderRepository->get($orderId);
$this->execute($order);
Expand Down
22 changes: 18 additions & 4 deletions Plugin/GuestPaymentInformationResetOrderId.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Adyen\Payment\Plugin;

use Adyen\Payment\Helper\PaymentMethods;
use Adyen\Payment\Logger\AdyenLogger;
use Exception;
use Magento\Checkout\Api\GuestPaymentInformationManagementInterface;
Expand All @@ -26,6 +27,13 @@ class GuestPaymentInformationResetOrderId
*/
protected $quoteRepository;

/**
* Payment methods helper
*
* @var PaymentMethods
*/
protected $paymentMethodsHelper;

/**
* @var AdyenLogger
*/
Expand All @@ -44,12 +52,14 @@ class GuestPaymentInformationResetOrderId
*/
public function __construct(
CartRepositoryInterface $quoteRepository,
AdyenLogger $adyenLogger,
QuoteIdMaskFactory $quoteIdMaskFactory
QuoteIdMaskFactory $quoteIdMaskFactory,
PaymentMethods $paymentMethodsHelper,
AdyenLogger $adyenLogger
) {
$this->quoteRepository = $quoteRepository;
$this->adyenLogger = $adyenLogger;
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
$this->paymentMethodsHelper = $paymentMethodsHelper;
$this->adyenLogger = $adyenLogger;
}

/**
Expand All @@ -65,7 +75,11 @@ public function beforeSavePaymentInformationAndPlaceOrder(
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
$quoteId = $quoteIdMask->getQuoteId();
$quote = $this->quoteRepository->get($quoteId);
$quote->setReservedOrderId(null);
$method = $quote->getPayment()->getMethod();

if ($this->paymentMethodsHelper->isAdyenPayment($method)) {
$quote->setReservedOrderId(null);
}
} catch (Exception $e) {
$this->adyenLogger->error("Failed to reset reservedOrderId for guest shopper" . $e->getMessage());
}
Expand Down
17 changes: 16 additions & 1 deletion Plugin/PaymentInformationResetOrderId.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Adyen\Payment\Plugin;

use Adyen\Payment\Helper\PaymentMethods;
use Adyen\Payment\Logger\AdyenLogger;
use Exception;
use Magento\Checkout\Api\PaymentInformationManagementInterface;
Expand All @@ -25,6 +26,13 @@ class PaymentInformationResetOrderId
*/
protected $quoteRepository;

/**
* Payment methods helper
*
* @var PaymentMethods
*/
protected $paymentMethodsHelper;

/**
* @var AdyenLogger
*/
Expand All @@ -33,13 +41,16 @@ class PaymentInformationResetOrderId
/**
* PaymentInformationResetOrderId constructor.
* @param CartRepositoryInterface $quoteRepository
* @param PaymentMethods $paymentMethodsHelper
* @param AdyenLogger $adyenLogger
*/
public function __construct(
CartRepositoryInterface $quoteRepository,
PaymentMethods $paymentMethodsHelper,
AdyenLogger $adyenLogger
) {
$this->quoteRepository = $quoteRepository;
$this->paymentMethodsHelper = $paymentMethodsHelper;
$this->adyenLogger = $adyenLogger;
}

Expand All @@ -54,7 +65,11 @@ public function beforeSavePaymentInformationAndPlaceOrder(
) {
try {
$quote = $this->quoteRepository->get($cartId);
$quote->setReservedOrderId(null);
$method = $quote->getPayment()->getMethod();

if ($this->paymentMethodsHelper->isAdyenPayment($method)) {
$quote->setReservedOrderId(null);
}
} catch (Exception $e) {
$this->adyenLogger->error("Failed to reset reservedOrderId " . $e->getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/web/js/model/adyen-payment-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ define(
{cartId: quote.getQuoteId()}
)
}
const payload = JSON.stringify({'payload': '{}', orderId})
const payload = JSON.stringify({orderId})

return storage.post(url, payload, true)
},
Expand Down

0 comments on commit 7cde2ae

Please sign in to comment.