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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Model\Adapter;
use Magento\Braintree\Gateway\Config\Config;
use Magento\Framework\ObjectManagerInterface;
/**
* This factory is preferable to use for Braintree adapter instance creation.
*/
class BraintreeAdapterFactory
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var Config
*/
private $config;
/**
* @param ObjectManagerInterface $objectManager
* @param Config $config
*/
public function __construct(ObjectManagerInterface $objectManager, Config $config)
{
$this->config = $config;
$this->objectManager = $objectManager;
}
/**
* Creates instance of Braintree Adapter.
*
* @param int|null $storeId if null is provided as an argument, then current scope will be resolved
* by \Magento\Framework\App\Config\ScopeCodeResolver (useful for most cases) but for adminhtml area the store
* should be provided as the argument for correct config settings loading.
* @return BraintreeAdapter
*/
public function create($storeId = null)
{
return $this->objectManager->create(
BraintreeAdapter::class,
[
'merchantId' => $this->config->getMerchantId($storeId),
'publicKey' => $this->config->getValue(Config::KEY_PUBLIC_KEY, $storeId),
'privateKey' => $this->config->getValue(Config::KEY_PRIVATE_KEY, $storeId),
'environment' => $this->config->getEnvironment($storeId),
]
);
}
}