How to get current environment type value for braintree payment method using programmatically magento?

We can get the current environment type value by programmatically checking the current mode setup in the admin configuration.

There will be two possible environment types sandbox and production.

You need to create a PHP Class to render the function to fetch the current environment mode value,



namespace Rbj\Payment\Model;

use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use PayPal\Braintree\Gateway\Config\Config;
use PayPal\Braintree\Model\StoreConfigResolver;

class CheckBraintreeEnvironment
    private StoreConfigResolver $storeConfigResolver;
    private Config $config;

    public function __construct(
        StoreConfigResolver $storeConfigResolver,
        Config $config
    ) {
        $this->storeConfigResolver = $storeConfigResolver;
        $this->config = $config;

     * Return environment type.
     * @return string
     * @throws InputException
     * @throws NoSuchEntityException
    public function getEnvironment(): string
        $storeId = $this->storeConfigResolver->getStoreId();
        $environmentIdentifier = $this->config->getValue(Config::KEY_ENVIRONMENT, $storeId);

        return $environmentIdentifier;

Now We have to use the getEnvironment() method to fetch the current value of the environment for the Braintree.

The possible outcome will be either sandbox or production.