We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Config.php 5.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<?php
/**
 *                       ######
 *                       ######
 * ############    ####( ######  #####. ######  ############   ############
 * #############  #####( ######  #####. ######  #############  #############
 *        ######  #####( ######  #####. ######  #####  ######  #####  ######
 * ###### ######  #####( ######  #####. ######  #####  #####   #####  ######
 * ###### ######  #####( ######  #####. ######  #####          #####  ######
 * #############  #############  #############  #############  #####  ######
 *  ############   ############  #############   ############  #####  ######
 *                                      ######
 *                               #############
 *                               ############
 *
 * Adyen Payment module (https://www.adyen.com/)
 *
 * Copyright (c) 2020 Adyen BV (https://www.adyen.com/)
 * See LICENSE.txt for license details.
 *
 * Author: Adyen <magento@adyen.com>
 */

namespace Adyen\Payment\Helper;

use Magento\Framework\App\Config\ScopeConfigInterface;
27
use Magento\Framework\Encryption\EncryptorInterface;
28 29 30 31 32 33

class Config
{
    const XML_PAYMENT_PREFIX = "payment";
    const XML_ADYEN_ABSTRACT_PREFIX = "adyen_abstract";
    const XML_NOTIFICATIONS_CAN_CANCEL_FIELD = "notifications_can_cancel";
34 35
    const XML_NOTIFICATIONS_HMAC_CHECK = "notifications_hmac_check";
    const XML_NOTIFICATIONS_IP_CHECK = "notifications_ip_check";
36 37
    const XML_NOTIFICATIONS_HMAC_KEY_LIVE = "notification_hmac_key_live";
    const XML_NOTIFICATIONS_HMAC_KEY_TEST = "notification_hmac_key_test";
38 39 40 41 42 43

    /**
     * @var Magento\Framework\App\Config\ScopeConfigInterface
     */
    protected $scopeConfig;

44 45 46 47 48 49 50 51 52 53
    /**
     * @var EncryptorInterface
     */
    private $encryptor;

    /**
     * @var \Adyen\Payment\Helper\Data
     */
    private $adyenHelper;

54 55
    /**
     * Config constructor.
56
     *
57
     * @param Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
58 59
     * @param EncryptorInterface $encryptor
     * @param \Adyen\Payment\Helper\Data $adyenHelper
60 61
     */
    public function __construct(
62 63 64
        ScopeConfigInterface $scopeConfig,
        EncryptorInterface $encryptor,
        \Adyen\Payment\Helper\Data $adyenHelper
65 66
    ) {
        $this->scopeConfig = $scopeConfig;
67 68
        $this->encryptor = $encryptor;
        $this->adyenHelper = $adyenHelper;
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    }

    /**
     * Retrieve flag for notifications_can_cancel
     *
     * @param int $storeId
     * @return bool
     */
    public function getNotificationsCanCancel($storeId = null)
    {
        return (bool)$this->getConfigData(
            self::XML_NOTIFICATIONS_CAN_CANCEL_FIELD,
            self::XML_ADYEN_ABSTRACT_PREFIX,
            $storeId,
            true
        );
    }

87
    /**
88
     * Retrieve flag for notifications_hmac_check
89 90 91 92
     *
     * @param int $storeId
     * @return bool
     */
93
    public function getNotificationsHmacCheck($storeId = null)
94 95
    {
        return (bool)$this->getConfigData(
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
            self::XML_NOTIFICATIONS_HMAC_CHECK,
            self::XML_ADYEN_ABSTRACT_PREFIX,
            $storeId,
            true
        );
    }

    /**
     * Retrieve flag for notifications_ip_check
     *
     * @param int $storeId
     * @return bool
     */
    public function getNotificationsIpCheck($storeId = null)
    {
        return (bool)$this->getConfigData(
            self::XML_NOTIFICATIONS_IP_CHECK,
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
            self::XML_ADYEN_ABSTRACT_PREFIX,
            $storeId,
            true
        );
    }

    /**
     * Retrieve key for notifications_hmac_key
     *
     * @param int $storeId
     * @return string
     */
    public function getNotificationsHmacKey($storeId = null)
    {
        if ($this->adyenHelper->isDemoMode($storeId)) {
            $key = $this->getConfigData(
                self::XML_NOTIFICATIONS_HMAC_KEY_TEST,
                self::XML_ADYEN_ABSTRACT_PREFIX,
                $storeId,
                false
            );
        } else {
            $key = $this->getConfigData(
                self::XML_NOTIFICATIONS_HMAC_KEY_LIVE,
                self::XML_ADYEN_ABSTRACT_PREFIX,
                $storeId,
                false
            );
        }
        return $this->encryptor->decrypt(trim($key));
    }
144 145 146 147 148 149 150 151 152 153 154 155

    /**
     * Check if alternative payment methods vault is enabled
     *
     * @param null|int|string $storeId
     * @return mixed
     */
    public function isStoreAlternativePaymentMethodEnabled($storeId = null)
    {
        return $this->adyenHelper->getAdyenHppVaultConfigDataFlag('active', $storeId);
    }

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    /**
     * Retrieve information from payment configuration
     *
     * @param string $field
     * @param string $xmlPrefix
     * @param int $storeId
     * @param bool|false $flag
     * @return bool|mixed
     */
    private function getConfigData($field, $xmlPrefix, $storeId, $flag = false)
    {
        $path = implode("/", [self::XML_PAYMENT_PREFIX, $xmlPrefix, $field]);

        if (!$flag) {
            return $this->scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
        } else {
            return $this->scopeConfig->isSetFlag($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
        }
    }
}