payment_configuration.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. use Magento\Config\Model\Config;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. use Magento\Framework\Encryption\EncryptorInterface;
  9. use Magento\Store\Model\ScopeInterface;
  10. use Magento\TestFramework\Helper\Bootstrap;
  11. $objectManager = Bootstrap::getObjectManager();
  12. /** @var EncryptorInterface $encryptor */
  13. $encryptor = $objectManager->get(EncryptorInterface::class);
  14. $processConfigData = function (Config $config, array $data) {
  15. foreach ($data as $key => $value) {
  16. $config->setDataByPath($key, $value);
  17. $config->save();
  18. }
  19. };
  20. // save payment configuration for the default scope
  21. $configData = [
  22. 'payment/braintree/merchant_id' => 'def_merchant_id',
  23. 'payment/braintree/public_key' => $encryptor->encrypt('def_public_key'),
  24. 'payment/braintree/private_key' => $encryptor->encrypt('def_private_key'),
  25. ];
  26. /** @var Config $defConfig */
  27. $defConfig = $objectManager->create(Config::class);
  28. $defConfig->setScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
  29. $processConfigData($defConfig, $configData);
  30. // save payment configuration per store
  31. require __DIR__ . '/../../Store/_files/store.php';
  32. $storeConfigData = [
  33. 'payment/braintree/merchant_id' => 'store_merchant_id',
  34. 'payment/braintree/public_key' => $encryptor->encrypt('store_public_key'),
  35. ];
  36. /** @var Config $storeConfig */
  37. $storeConfig = $objectManager->create(Config::class);
  38. $storeConfig->setScope(ScopeInterface::SCOPE_STORES);
  39. $storeConfig->setStore('test');
  40. $processConfigData($storeConfig, $storeConfigData);
  41. // save payment website config data
  42. require __DIR__ . '/../../Store/_files/second_website_with_two_stores.php';
  43. $websiteConfigData = [
  44. 'payment/braintree/merchant_id' => 'website_merchant_id',
  45. 'payment/braintree/private_key' => $encryptor->encrypt('website_private_key'),
  46. ];
  47. /** @var Config $websiteConfig */
  48. $websiteConfig = $objectManager->create(Config::class);
  49. $websiteConfig->setScope(ScopeInterface::SCOPE_WEBSITES);
  50. $websiteConfig->setWebsite($websiteId);
  51. $processConfigData($websiteConfig, $websiteConfigData);