|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * |
| 4 | + * Adyen Payment module (https://www.adyen.com/) |
| 5 | + * |
| 6 | + * Copyright (c) 2026 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\Model\Ui; |
| 13 | + |
| 14 | +use Adyen\AdyenException; |
| 15 | +use Adyen\Payment\Helper\Config; |
| 16 | +use Adyen\Payment\Helper\ConnectedTerminals; |
| 17 | +use Adyen\Payment\Helper\PaymentMethods; |
| 18 | +use Magento\Checkout\Model\ConfigProviderInterface; |
| 19 | +use Magento\Checkout\Model\Session; |
| 20 | +use Magento\Framework\Exception\LocalizedException; |
| 21 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 22 | +use Magento\Store\Model\StoreManagerInterface; |
| 23 | + |
| 24 | +/** |
| 25 | + * This config provider is initially used to provide payment methods and connected terminals to the checkout |
| 26 | + * as the required `shipping-information` or `payment-information` API calls are not triggered for virtual quotes. |
| 27 | + */ |
| 28 | +class AdyenVirtualQuoteConfigProvider implements ConfigProviderInterface |
| 29 | +{ |
| 30 | + /** |
| 31 | + * @param PaymentMethods $paymentMethodsHelper |
| 32 | + * @param StoreManagerInterface $storeManager |
| 33 | + * @param Config $configHelper |
| 34 | + * @param Session $session |
| 35 | + * @param ConnectedTerminals $connectedTerminalsHelper |
| 36 | + */ |
| 37 | + public function __construct( |
| 38 | + private readonly PaymentMethods $paymentMethodsHelper, |
| 39 | + private readonly StoreManagerInterface $storeManager, |
| 40 | + private readonly Config $configHelper, |
| 41 | + private readonly Session $session, |
| 42 | + private readonly ConnectedTerminals $connectedTerminalsHelper |
| 43 | + ) {} |
| 44 | + |
| 45 | + /** |
| 46 | + * @return array |
| 47 | + * @throws AdyenException |
| 48 | + * @throws LocalizedException |
| 49 | + * @throws NoSuchEntityException |
| 50 | + */ |
| 51 | + public function getConfig(): array |
| 52 | + { |
| 53 | + $storeId = $this->storeManager->getStore()->getId(); |
| 54 | + $config = []; |
| 55 | + |
| 56 | + if ($this->session->getQuote()->isVirtual()) { |
| 57 | + if ($this->configHelper->getIsPaymentMethodsActive($storeId)) { |
| 58 | + $config['payment']['adyen']['virtualQuote']['paymentMethodsResponse'] = |
| 59 | + $this->paymentMethodsHelper->getApiResponse($this->session->getQuote()); |
| 60 | + } |
| 61 | + |
| 62 | + if ($this->configHelper->getAdyenPosCloudConfigData("active", $storeId, true)) { |
| 63 | + $config['payment']['adyen']['virtualQuote']['connectedTerminals'] = |
| 64 | + $this->connectedTerminalsHelper->getConnectedTerminalsApiResponse($storeId); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + return $config; |
| 69 | + } |
| 70 | +} |
0 commit comments