payment_configuration.php 2.1 KB
Newer Older
Ketan's avatar
Ketan committed
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

use Magento\Config\Model\Config;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\TestFramework\Helper\Bootstrap;

$objectManager = Bootstrap::getObjectManager();

/** @var EncryptorInterface $encryptor */
$encryptor = $objectManager->get(EncryptorInterface::class);

$processConfigData = function (Config $config, array $data) {
    foreach ($data as $key => $value) {
        $config->setDataByPath($key, $value);
        $config->save();
    }
};

// save payment configuration for the default scope
$configData = [
    'payment/braintree/merchant_id' => 'def_merchant_id',
    'payment/braintree/public_key' => $encryptor->encrypt('def_public_key'),
    'payment/braintree/private_key' => $encryptor->encrypt('def_private_key'),
];
/** @var Config $defConfig */
$defConfig = $objectManager->create(Config::class);
$defConfig->setScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
$processConfigData($defConfig, $configData);

// save payment configuration per store
require __DIR__ . '/../../Store/_files/store.php';
$storeConfigData = [
    'payment/braintree/merchant_id' => 'store_merchant_id',
    'payment/braintree/public_key' => $encryptor->encrypt('store_public_key'),
];
/** @var Config $storeConfig */
$storeConfig = $objectManager->create(Config::class);
$storeConfig->setScope(ScopeInterface::SCOPE_STORES);
$storeConfig->setStore('test');
$processConfigData($storeConfig, $storeConfigData);

// save payment website config data
require __DIR__ . '/../../Store/_files/second_website_with_two_stores.php';
$websiteConfigData = [
    'payment/braintree/merchant_id' => 'website_merchant_id',
    'payment/braintree/private_key' => $encryptor->encrypt('website_private_key'),
];
/** @var Config $websiteConfig */
$websiteConfig = $objectManager->create(Config::class);
$websiteConfig->setScope(ScopeInterface::SCOPE_WEBSITES);
$websiteConfig->setWebsite($websiteId);
$processConfigData($websiteConfig, $websiteConfigData);